void cmd_recurse(mapcache_context *cmd_ctx, mapcache_tile *tile) { cmd action; int curx, cury, curz; int minchildx,maxchildx,minchildy,maxchildy; double bboxbl[4],bboxtr[4]; double epsilon; apr_pool_clear(cmd_ctx->pool); if(sig_int_received || error_detected) { //stop if we were asked to stop by hitting ctrl-c //remove all items from the queue struct seed_cmd entry; while (trypop_queue(&entry)!=APR_EAGAIN) {queuedtilestot--;} return; } action = examine_tile(cmd_ctx, tile); if(action == MAPCACHE_CMD_SEED || action == MAPCACHE_CMD_DELETE || action == MAPCACHE_CMD_TRANSFER){ //current x,y,z needs seeding, add it to the queue struct seed_cmd cmd; cmd.x = tile->x; cmd.y = tile->y; cmd.z = tile->z; cmd.command = action; push_queue(cmd); queuedtilestot++; progresslog(tile->x,tile->y,tile->z); } //recurse into our 4 child metatiles curx = tile->x; cury = tile->y; curz = tile->z; tile->z += 1; if(tile->z > maxzoom) { tile->z -= 1; return; } /* * compute the x,y limits of the next zoom level that intersect the * current metatile */ mapcache_grid_get_extent(cmd_ctx, grid_link->grid, curx, cury, curz, bboxbl); mapcache_grid_get_extent(cmd_ctx, grid_link->grid, curx+tileset->metasize_x-1, cury+tileset->metasize_y-1, curz, bboxtr); epsilon = (bboxbl[2]-bboxbl[0])*0.01; mapcache_grid_get_xy(cmd_ctx,grid_link->grid, bboxbl[0] + epsilon, bboxbl[1] + epsilon, tile->z,&minchildx,&minchildy); mapcache_grid_get_xy(cmd_ctx,grid_link->grid, bboxtr[2] - epsilon, bboxtr[3] - epsilon, tile->z,&maxchildx,&maxchildy); minchildx = (minchildx / tileset->metasize_x)*tileset->metasize_x; minchildy = (minchildy / tileset->metasize_y)*tileset->metasize_y; maxchildx = (maxchildx / tileset->metasize_x + 1)*tileset->metasize_x; maxchildy = (maxchildy / tileset->metasize_y + 1)*tileset->metasize_y; for(tile->x = minchildx; tile->x < maxchildx; tile->x += tileset->metasize_x) { if(tile->x >= grid_link->grid_limits[tile->z][0] && tile->x < grid_link->grid_limits[tile->z][2]) { for(tile->y = minchildy; tile->y < maxchildy; tile->y += tileset->metasize_y) { if(tile->y >= grid_link->grid_limits[tile->z][1] && tile->y < grid_link->grid_limits[tile->z][3]) { cmd_recurse(cmd_ctx,tile); } } } } tile->x = curx; tile->y = cury; tile->z = curz; }
void _create_capabilities_kml(mapcache_context *ctx, mapcache_request_get_capabilities *req, char *url, char *path_info, mapcache_cfg *cfg) { mapcache_request_get_capabilities_kml *request = (mapcache_request_get_capabilities_kml*)req; char *caps; const char *onlineresource = apr_table_get(cfg->metadata,"url"); int i, j; if(!onlineresource) { onlineresource = url; } request->request.mime_type = apr_pstrdup(ctx->pool,"application/vnd.google-earth.kml+xml"); assert(request->tile || (request->grid && request->tileset)); /* if we have no specific tile, create a kml document referencing all the tiles of the first level in the grid*/ if(!request->tile) { mapcache_extent extent = request->grid->restricted_extent?*(request->grid->restricted_extent):request->grid->grid->extent; caps = apr_psprintf(ctx->pool, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n" " <Document>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>512</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n", extent.maxy,extent.miny,extent.maxx,extent.minx); for(i=request->grid->grid_limits[0].minx; i<request->grid->grid_limits[0].maxx; i++) { for(j=request->grid->grid_limits[0].miny; j<request->grid->grid_limits[0].maxy; j++) { mapcache_tile *t = mapcache_tileset_tile_create(ctx->pool, request->tileset, request->grid); mapcache_extent bb; t->x = i; t->y = j; t->z = 0; mapcache_grid_get_extent(ctx, t->grid_link->grid, t->x, t->y, t->z, &bb); caps = apr_psprintf(ctx->pool, "%s" " <NetworkLink>\n" " <name>%d%d%d</name>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>-1</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n" " <Link>\n" " <href>%s/kml/%s@%s/%d/%d/%d.kml</href>\n" " <viewRefreshMode>onRegion</viewRefreshMode>\n" " </Link>\n" " </NetworkLink>\n", caps, t->x, t->y, t->z, bb.maxy, bb.miny, bb.maxx, bb.minx, onlineresource, request->tileset->name, request->grid->grid->name, t->z, t->x, t->y); } } caps = apr_pstrcat(ctx->pool, caps, " </Document>\n</kml>\n", NULL); } else { mapcache_extent bbox; mapcache_grid_get_extent(ctx, request->tile->grid_link->grid, request->tile->x, request->tile->y, request->tile->z, &bbox); caps = apr_psprintf(ctx->pool, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n" " <Document>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>%d</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n" " <GroundOverlay>\n" " <drawOrder>0</drawOrder>\n" " <Icon>\n" " <href>%s/tms/1.0.0/%s@%s/%d/%d/%d.%s</href>\n" " </Icon>\n" " <LatLonBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonBox>\n" " </GroundOverlay>\n", (request->tile->z == request->tile->grid_link->grid->nlevels - 1) ? -1 : 512, bbox.maxy, bbox.miny, bbox.maxx, bbox.miny, onlineresource, request->tile->tileset->name, request->tile->grid_link->grid->name, request->tile->z, request->tile->x, request->tile->y, (request->tile->tileset->format) ? request->tile->tileset->format->extension : "png", bbox.maxy, bbox.miny, bbox.maxx, bbox.minx); if (request->tile->z < request->tile->grid_link->grid->nlevels - 1) { for (i = 0; i <= 1; i++) { for (j = 0; j <= 1; j++) { /* compute the addresses of the child tiles */ mapcache_tile *t = mapcache_tileset_tile_create(ctx->pool, request->tile->tileset, request->tile->grid_link); mapcache_extent bb; t->x = (request->tile->x << 1) + i; t->y = (request->tile->y << 1) + j; t->z = request->tile->z + 1; mapcache_grid_get_extent(ctx, t->grid_link->grid, t->x, t->y, t->z, &bb); caps = apr_psprintf(ctx->pool, "%s" " <NetworkLink>\n" " <name>%d%d%d</name>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>-1</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n" " <Link>\n" " <href>%s/kml/%s@%s/%d/%d/%d.kml</href>\n" " <viewRefreshMode>onRegion</viewRefreshMode>\n" " </Link>\n" " </NetworkLink>\n", caps, t->x, t->y, t->z, bb.maxy, bb.miny, bb.maxx, bb.minx, onlineresource, request->tile->tileset->name, request->tile->grid_link->grid->name, t->z, t->x, t->y); } } } caps = apr_pstrcat(ctx->pool, caps, " </Document>\n</kml>\n", NULL); } request->request.capabilities = caps; }
void _create_capabilities_kml(mapcache_context *ctx, mapcache_request_get_capabilities *req, char *url, char *path_info, mapcache_cfg *cfg) { mapcache_request_get_capabilities_kml *request = (mapcache_request_get_capabilities_kml*)req; char *caps; const char *onlineresource = apr_table_get(cfg->metadata,"url"); double bbox[4]; if(!onlineresource) { onlineresource = url; } request->request.mime_type = apr_pstrdup(ctx->pool,"application/vnd.google-earth.kml+xml"); mapcache_grid_get_extent(ctx,request->tile->grid_link->grid, request->tile->x, request->tile->y, request->tile->z, bbox); caps = apr_psprintf(ctx->pool,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n" " <Document>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>%d</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n" " <GroundOverlay>\n" " <drawOrder>0</drawOrder>\n" " <Icon>\n" " <href>%s/tms/1.0.0/%s@%s/%d/%d/%d.%s</href>\n" " </Icon>\n" " <LatLonBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonBox>\n" " </GroundOverlay>\n", (request->tile->z == request->tile->grid_link->grid->nlevels-1)?-1:512, bbox[3],bbox[1],bbox[2],bbox[0], onlineresource,request->tile->tileset->name,request->tile->grid_link->grid->name, request->tile->z, request->tile->x,request->tile->y, (request->tile->tileset->format)?request->tile->tileset->format->extension:"png", bbox[3],bbox[1],bbox[2],bbox[0]); if(request->tile->z < request->tile->grid_link->grid->nlevels-1) { int i,j; for(i=0;i<=1;i++) { for(j=0;j<=1;j++) { mapcache_tile *t = mapcache_tileset_tile_create(ctx->pool,request->tile->tileset, request->tile->grid_link); double bb[4]; t->x = (request->tile->x << 1) +i; t->y = (request->tile->y << 1) +j; t->z = request->tile->z + 1; mapcache_grid_get_extent(ctx,t->grid_link->grid, t->x, t->y, t->z, bb); caps = apr_psprintf(ctx->pool,"%s" " <NetworkLink>\n" " <name>%d%d%d</name>\n" " <Region>\n" " <Lod>\n" " <minLodPixels>128</minLodPixels><maxLodPixels>-1</maxLodPixels>\n" " </Lod>\n" " <LatLonAltBox>\n" " <north>%f</north><south>%f</south>\n" " <east>%f</east><west>%f</west>\n" " </LatLonAltBox>\n" " </Region>\n" " <Link>\n" " <href>%s/kml/%s@%s/%d/%d/%d.kml</href>\n" " <viewRefreshMode>onRegion</viewRefreshMode>\n" " </Link>\n" " </NetworkLink>\n", caps,t->x,t->y,t->z, bb[3],bb[1],bb[2],bb[0], onlineresource,request->tile->tileset->name,request->tile->grid_link->grid->name, t->z, t->x,t->y); } } } caps = apr_pstrcat(ctx->pool,caps," </Document>\n</kml>\n",NULL); request->request.capabilities = caps; }