简体   繁体   English

Angular Google地图自定义图标仅在标记更新时有效

[英]Angular google maps custom Icon only works when marker is updated

When I add a marker with a icon filed it appears as a default marker, however when I update the location in a while it starts to appear as a custom icon which I want. 当我添加带有图标的标记时,它会显示为默认标记,但是当我在一段时间内更新该位置时,它会开始显示为我想要的自定义图标。

map.html map.html

<ui-gmap-google-map center="map.center"
            control="map.control"
            zoom="map.zoom"
            options="map.options"
            bounds="map.bounds"
            draggable="true">
    <ui-gmap-markers
            models="markerArray"
            coords="'self'"
            icon="'icon'">
    </ui-gmap-markers>
</ui-gmap-google-map>

map.js/addMarker (puts the marker, with the default icon) map.js / addMarker (放置标记,默认图标)

function addMarker(markerId, latitude, longitude, icon, iconSize) {

    markerIconSize = new google.maps.Size(iconSize[0],iconSize[1]);

    var marker = {
        id: markerId,
        latitude: latitude,
        longitude: longitude, 
        icon: {
            url: icon,
            scaledSize: markerIconSize
        }
    };
    $scope.markers.push(marker);
    $scope.markerArray = $scope.markers;
}

map.js/updateMarker (updates the coord. with the custom icon) map.js / updateMarker (用自定义图标更新coord。)

function updateMarker(markerId,latitude,longitude) {

     var marker = _.find($scope.markerArray, function(marker) {
          return marker.id = markerId;
     });

     marker.latitude = latitude;
     marker.longitude = longitude;
}

Couple things I could think of: Try hard coding the icon url and see if that works. 我能想到的几件事情:尝试对图标网址进行硬编码,看看是否有效。 Then try to split marker declaration, so: 然后尝试拆分标记声明,所以:

var marker;
var markerOptions = {
    id: markerId,
    latitude: latitude,
    longitude: longitude, 
    icon: {
        url: icon,
        scaledSize: markerIconSize
    }
};
marker = new google.maps.Marker(markerOptions);
$scope.markers.push(marker);
$scope.markerArray = $scope.markers;

This is how I made my map work so, just giving you a suggestion. 这就是我使地图工作的方式,只是给你一个建议。 Hope it works for you as well. 希望它也适合你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM