-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use leaflet directive multiple time at once. #331
Comments
Hi, have you tried passing an id to the "leaflet" tag? The leafletData object stores a leaflet object based on the id, so it will be able to fetch the required map object when you ask for it. For example:
Then you can use:
Take a look at this example code: I think this will solve the behaviour you are experiencing. |
This is kind of happening to me too with async loaded views, when I go back and forth between these views the current leaflet map inherits the center of the previous leaflet map. |
Can you guys code a simple case where I can see this behaviour? You could fork this jsfiddle example as a starting point: |
Is this example OK? You may change some of scope preperties directly through the scope methods. |
There is an issue with the _layersControl when you have multiple maps: it is also a singleton. I have fixed it replacing "var _layersControl;" by "var _layersControl = [];" and every occurrence of the variable "_layersControl" by "_layersControl[mapId]". Seemed to work for me, though I am sort of newbie both in angularjs and leaflet, and I'm not sure if this is the best solution. Hope you hackers could take it from here, maybe... By the way, thanks for the good job!! |
I'm seeing this as well. All of the markers which are on layers (feature group) are applied to the first map on the page. This includes using marker clustering. If the markers are not on layers, then the markers get applied to the proper map. But our use case requires that all of the markers be in separate layers/feature groups. So this limits us to using only one map per page, which is a significant limitation that we would like to see removed. |
Having this issue as well. Having an issue building a dynamic map that has the ability to toggle various geojson and popup data. I've settled on having multiple maps on the page, and show/hiding them, but now that i've built that, I'm finding that I can't have more than one map showing different data on one page. I've tried passing the id solution as above with no luck unfortunately. |
Hey guys, can anyone make a jsfiddle where I can see this behaviour? |
@flashpunk, do you mean that you can't show two maps on the web page with different markers on each one? Is there some more complexity on your code? I'm going to try to make a jsfiddle myself |
http://jsfiddle.net/4PhzC/168/ This jsfidle could be an starting point. Could anyone ellaborate a more complex example where we can see the failure? |
I'm using multiple maps with different geojson data on each one (not markers) - also including data, style, and onEachFeature popups for each geojson boundary. |
Ok, so i've been playing with your example above, with some of the extra features i'm using and it seems to be working... |
Fantastic example. Would you mind if I put this code in the project as an example of how to use multiple maps and geojson data at the same time? |
Just found this bug with ng-show/ng-hide - the map on the show/hide doesn't seem to want to draw: http://jsfiddle.net/flashpunk/vosru6t9/1/ Sure feel free to use the example. |
Yes, the ng-show/ng-hide behaviour is related with leaflet, which needs to call "invalidateSize" when the size of the div is changed. You can easily solve this using ng-if instead of ng-show: http://jsfiddle.net/bL69rzch/1/ I'll add your example to the project, thanks. |
FYI, I ended up scrapping this method, and using this gist: https://gist.github.com/pospi/85c31530c4a93cf091ce It destroys the layer and recreates a new one. I've also had to hack a way to destroy the legend and create a new one whenever the button was created (that was done with Can probably create a fiddle at some point with an example for anyone else needing this type of functionality. |
Hi @flashpunk, just added your example here: http://tombatossals.github.io/angular-leaflet-directive/examples/double-map-sharing-attributes.html Thanks for sharing |
That example is helpful but it still isn't quite what I need. I debugged this a lot more today. Basically, I need to pass in dynamic names to the directive via the attribs. But since the directive uses isolated scope with = (two way data binding) you cannot use data binding in the attribs. Do you really need to be bound in both directions? Should the directive really be modifying the event-broadcast, markers, paths, or layers objects? It seems like these should be input only? Here is what I need to work:
But this fails with Angular exceptions since you can't use data binding for these attributes. |
@Splaktar This isn't the full answer you're looking for, but in the end I was able to render multiple different maps by modifying and using this directive: https://gist.github.com/pospi/85c31530c4a93cf091ce |
Wondering if anyone has any insight on the following TypeError (seems to likely be related to this issue). I have two maps,
I should not this occurred when employing |
This issue was moved to angular-ui/ui-leaflet#11 |
I'm going to rework&redesign angular-leaflet-directive to be compatible with Leaflet v1.0. It will mantain almost all its functionality, and will be compatible with the current features of the directive, but I must start from a fresh point, so I'm going to close this issue. If you think it must be worked with the new version, please reopen it. |
This is still not working or me. Multiple maps each is updating it center when moving the other. Causes tiles to not load as well. I have different ID's for the maps and different controllers. |
Hello,
The _leafletMap directive variable singleton in the root directive cause leaflet to crash in various way if more than one map is used at the same time in the application. ( all maps use the variable, causing previous maps to loose reference to their own map at one point )
Fix should be easy using a scope variable instead of directive singleton to store the map promise.
The text was updated successfully, but these errors were encountered: