无法在多边形内部单击KML图层

5
我的问题很简单,但我找不到解决方法。我正在使用AngularJS和Angular Google Maps(https://github.com/angular-ui/angular-google-maps)。我有一个简单的地图,只有一个多边形和一个KML图层,其中显示了一个单独的标记在多边形内部。但是我不知道为什么,我无法点击标记。我在地图上放置了两个不同的KML图层,所以您可以看到外部的那个可点击,而内部的那个不可点击。您可以在下面看到代码:

'use strict';
angular.module("map", ['uiGmapgoogle-maps'])

.controller("MapController",['$scope', '$http', function ($scope, $http) {
 $scope.map = {
  center: {
   latitude: 48.80913908755741,
   longitude: 3.0915678394317014
  },
  zoom: 12,
  bounds: {}
 };

 $scope.polygons = [{
  id: 1,
  path: [
   { latitude: 48.825218, longitude: 3.050508 },
   { latitude: 48.823409, longitude: 3.101664 },
   { latitude: 48.792885, longitude: 3.111105 },
   { latitude: 48.793224, longitude: 3.060465 }
  ],
  stroke: {
   color: '#584885',
   weight: 2
  },
  editable: false,
  draggable: false,
  geodesic: false,
  visible: true,
  clickable: false,
  zindex: -1,
  fill: {
   color: '#E6E6E6',
   opacity: 0.6
  }
 }];

 $scope.kmlLayerOptions1 = {
  url: "http://nanakii.fr/up/ligne_bus.kml",
  preserveViewport: true
 };
 $scope.kmlLayerOptions2 = {
  url: "http://nanakii.fr/up/ligne_bus2.kml",
  preserveViewport: true
 };
 $scope.showKml = true;
}]);
* { margin: 0; padding: 0;}

body, html { height:100%; }

.angular-google-map-container  {
    position:absolute;
    width:100%;
    height:100%;
}
<html ng-app="map">

<head>
 <script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
 <script src="http://rawgit.com/angular-ui/angular-google-maps/master/dist/angular-google-maps_dev_mapped.js"></script>
 <script src="//maps.googleapis.com/maps/api/js?libraries=weather,geometry,visualization,places&sensor=false&language=en&v=3.17"></script>
</head>

<body ng-controller="MapController">
 <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" bounds="map.bounds">
  <ui-gmap-polygon static="true" ng-repeat="p in polygons track by p.id" path="p.path" stroke="p.stroke" visible="p.visible" geodesic="p.geodesic" fill="p.fill" fit="false" editable="p.editable" draggable="p.draggable">
  </ui-gmap-polygon>
  <ui-gmap-layer type="KmlLayer" options="kmlLayerOptions1" show="showKml"></ui-gmap-layer>
  <ui-gmap-layer type="KmlLayer" options="kmlLayerOptions2" show="showKml"></ui-gmap-layer>
  <ui-gmap-marker coords="marker.coords" options="marker.options" idkey="marker.id"></ui-gmap-marker>
    </ui-gmap-google-map>
</body>
</html>

我尝试了许多选项,但没有结果。我在这里找到一个旧问题,与相同的问题,但答案并没有解决它。(如果在多边形内部,则无法从KML中单击点)
任何帮助都将是极好的!谢谢!

编辑:

我也尝试过不使用Angular,所以问题直接来自于Google Maps。 您可以在多边形外的公交线路上单击,但无法在内部单击。

您可以在此处测试代码(片段未能正常工作): http://nanakii.fr/dev/test/gmap.php

2个回答

2

您忘记为指令设置clickable参数(演示也没有设置clickable属性):

<ui-gmap-polygon clickable="p.clickable" >

'use strict';


angular.module("map", ['uiGmapgoogle-maps'])

.controller("MapController", ['$scope', '$http',
  function($scope, $http) {
    $scope.map = {
      center: {
        latitude: 48.80913908755741,
        longitude: 3.0915678394317014
      },
      zoom: 12,
      bounds: {}
    };

    $scope.polygons = [{
      id: 1,
      clickable: false,
      path: [{
        latitude: 48.825218,
        longitude: 3.050508
      }, {
        latitude: 48.823409,
        longitude: 3.101664
      }, {
        latitude: 48.792885,
        longitude: 3.111105
      }, {
        latitude: 48.793224,
        longitude: 3.060465
      }],
      stroke: {
        color: '#584885',
        weight: 2
      },
      editable: true,
      draggable: false,
      geodesic: false,
      visible: true,

      zindex: -1,
      fill: {
        color: '#E6E6E6',
        opacity: 0.6
      }
    }];

    $scope.kmlLayerOptions1 = {
      url: "http://nanakii.fr/up/ligne_bus.kml",
      preserveViewport: true
    };
    $scope.kmlLayerOptions2 = {
      url: "http://nanakii.fr/up/ligne_bus2.kml",
      preserveViewport: true
    };
    $scope.showKml = true;
  }
]);
* {
  margin: 0;
  padding: 0;
}
body,
html {
  height: 100%;
}
.angular-google-map-container {
  position: absolute;
  width: 100%;
  height: 100%;
}
<script>
  // only for the code-snippet
  document.getElementsByTagName('html')[0].setAttribute('ng-app', 'map')
  document.getElementsByTagName('body')[0].setAttribute('ng-controller', 'MapController')
</script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://rawgit.com/angular-ui/angular-google-maps/master/dist/angular-google-maps.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=weather,geometry,visualization,places&sensor=false&language=en&v=3.17"></script>


<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" bounds="map.bounds">
  <ui-gmap-polygon static="true" ng-repeat="p in polygons track by p.id" path="p.path" clickable="p.clickable" stroke="p.stroke" visible="p.visible" geodesic="p.geodesic" fill="p.fill" fit="false" editable="p.editable" draggable="p.draggable">
  </ui-gmap-polygon>
  <ui-gmap-layer type="KmlLayer" options="kmlLayerOptions1" show="showKml"></ui-gmap-layer>
  <ui-gmap-layer type="KmlLayer" options="kmlLayerOptions2" show="showKml"></ui-gmap-layer>
  <ui-gmap-marker coords="marker.coords" options="marker.options" idkey="marker.id"></ui-gmap-marker>
</ui-gmap-google-map>


哇,确实,我怎么会错过那个...谢谢!还有一个问题,是否可能将KML图层放在多边形上方?我尝试了zindex选项,但它并不像我想要的那样工作... - Aly
1
不,这是不可能的,请参见:http://stackoverflow.com/questions/28837030/googlemaps-api-kml-on-top-of-polygon。zIndex 在这里没有任何效果,因为多边形将在另一个地图窗格中呈现(其 zIndex 高于 KmlLayer 将呈现的窗格)。 - Dr.Molle

1

重叠的多边形可能是问题所在吗?我认为点击事件被多边形捕获了,而不是标记,但在这种情况下,“clickable: false”应该足够。

我认为必须还有其他问题,正如gmaps文档中所述:“所有要素按照它们的zIndex顺序显示在地图上,具有更高值的要素显示在具有较低值的要素前面。 标记始终显示在线串和多边形的前面。”很明显这不是这种情况。

尝试为所有元素指定zIndex。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接