4
當我添加帶有圖標提交的標記時,它會顯示爲默認標記,但是當我更新位置時,它開始顯示爲我想要的自定義圖標。角度谷歌地圖自定義圖標只適用於標記更新時
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(把該標記時,用默認圖標)
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(更新與定製圖標協調)
function updateMarker(markerId,latitude,longitude) {
var marker = _.find($scope.markerArray, function(marker) {
return marker.id = markerId;
});
marker.latitude = latitude;
marker.longitude = longitude;
}