I am trying to create a map using Angular-Leaflet-Directive and data from two different Angular services that call web services using the $ resource. These services return JSON messages that include lat / long values ββfor filling markers on the map.
However, I cannot get a directive to use data from services.
I see that my services update the scope, so they work fine, and map markers are displayed correctly if I hard-code the values ββin the controller (for example, see below "center"). What I want to do is very similar to this example
Here is my code:
Controller:
angular.module('myDetails', ['leaflet-directive', 'shop', 'home']) .controller('MyDetailsCtrl', ['$scope', '$routeParams', '$http', '$q', '$rootScope', 'shopService', 'homeService', function ($scope, $routeParams, $http, $q, $rootScope, shopService, homeService) { function getShop() { var d = $q.defer(); var shop = shopService.get({shopId: $routeParams.shopId}, function (shop) { d.resolve(shop); }); return d.promise; } function getHome() { var d = $q.defer(); var home = homeService.get({homeId: $routeParams.homeId}, function (home) { d.resolve(home); }); return d.promise; } $q.all([ getShop(), getHome() ]).then(function (data) { var shop = $scope.shop = data[0]; var home = $scope.home = data[1]; var markers = { shop: { lat: $scope.shop.loc.coordinates[0], lng: $scope.shop.loc.coordinates[1], draggable: false, message: $scope.shop.name, focus: true }, home: { lat: $scope.home.loc.coordinates[0], lng: $scope.home.loc.coordinates[1], draggable: false, message: $scope.home.name, focus: true } }; console.log("Markers are " + angular.toJson(markers)); $scope.markers = markers; }); $scope.center = { lat: 53.26, lng: -2.45, zoom: 6 }; }]);
What I find is that my 2 services are returning, the update area is updated with values, but this is not passed to the angular -leaflet directive.
Angular's directive documentation assumes that the following code in the directive will associate child regions with the parent region so that they are both updated:
scope: { center: '=center', maxBounds: '=maxbounds', bounds: '=bounds', marker: '=marker', markers: '=markers', defaults: '=defaults', paths: '=paths', tiles: '=tiles', events: '=events' }
but it doesn't seem to work for me. However, the angular path to the elevator directive seems to resolve this (you can add markers, change markers, etc.) and update maps in real time.
What do I need to do so that the markers appear on my map after the services are returned?
Note that there is a similar question for Stackoverflow, but the answer to these questions is to enable service calls in the Directive. I do not want to do this, because the controller offers more functionality than just a direct call to a service, such as processing a form, etc. And requires access to the same data.