Comments (4)
Hi,
Sorry for the wait. Probably you have found the solution by yourself in the meantime.
In case not, I think it's because your forgot to add the decorators to the map. PolylineDecorator
instances are map layers themselves, so they to be explicitely added to the map.
The code snippet you provided actually creates a PolylineDecorator
for each layer object, but it is discarded as soon as the function exits, as it is not stored in a variable or added to the map.
If your map object is in a variable named map
, it should be something like that:
onEachFeature: function (feature, layer) {
L.polylineDecorator(layer, {
patterns: [
{offset: 25, repeat: 30, symbol: L.Symbol.arrowHead({pixelSize: 15, pathOptions: {fillOpacity: 1, weight: 0}})}
]
}).addTo(map);
}
This should work.
Alternative
As a single instance of PolylineDecorator
can decorate mulitple polyline objects, you can chose another solution, not relying on eachFeature
. Just instantiate the decorator after you loaded the GeoJSON, passing it the array of Polyline
s built by the GeoJSON
Leaflet object (getLayers
method).
If all your geometries are LineStrings/Polylines and use the same patterns, it's simpler, and also better performance-wise.
Hope it helped :)
Cheers!
P.S. : tags on GitHub issues are named "labels". You should be able to assign them right next to your message, after you created it.
from leaflet.polylinedecorator.
Thanks for the reply. I got both your options to work, but I think (unless there's a better way) I need to use the one within onEachFeature to filter out all the ways without a relation's 'role' set:
if (feature.properties.relations[0].role) {
L.polylineDecorator(layer, {
patterns: [
{offset: 15, repeat: 30, symbol: L.Symbol.arrowHead({pixelSize: 15, pathOptions: {fillOpacity: 1, weight: 0}})}
]
}).addTo(TwoTunnelsCircuitGroup)
}
This leads on to my next problem. Is there a simple way within decorator to rotate the symbol 180 degrees so that they point in the correct direction for any 'roles' that are set to 'backward'? The only other way I can think of is to reverse the coordinates for those ways.
Cheers
Dave F.
from leaflet.polylinedecorator.
Glad it helped :)
I still think you can use a single PolylineDecorator
, while using onEachFeature
only for the filtering and selection (for example, putting features with your role
attribute in another array, and passing this array to the PolylineDecorator), but maybe your case is more complicated than that.
Anyway, I'll consider your issue fixed.
For your second question, can you please open a separated issue? It will be easier for other people to find it if they have the same question. I'll reply to it quickly.
Thanks a lot!
from leaflet.polylinedecorator.
Hi
I still think you can use a single PolylineDecorator
I shall look into it in more detail.
For your second question, can you please open a separated issue?
Done
from leaflet.polylinedecorator.
Related Issues (20)
- How in leaflet add custom data to polyline?
- I'd like to ask you how to add slashes to polygons, like this
- how do i delete some arrow on the map HOT 1
- Separate colors for stroke, fill HOT 1
- Markers Color HOT 9
- Leaflet polyline decorator HOT 1
- Decorator onclick event retrieve property HOT 1
- How to disable arrow auto scale? HOT 2
- Using polylineDecorator with ant-path is not working HOT 1
- Show/Hide Polylinedecorators dynamically (based on other variable) in React Leaflet
- Is there any option to prevent collision between arrows?
- How to add multiple arrows in one line๏ผ HOT 2
- How do I make my arrowhead pointy? HOT 2
- Issue with Leaflet.PolylineOffset
- rotationAngle conflicts with Leaflet.RotatedMarker HOT 4
- L.polylineDecorator is Undefined HOT 2
- PolylineDecorator always top layer even when calling bringToBack() HOT 3
- Polyline decorator doesn't preserve the state of symbol styling HOT 1
- Problem with fullscreen control
- Problem with using method setPaths
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet.polylinedecorator.