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

Unable to double-click zoom on region marked with GeoJson #1135

Open Kamilius opened 8 years ago

Kamilius commented 8 years ago

When I'm double-clicking on region highlighted with help of attribute geojson, nothing happens. http://tombatossals.github.io/angular-leaflet-directive/examples/0000-viewer.html#/basic/geojson-update-example

If I'm doing same thing in original leaflet - http://leafletjs.com/examples/choropleth.html (ex. "Adding some color" example"), it zooms in.

Any tip on fixing this behavior?

yukk1 commented 8 years ago

Add onEachFeature to the geojson of http://tombatossals.github.io/angular-leaflet-directive/examples/0000-viewer.html#/basic/geojson-update-example

angular.extend($scope, {
    center: { ... },
    geojson : {
        data: { ... },
        style: { ... },
        onEachFeature: function (feature, layer) {
            layer.on({
              click: function () {

                // Fit the map to the bounds of the rectangle
                leafletData.getMap().then(function (map) {
                  map.fitBounds(layer.getBounds());
                });

                // Or zoom in
                 if ($scope.center.zoom < 6) {
                   $scope.center.zoom ++;
                 }
              }
            })
        }
    }          
 });