tombatossals / angular-leaflet-directive

AngularJS directive to embed an interact with maps managed by Leaflet library
http://tombatossals.github.io/angular-leaflet-directive
MIT License
1.5k stars 635 forks source link

Make overlays and base layers refreshable [feature request] #730

Closed pieterjandesmedt closed 9 years ago

pieterjandesmedt commented 9 years ago

In layers.js there are checks to see if a layer needs to be deleted. These checks can be modified to make a layer refreshable: Line 76

    if (!isDefined(newBaseLayers[name])) {

becomes

    if (!isDefined(newBaseLayers[name]) || newBaseLayers[name].refresh) {

and line 126

    if (!isDefined(newOverlayLayers[name])) {

becomes

    if (!isDefined(newOverlayLayers[name]) || newOverlayLayers[name].refresh) {

then you can do this:

overlays: {
    trafficSpeed: {
        name: 'Traffic Speed',
        type: 'xyz',
        url: urlConfig.mapUrls.trafficSpeed,
        visible: false,
        refresh: true    // <----
    }, ...

and make an angular service refresh the layer every minute or so.

tombatossals commented 9 years ago

It seems interesting. What do you think about this @nmccready?

nmccready commented 9 years ago

I would change refresh to be more obvious that it is a boolean. Like doRefresh that is if it is a boolean, it could be a function.

nmccready commented 9 years ago

But yes this makes sense. I hope there are checks in the scope.$watch('layers', function()) to make sure it really has changed as well.

tombatossals commented 9 years ago

Ok! Agree with the "doRefrest". I'm coding this.

@pieterjandesmedt, do you have any example of dynamic overlay layer which could be added to an example to test this funcionality?

nmccready commented 9 years ago

I was looking at his fork; and it looks like he started the code changes. However he is missing examples.

pieterjandesmedt commented 9 years ago

The traffic speed layers on http://www.10miles.be-mobile.biz/web/apps/10miles/#/map are refreshed every minute, however it is using an older version of your excellent library. Layer url is http://map.be-mobile.be/customer/mobileninja/nl/los/{z}/{x}/{y}.png. I append a rand query parameter to the url to force refresh, e.g. ?rand=0.7992366699036211.

j-r-t commented 9 years ago

You should submit your changes, I'm sure I will find this one especially useful

https://github.com/pieterjandesmedt/angular-leaflet-directive/commit/8b62ffbdf59efc9008230a2fa6c6db9a630b1db7

pieterjandesmedt commented 9 years ago

@jessertaylor Unfortunately, that particular fix doesn't seem to work anymore. A fix like that used to work in previous versions (at least in the version of 27-10-2014). But this example might be useful, I haven't tested it yet for translations.