【问题标题】:How to set specific marker show on another markers in markers list use Angular Google maps如何使用 Angular Google 地图在标记列表中的另一个标记上设置特定标记显示
【发布时间】:2016-10-22 16:57:50
【问题描述】:

我正在使用Angular Google Maps,我在地图中有一些标记:

$scope.markers = [
  {
    id: 5,
    latitude: 44.4284821,
    longitude: 26.1241451,
    icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/blue.png'
  },
  {
    id: 4,
    latitude: 43,
    longitude: 26.1241451
  }

];

这是我的例子:Here

我想将特定的z-index 设置为蓝色标记(id 为 5)始终显示在红色标记图标(id 为 4)或其他标记上。并且不要关心它的latlong。如果不能使用z-index,请给我另一种方法。

注意:标记数组中蓝色标记的索引始终为 0

希望你能帮助我,谢谢。

【问题讨论】:

    标签: angularjs google-maps google-maps-markers angular-google-maps


    【解决方案1】:

    要控制标记对象 (google.maps.Marker) 的 z 顺序,需要指定两个属性:

    z-index: <value>
    optimized:false
    

    如果是angular-google-maps 库,您可以设置z-indexoptimized 属性,如下所示:

    <ui-gmap-markers models="markers" options="'options'" coords="'self'" icon="'icon'" zIndex="'zIndex'" optimized="'optimized'">
    </ui-gmap-markers>
    
    $scope.markers = [
      {
        id: 5,
        latitude: 44.4284821,
        longitude: 26.1241451,
        icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/blue.png',
        options : {
           zIndex: 923,
           optimized: false
        }
      },
      {
        id: 4,
        latitude: 43,
        longitude: 26.1241451,
        options : {
           zIndex: 611,
           optimized: false
        }   
      }
    
    ]; 
    

    示例

    angular.module('appMaps', ['uiGmapgoogle-maps'])
      .controller('mainCtrl', function ($scope) {
    
        $scope.markers = [
          {
            id: 5,
            latitude: 44.4284821,
            longitude: 26.1241451,
            icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/blue.png',
            options : {
               zIndex: 923,
               optimized: false
            }
          },
          {
            id: 4,
            latitude: 43,
            longitude: 26.1241451,
            options : {
               zIndex: 611,
               optimized: false
            }   
          }
    
        ];
    
        $scope.map = {
          center: {
            latitude: 32,
            longitude: 15
          },
          zoom: 4,
          bounds: {},
          markers: {
            models: [],
            type: 'cluster',
            typeOptions: {
              minimumClusterSize: 12,
              gridSize: 60
            }
          },
          options: {
            mapTypeControl: true,
            zoomControl: true,
            streetViewControl: true,
            scrollwheel: true
          }
        };
    
      });
     html, body, #map_canvas {
                height: 100%;
                width: 100%;
                margin: 0px;
            }
    
            #map_canvas {
                position: relative;
            }
    
            .angular-google-map-container {
                position: absolute;
                top: 0;
                bottom: 0;
                right: 0;
                left: 0;
            }
    <script src="https://code.angularjs.org/1.3.14/angular.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
        <script src="https://rawgit.com/angular-ui/angular-google-maps/2.0.X/dist/angular-google-maps.js"></script>
    <div id="map_canvas" ng-app="appMaps" ng-controller="mainCtrl">
        <ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="map.options" bounds="map.bounds">
            <ui-gmap-markers models="markers" options="'options'" coords="'self'" icon="'icon'" zIndex="'zIndex'" optimized="'optimized'">
            </ui-gmap-markers>
        </ui-gmap-google-map>
    </div>

    Modified plunker

    【讨论】:

    • 我尝试在options 属性中使用zIndexoptimized,但我错过了设置options="'options'"。谢谢你的好回答
    【解决方案2】:

    我们无法发送标记的 z-index,因为 google-maps 正在制作画布然后进行渲染。 所以如果你故意要改变z-index,你必须要相应地改变标记图像,因为一旦google map被渲染出来,我们就无法改变z-index。

    【讨论】:

    • 没有z-index还有什么方法?
    • 您可以为不同的标记使用不同阴影的不同图像,并且只为嵌入在每个标记顶部的文本提供 z-index,因为 google-maps 为标记而不是顶部的文本创建画布它。但这将是一种非常随意的做法。
    • "options": { "labelContent": markerText }, "icon": imagePath 这就是我们如何手动指定每个带有所需图像和文本的标记的方法。检查 google-maps 实现以供参考
    • 它不能让一个特定的标记总是显示在另一个标记上。
    猜你喜欢
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 2018-02-11
    • 2015-01-24
    相关资源
    最近更新 更多