tombatossals / angular-openlayers-directive

AngularJS directive to embed an interact with maps managed by the OpenLayers library
http://tombatossals.github.io/angular-openlayers-directive/
MIT License
282 stars 183 forks source link

olpath directive doesnot create path if scope variable updates #367

Open JcDenton86 opened 7 years ago

JcDenton86 commented 7 years ago

Hello,

I am trying to build a path using <ol-path coords={{map.path}}></ol-path> and my controller looks like this:

app.controller('mapController', ['$scope','$timeout', function($scope,$timeout) {
    var map = this;
    $timeout(function(){
        map.path = [[[-58.38,-34.60], [-58.58,-34.60],[-58.38,-34.70], [-58.38,-34.80]]];
    }, 250);
}

Debugging your directive the coords array is empty. Instead If I remove the $timeout the path works. The problem is that I am fetching the path dynamically from an API and the building it. Tried with $digest and $apply and also added $watch in the directive with no result.. Any help is appreciated, thanks

holgeric commented 7 years ago

Hi,

I had the same issue (ol-path only has a link method, so it won't update once rendered), so I ended up with this workaround:

        <ol-path ng-if="ctrl.pathFlag" coords="{{ctrl.coords}}"></ol-path>
        <ol-path ng-if="!ctrl.pathFlag" coords="{{ctrl.coords}}"></ol-path>
    </openlayers>