1

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

你能建议可能是什么问题吗?有什么解决方法吗?

重现步骤

  1. 在地图中单击一个圆圈标记
  2. 将圆圈标记移出地图范围
  3. 然后尝试单击不会出现弹出窗口的任何其他标记
  4. 如果我在圆圈外单击并再次单击圆圈,则会再次出现弹出窗口

以下是代码片段,如果您需要完整代码,请访问此 github 链接

https://github.com/Umamaheswaran1990/learningleaflet

在此处输入图像描述

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
                };
            }
        });
    }
}]);
4

1 回答 1

0

我通过添加让它工作

event-broadcast="events"

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

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

到 app.js

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

于 2016-09-20T15:52:13.697 回答