Leaflet.PolylineDecorator with GeoJSON layer

572 views
Skip to first unread message

k_man_au

unread,
Mar 28, 2014, 12:46:35 AM3/28/14
to leafl...@googlegroups.com
Hi,

Would anyone have a good example of applying Leaflet.PolylineDecorator to a GeoJSON layer.

The code I'm using to load up the layer currently is 

var lines= L.geoJson(LineFeaturesFromAjaxRequest, {
style: LineStyle,
onEachFeature: onEachFeatureLine
}).addTo(map);

I've tried applying the adding the layer to an L.polylineDecorator and then adding the L.polylineDecorator to the map, but doesn't seem to work. Is there any way to apply from within onEachFeature, as this would be ideal?

cheers

k_man_au

unread,
Apr 11, 2014, 2:27:17 AM4/11/14
to leafl...@googlegroups.com
Can anyone help?

Dave F.

unread,
Nov 5, 2014, 4:53:05 PM11/5/14
to leafl...@googlegroups.com
Hi

I'm having the same problem as you. Did you ever find a solution? I suspect it /may/ be because geojson's co-ordinates are Lng/Lat format but Decorator uses Lat/Lng? But I know so little about JS that even swapping them around is beyond me

Cheers
Dave F>.

PJ Hooker

unread,
Aug 3, 2015, 5:59:17 PM8/3/15
to Leaflet
I use this code and works ... but I can't pass properties for dinamic color

 $.getJSON("https://raw.githubusercontent.com/pjhooker/monferratopaesaggi/master/pl_linee_pano_0.geojson", function(data) {
 
var exp_linee = L.geoJson(data, {
 onEachFeature
: function (feature, layer) {
    L
.polylineDecorator(layer, {
        patterns
: [
 
{ offset: 12, repeat: 25, symbol: L.Symbol.dash({pixelSize: 10, pathOptions: {color: '#f00', weight: 2}}) },
               
{ offset: 0, repeat: 25, symbol: L.Symbol.dash({pixelSize: 0}) }
       
]
   
}).addTo(linee1);
 
}
 
});



Reply all
Reply to author
Forward
0 new messages