弹出窗口无法正常使用圆形标记

时间:2016-06-21 13:44:32

标签: angularjs leaflet angular-leaflet-directive ui-leaflet

我在ui传单插件中遇到圆圈标记问题。当有人点击一个圆圈即可获得弹出窗口,但是如果我在地图中的圆圈外点击然后再次尝试点击圆圈,则弹出窗口不会出现。

你能否说一下可能出现的问题?这有什么解决办法吗?

重现的步骤

  1. 在地图中点击一个圆圈标记
  2. 将圆圈标记移出地图范围
  3. 然后尝试点击弹出窗口中不会出现的任何其他标记
  4. 如果我在圈子外单击并再次点击圈子,则会再次显示弹出窗口
  5. 以下是代码片段,如果您需要完整代码,请访问此github链接

    https://github.com/Umamaheswaran1990/learningleaflet

    enter image description here

    HTML

    <!DOCTYPE html>
    <html ng-app="demoapp">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="../bower_components/angular/angular.min.js"></script>
        <script src="../bower_components/leaflet/dist/leaflet.js"></script>
        <script src="../bower_components/angular-simple-logger/dist/angular-simple-logger.js"></script>
        <script src="../bower_components/ui-leaflet/dist/ui-leaflet.min.js"></script>
        <link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
        <script src="app.js"></script>
    </head>
    <body ng-controller="LayersSimpleController as vm">
        <leaflet center="center" tiles="tiles" paths="paths" width="50%" height="480px"></leaflet>
    </body>
    </html>
    

    JS

    var app = angular.module("demoapp", ['ui-leaflet']);
    app.controller("LayersSimpleController", ["$scope", function ($scope) {
        var vm = this;
    
        $scope.$on('leafletDirectiveMap.map.load', function (event, data) {
            var map = data.leafletObject;
            map.attributionControl.setPrefix(false);
        });
    
        $scope.$on('leafletDirectiveMap.moveend', function (event, data) {
            activate();
        });
    
        var map = [
            { "lat": 30.7559, "lon": -96.489 },
            { "lat": 41.8887, "lon": -111.769 }];
    
        angular.extend($scope, {
            center: {
                lat: 39.774769,
                lng: -98.789062,
                zoom: 4,
                minZoom: 4,
                zoomControl: true,
            },
            events: {},
            tiles: {
                url: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
                options: {
                    subdomains: ['otile1', 'otile2', 'otile3', 'otile4']
                },
                layers: {},
                defaults: {
    
                }
            }
        });
    
        activate();
    
        function activate() {
            $scope.paths = {};
            angular.forEach(map, function (value, key) {
                if (value.lat !== null && value.lon !== null) {
                    $scope.paths['circle' + key] = {
                        type: 'circleMarker',
                        className: 'testClass',
                        fillColor: 'DarkSlateGray',
                        color: '#000000',
                        weight: 0,
                        opacity: 1,
                        message: 'This is a test marker',
                        fillOpacity: 0.8,
                        stroke: false,
                        clickable: true,
                        latlngs: [parseFloat(value.lat), parseFloat(value.lon)],
                        radius: 20
                    };
                }
            });
        }
    }]);
    

1 个答案:

答案 0 :(得分:0)

我通过添加

来实现它
event-broadcast="events"

到index.html中的leaflet元素,并添加

 events: {
          path: {
                 enable: ['click']
                 }
         },

到app.js

我不确定为什么这是必要的,因为ui-leaflet事件示例表明默认情况下启用了所有广播事件。 http://angular-ui.github.io/ui-leaflet/examples/0000-viewer.html#/basic/events-example