simplegeo / polymaps

Polymaps is a free JavaScript library for making dynamic, interactive maps in modern web browsers.
http://polymaps.org/
Other
1.6k stars 213 forks source link

URL placeholders are tile indices? How to reference location instead? #53

Open stodge opened 13 years ago

stodge commented 13 years ago

The documentation on URL placeholders is minimal, but I assume X,Y are the indices of the tile and Z is the zoom factor. I'm writing my own small custom server as I have my own dataset. My server (Django) doesn't have the concept of tiles and my dataset is not in lat/long coordinate space. How can I turn the X/Y/Z tuple into basic coordinates so I can respond wiht only the required data? Thanks

RandomEtc commented 13 years ago

http://polymaps.org/docs/url.html is indeed a bit minimal :) I've tagged this issue as doc so that we'll remember to clean that up at some point.

Meanwhile, you might try using a {B} parameter in your url template. This will make a tile request using a north,west,south,east latitude and longitude bounding box instead of tile indices.

If your data isn't in latitude and longitude then you need to invent a tile scheme for it. Typically, zoom level 0 is a single 256px tile and contains all your data. Zoom level 1 is 2x2 tiles, so you'd scale your data to fit a 512px tile and then move it depending on the tile indices. A full tutorial for this isn't really in the scope of a github issue thread though, nor a coffee break support session :)

shawnbot commented 13 years ago

+1 what Tom said. The URL format is "{Z}/{Y}/{X}", where Y and X are WGS84 latitude and longitude, respectively. If your dataset isn't in WGS84 you might consider reprojecting it either once permanently or at runtime. GeoDjango does a lot of this, and can build queries that intersect geometries in your database with the bounding boxes of individual tiles. TileStache also has a built-in GeoJSON provider, but that requires that you back onto Postgresql, so it may not work for you.

stodge commented 13 years ago

Thanks. I am using Postgresql/postgis.

The {B} helped, though the svg generated by polymaps is invalid:

Error: Problem parsing d="M-10105303.040000001,NaNL-9822770.062222224 etc

Likely I'm returning dodgy data.

Thanks again.

RandomEtc commented 13 years ago

Are you using GeoJSON? GeoJSON coordinates must be in latitude and longitude degrees to be understood by Polymaps. The NaN will happen with latitude approaching (or over) +/- 90º I think.

You might just have lat/lon mixed up? A GeoJSON coordinate should be [ lon, lat ] (think x,y), even though people commonly say 'latitude and longitude' just to confuse things.

stodge commented 13 years ago

Right I remember reading that. Yes I am using geojson, though I'm using a local coordinate system, not lat/long. My coordinates range from approx -5000,-5000 to 5000,5000. So geojson won't work.

mbostock commented 13 years ago

You don't need to use po.url; that's just the default implementation of the URL template. You can pass in any function that takes a coordinate object (row, column, zoom) and returns a string. There's a bit more details here:

http://polymaps.org/docs/image.html#url