我正在做一个网络动态项目,在我的 html/jsp 页面主体中使用 Google 地图。
我创建了一个函数,通过(lat,lng,map)创建一个标记,并在标记的参数中使用特殊的 image.png 作为图标。
在我的地图中,我制作了两种不同的样式(地图的颜色...):“白天”和“夜晚”。
我想知道当用户单击“夜间”更改样式时如何更改标记的图标。确实,标记的颜色不适合这种风格的地图......
我尝试用相同的名称以不同的样式初始化 var image = /.../...png ,这样我就可以在地图代码中使用 var ,但它不起作用。我还尝试了 if like
if(map.mapTypeControlOptions.mapTypeIds.equals(Day)){
var image=...png
} else {
var image=...png
}...
customMapTypeIdJour<div id="map"></div>
<script>
function initMap() {
var customMapTypeNuit = new google.maps.StyledMapType([
{
"featureType": "landscape.man_made", "elementType": "geometry.fill", "stylers": [ { "color": "#2b3f57" } ]
},
// ... the style of map
{
name: 'Nuit'
}
);
var customMapTypeJour = new google.maps.StyledMapType([
// a style of map
{
name: 'Jour'
}
);
var customMapTypeIdJour = 'Jour';
var customMapTypeIdNuit = 'Nuit';
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 43.6666, lng: 1.43333},
zoom: 17,
streetViewControl: false,
zoomControl: false,
mapTypeControlOptions: {
mapTypeIds: [customMapTypeIdJour, customMapTypeIdNuit]
}
});
map.mapTypes.set(customMapTypeIdNuit, customMapTypeNuit);
map.mapTypes.set(customMapTypeIdJour, customMapTypeJour);
map.setMapTypeId(customMapTypeIdJour);
var infoWindow = new google.maps.InfoWindow({map: map});
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Vous êtes ici.');
createMarqueur(lat, lng, map); // create a special marker with a special image as icon
map.setCenter(pos);
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}
</script>