TileLayer.TileJSON: point radius in meters?

558 views
Skip to first unread message

Jack Michel

unread,
May 26, 2012, 7:35:45 AM5/26/12
to leafl...@googlegroups.com
Hello!

I'm using the great TileLayer.TileJSON.js extention [1] for leafletjs.
I want to draw points on the map depending on the zoom level and with an exactly size in meters.

Currently I use this style:

tile.styleFor = function (feature) {
        var type = feature.geometry.type;
        var styleColor = feature.properties.style.color;
        switch (type) {
            case 'Point':
                return {
                    color: styleColor,
                    radius: 3 // what's the unit?
                };
           
        }
    };

The radius value is used in the TileJSON.js the following:

g.arc(p.x, p.y, style.radius, 0, Math.PI * 2);

I'm wondering which unit is the radius value? Are these meters? If not, how can I set this value to meters?
I'm using the default Openstreetmap projection.

Thank you for your help!

Best regards,
Jack

[1] https://gist.github.com/2479540

Diego Guidi

unread,
May 26, 2012, 8:37:20 AM5/26/12
to leafl...@googlegroups.com
> I'm using the great TileLayer.TileJSON.js extention [1] for leafletjs.
happy to read that you like it :)

> The radius value is used in the TileJSON.js the following:
>> g.arc(p.x, p.y, style.radius, 0, Math.PI * 2);
> I'm wondering which unit is the radius value? Are these meters? If not, how
> can I set this value to meters?
> I'm using the default Openstreetmap projection.

the unit here is in pixels, and is completely indipendent of
projection or even zoom factor.
If you want to draw a point that has a radius of 50 meters, you must
evaluate some points.
I'm not sure about this, so feel free to verify and to check better
what I write.
If you use spherical mercator projection (the same used by google and bing)
a pixel at the maximum zoom is a meter, so you simply must set radius
value as 50 / (2 * currentzoom).

Some useful references:
http://www.sharpgis.net/post/2007/05/spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing.aspx
http://www.sharpgis.net/post/2007/07/The-Microsoft-Live-Maps-and-Google-Maps-projection.aspx
http://msdn.microsoft.com/en-us/library/bb259689.aspx

Jack Michel

unread,
May 27, 2012, 5:46:18 AM5/27/12
to leafl...@googlegroups.com
Hello Diego!


Am Samstag, 26. Mai 2012 14:37:20 UTC+2 schrieb Diego Guidi:
If you use spherical mercator projection (the same used by google and bing)
a pixel at the maximum zoom is a meter, so you simply must set radius
value as 50 / (2 * currentzoom).

Do you mean with "currentzoom" the zoomlevel like 17? If so, the pixel value for a 50m point would be 1,47.
I tried this, but comparing to the elements on my map (streets, buildings) in zoom level 17, the point looks too small.

I found on the Openstreetmap wiki some information about "meters per pixel" [1]. This document says that I have at zoom level 17 about 1,193 meter per pixel. Therefore the radius value (in pixel) for a 50m point would be (50m/1,193 pixel)/2 =  20.95

I'm not sure, if this is calculation is right. The point size on level 17 looks good, I think.
Is there a better - more scientific - solution?

[1] http://wiki.openstreetmap.org/wiki/Zoom_levels

Diego Guidi

unread,
May 27, 2012, 5:57:42 AM5/27/12
to leafl...@googlegroups.com
> I found on the Openstreetmap wiki some information about "meters per pixel"
> [1]. This document says that I have at zoom level 17 about 1,193 meter per
> pixel. Therefore the radius value (in pixel) for a 50m point would be
> (50m/1,193 pixel)/2 =  20.95
I'm sure this is right. Looks strange that a "actual" size in meters
of a pixel depends on current zoom, but maybe you can search for this
and other explainations also in google/openlayers forum.
Please share results of your experiments :)
Reply all
Reply to author
Forward
0 new messages