seek
seek

Reputation: 1105

Is there any method to draw Path (Polyline) on Leaflet with constant width/stroke in meters instead pixels?

Does anyone known any working method to draw polylines on Leaflet with constant width in meters?

I can't find any working solutions for this. Documentation about Leaflet Path have only stroke with weight in pixels.

Upvotes: 3

Views: 2406

Answers (3)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35134

I've just published leaflet-corridor plugin which does exactly what you asked for: draws a polyline with width fixed in meters.

Demo

Github repository

Usage:

var corridor = L.corridor([/*Array of L.latlng*/], widthInMeters);
map.addLayer(corridor);

Upvotes: 3

Kade Keith
Kade Keith

Reputation: 228

Your map tile provider probably provides the meters/pixel data for all the zoom levels. OpenStreetMaps example: http://wiki.openstreetmap.org/wiki/Zoom_levels

Then add an event to zoomend that scales the strokewidth of your polyline(s) based on the current zoom level.

Upvotes: 0

kiwixz
kiwixz

Reputation: 1398

There isn't any method like that, but knowing the density of pixels on the screen, you can get the number of pixels you need for 1 meter.

Upvotes: 1

Related Questions