How to get lat / lng information for clicks on a booklet map in angular ui

I am creating a fairly simple web application with Angular.js and a worksheet.

I am trying to get lat / lng information from clicks on a map, and I am having problems finding any documents on integrating event handlers from List in Angular.

if someone can point me in the right direction, I would become a topic.

code below:

app.controller("eventcrtl", [ '$scope', function($scope) {
    $scope.$on('leafletDirectiveMap.click', function(event){
      console.log(event.latlng);
    });
}]);

does not work

+4
source share
1 answer

To handle events, first define an event object in your scope ...

angular.extend($scope, {
    events: {
      map: {
        enable: ['click', 'drag', 'blur', 'touchstart'],
        logic: 'emit'
      }
    },
    ...

and add it to your leaflet.

<leaflet event-broadcast="events"></leaflet>

Then you can access the latitude and longitude inside the args parameter of the click handler:

$scope.$on('leafletDirectiveMap.click', function(event, args){
    console.log(args.leafletEvent.latlng);
});

: http://plnkr.co/PxRDhz6S5Svsg9FG4VRk

+16

Source: https://habr.com/ru/post/1535126/


All Articles