Angular Google Maps custom Icon only works when updating marker

When I add a marker with a marked icon, it appears as the default marker, however, when I update the location for some time, it starts to appear as the user icon I want.

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 a marker with a default icon)

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 coordinates using a custom icon)

function updateMarker(markerId,latitude,longitude) {

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

     marker.latitude = latitude;
     marker.longitude = longitude;
}
+4
source share
1 answer

A couple of things I could think of: Try hard-coding the URL of the icon and see if this works. Then try splitting the marker declaration to:

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;

, . , .

+2

Source: https://habr.com/ru/post/1589016/


All Articles