Generating map tiles (dynamically?) from SQL/CSV data -
here's have:
sql table/csv file "tile xyz" coordinates (web mercator tile coordinates) , "data/color"
x y z color 13 13 5 yellow 13 14 5 green 13 14 5 red ...
data structure easy, no fancy stuff needed, can draw pngs code.
- amount of data large, i.e. worldwide tiled, zoomlevel 15
what want:
- png tiles
- underlying data should not accessible
- show png tiles webpage map of leaflet/google maps api
problem/question:
- too data generate tiles worldwide before (takes days)
- i therefore thinking dynamic caching/tile creation algorithm (maybe create zoomlevel 0-9 before, higher zoom levels created dynamically)
- it seems there many tools out there (tilemill, tilestache, arcgis server, etc) of them seem have high learning curve or meant more complex tasks.
- is there way run lean server fits needs? maybe php script queries database, draws png , feeds map on-demand? how work exactly? clever solution?
thanks much.
i went through similar problem: having tile indexes, return points of table fell corresponding bounding box.
backend
since using postgresql + postgis bbdd, used function that's defined in peter warden's postgis2gmap repo.
bounds_for_tile_indices(lat_index float8, lon_index float8, zoom_level int)
this takes latitude , longitude coordinates tile, , zoom level, , returns geography object containing bounding box tile. use limiting queries on geographic data particular tile, eg;
select * checkins st_intersects(lonlat, bounds_for_tile_indices(6, 2, 4);
now, use case, might not have every possible tile stored given table, can still use said function determine bounding box of given tile coords:
select box2d(bounds_for_tile_indices(13, 14, 5)::geometry);
which returns
box(-22.5 21.9430434618232,-11.25 31.9521604783552)
please note i'm explicitly casting output of bounds_for_tile_indices
geometry, since native output geography , cannot apply box2d on geography.
since you'll have table of tile coordinates instead of geometries, former method might overkill.
you need query table given x/y/x combination, color need, , generate 256x256px image of given color, using imagefill. quoting docs example:
$im = imagecreatetruecolor(100, 100); // sets background red $red = imagecolorallocate($im, 255, 0, 0); imagefill($im, 0, 0, $red);
or, keep limited collection of 256x256px png files, use color got query build path right image, , use imagecreatefrompng create final result you'll send front proper image header treated png.
as see, drawing plain colored tiles easy, went through first part because believe tiles aren't plain in question.
frontend
in front, need declare custom map type (in particular, use case google.maps.imagemaptype
)
var mytilesmap = new google.maps.imagemaptype({ gettileurl: function (coord, zoom) { return "/my_backend/" + coord.x + "/" + coord.y + "/" + zoom; }, tilesize: new google.maps.size(256, 256), name: "mytiles" }); map.overlaymaptypes.insertat(0, mytilesmap);
Comments
Post a Comment