Saturday, July 24, 2010

Custom tile layer

Hi all.

I'm developing a map which has to display many thousands of markers
and am using a custom tile layer to do so.

http://developer.martinpearman.co.uk/www.shipfinder.co.uk/20100724/

My problem is how to create tiles which contain part of a graphic
image from a neighbouring tile.
I'm using PHP and GD library to draw circles on tiles, the diameter of
the circle being the map's current zoom level.
(At zoom levels 0 to 7 a tile contains just some text denoting the
number of markers within that tile and then from zoom level 8 and
higher the tiles display markers (my GD circles)).

The custom tile creation script is based on code from the Google Maps
Book and doesn't (originally) take any account of where a marker image
is not fully contained within a tile.

The map javascript can be found here:

http://developer.martinpearman.co.uk/www.shipfinder.co.uk/20100724/scripts/ShipFinderMap.js

And here's my getTileUrl() method:

$tileLayer.getTileUrl=function($point, $zoom){
var $values=[$zoom, $point.x, $point.y];
if($map.getZoom()>=$this.enableHotspotsAtZoom){
var $projection=$map.getCurrentMapType().getProjection(),
$min_x=($point.x*256)-$zoom, $max_x=$min_x+255+$zoom,
$min_y=($point.y*256)-$zoom, $max_y=$min_y+255+$zoom;
var $sw=$projection.fromPixelToLatLng(new GPoint($min_x, $max_y),
$zoom);
var $ne=$projection.fromPixelToLatLng(new GPoint($max_x, $min_y),
$zoom);
$values.push($sw.toUrlValue());
$values.push($ne.toUrlValue());
}
return 'scripts/ship_layer_tile.php?tile='+$values.join(',');
};

As you can see, at zoom levels 8 and higher i'm trying to pass an
extended tile bounds to the server - the original bounds of the tile
extended by the size of the marker which is the map's zoom level.

This screengrab shows a typical view:

http://developer.martinpearman.co.uk/www.shipfinder.co.uk/20100724/screen_grab.png

You can see that some markers are correctly drawn when they are not
completely contained within a tile and others are not.
I tried extending the tile bounds by hardcoded values (larger than the
map's current zoom level) thinking that maybe i wasn't extending the
tile bounds by enough pixels but it didn't work.

My tile creation script can be found here:

http://developer.martinpearman.co.uk/www.shipfinder.co.uk/20100724/ship_layer_tile.txt

And the Google Maps Book utility script here:

http://developer.martinpearman.co.uk/www.shipfinder.co.uk/20100724/GoogleMapUtility.txt

My original plan was to create all tile URLs with just tile x, tile y
and zoom level passed to the server and then the server would extend
the tile bounds if the zoom level was 8 or higher.
Using the Google Maps Book utility, i could get the map pixel bounds
of a tile which i could then extend by the required number of pixels,
but i couldn't then convert that extended pixel bounds back to lat/lng
bounds needed for the database query.

The original Google Maps Book utility contained a method to convert
pixel coordinates to lat/lng coordinates but it didn't work and to me
looks like buggy code.

http://www.googlemapsbook.com/chapter7/ServerCustomTiles/GoogleMapUtility.php.source#l7-11

public static function fromXYToLatLng($point,$zoom) {
$scale = (1 << ($zoom)) * GoogleMapUtility::TILE_SIZE;

return new Point(
(int) ($normalised->x * $scale),
(int)($normalised->y * $scale)
);

return new Point(
$pixelCoords->x % GoogleMapUtility::TILE_SIZE,
$pixelCoords->y % GoogleMapUtility::TILE_SIZE
);
}

Two return statements and undefined variables?

Anyway whether the bounds are extended client side or server side
doesn't matter - as long as it works!

Can anyone take a look at my map and code and see where it's failing?

Thanks a lot.

Martin.

--
You received this message because you are subscribed to the Google Groups "Google Maps API" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate