NgMap cluster change markers colors after zoom

最后都变了- 提交于 2019-12-02 20:51:06

问题


I want to change the color of the markers. I'm using ng-map to display the map. I'm also using the cluster option in this library.

My problem: I'm able to change the marker color and I can see that, but once I begin zooming, the markers color change to the default one (red color).

This is my code:

<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>

This is the cluster code:

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:


I solved the problem!

If anyone has the same problem, the solution is in adding the icon filed when pushing new a marker:

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, {});
            });


来源:https://stackoverflow.com/questions/43942610/ngmap-cluster-change-markers-colors-after-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!