缩放后,NgMap群集更改标记颜色

时间:2017-05-12 16:37:36

标签: javascript google-maps marker ng-map

我想改变标记的颜色。我使用ng-map来显示地图。我也在使用此库中的群集选项。

我的问题:我能够更改标记颜色,我可以看到,但是一旦我开始缩放,标记颜色会变为默认颜色(红色)。

这是我的代码:

<ng-map zoom-to-include-markers="auto" 
         id="map"
         map-type-id="ROADMAP"
         street-view-control-options="{position: 'LEFT_CENTER'}">

   <marker ng-repeat="p in paths" position="{{p.positions}}" icon="{{p.icon}}"></marker>

</ng-map>

这是群集代码:

NgMap.getMap().then(function (map) {
                for (var i = 0; i < $scope.paths.length; i++) {
                    var latLng = new google.maps.LatLng($scope.paths[i].positions[0], $scope.paths[i].positions[1]);
                    $scope.dynMarkers.push(new google.maps.Marker({position: latLng}));
                }
                $scope.markerClusterer = new MarkerClusterer(map, $scope.dynMarkers, {});
            });

1 个答案:

答案 0 :(得分:0)

我解决了这个问题!

如果有人遇到同样的问题,解决方案是在推送新标记时添加icon字段:

NgMap.getMap().then(function (map) {
                for (var i = 0; i < $scope.paths.length; i++) {
                    var latLng = new google.maps.LatLng($scope.paths[i].positions[0], $scope.paths[i].positions[1]);
                    $scope.dynMarkers.push(new google.maps.Marker({position: latLng, icon: $scope.paths[i].icon}));
                }
                $scope.markerClusterer = new MarkerClusterer(map, $scope.dynMarkers, {});
            });