* msTileSetExtent * * * * Based on the input parameters, set the output extent for this * * tile. * ************************************************************************/
| 332 | * tile. * |
| 333 | ************************************************************************/ |
| 334 | int msTileSetExtent(mapservObj* msObj) { |
| 335 | #ifdef USE_TILE_API |
| 336 | |
| 337 | mapObj *map = msObj->map; |
| 338 | double dx, dy, buffer; |
| 339 | tileParams params; |
| 340 | |
| 341 | /* Read the tile-mode map file parameters */ |
| 342 | msTileGetParams(msObj->map, ¶ms); |
| 343 | |
| 344 | if( msObj->TileMode == TILE_GMAP ) { |
| 345 | int x, y, zoom; |
| 346 | double zoomfactor, tilesize, xmin, xmax, ymin, ymax; |
| 347 | |
| 348 | if( msObj->TileCoords ) { |
| 349 | if( msTileGetGMapCoords(msObj->TileCoords, &x, &y, &zoom) == MS_FAILURE ) |
| 350 | return MS_FAILURE; |
| 351 | } |
| 352 | else { |
| 353 | msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()"); |
| 354 | return MS_FAILURE; |
| 355 | } |
| 356 | |
| 357 | if(map->debug) |
| 358 | msDebug("msTileSetExtent(): gmaps coords (x: %d, y: %d, z: %d)\n",x,y,zoom); |
| 359 | |
| 360 | /* |
| 361 | ** If we are metatiling, adjust the zoom level appropriately, |
| 362 | ** then scale back the x/y coordinates to match the new level. |
| 363 | */ |
| 364 | if( params.metatile_level > 0 ) { |
| 365 | zoom = zoom - params.metatile_level; |
| 366 | x = x >> params.metatile_level; |
| 367 | y = y >> params.metatile_level; |
| 368 | } |
| 369 | |
| 370 | if(map->debug) |
| 371 | msDebug("msTileSetExtent(): gmaps metacoords (x: %d, y: %d, z: %d)\n",x,y,zoom); |
| 372 | |
| 373 | zoomfactor = pow(2.0, (double)zoom); |
| 374 | |
| 375 | /* |
| 376 | ** Calculate the ground extents of the tile request. |
| 377 | */ |
| 378 | /* printf("X: %i Y: %i Z: %i\n",x,y,zoom); */ |
| 379 | tilesize = SPHEREMERC_GROUND_SIZE / zoomfactor; |
| 380 | xmin = (x * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0); |
| 381 | xmax = ((x + 1) * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0); |
| 382 | ymin = (SPHEREMERC_GROUND_SIZE / 2.0) - ((y + 1) * tilesize); |
| 383 | ymax = (SPHEREMERC_GROUND_SIZE / 2.0) - (y * tilesize); |
| 384 | |
| 385 | map->extent.minx = xmin; |
| 386 | map->extent.maxx = xmax; |
| 387 | map->extent.miny = ymin; |
| 388 | map->extent.maxy = ymax; |
| 389 | |
| 390 | } |
| 391 | else if( msObj->TileMode == TILE_VE ) { |
no test coverage detected