我是新來的地圖箱。我在mapbox地圖的標記圖像變化中遇到麻煩。 我從https://www.mapbox.com/mapbox-gl-js/example/custom-marker-icons/得到的代碼我無法更改標記圖像。如何在Mapbox中更改標記圖像?
這裏是我的代碼:
var geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"message": "IN",
"iconSize": [30, 30]
},
"geometry": {
"type": "Point",
"coordinates":<?php echo $in; ?>
}
},
{
"type": "Feature",
"properties": {
"message": "Check IN",
"iconSize": [30, 30]
},
"geometry": {
"type": "Point",
"coordinates":<?php echo $c; ?>
}
},
{
"type": "Feature",
"properties": {
"message": "OUT",
"iconSize": [30, 30]
},
"geometry": {
"type": "Point",
"coordinates":<?php echo $o; ?>
}
}
]
};
geojson.features.forEach(function(marker) {
var el = document.createElement('div');
el.className = 'marker';
el.style.backgroundImage = 'url(images/check_in.jpg)';
el.style.width = marker.properties.iconSize[0] + 'px';
el.style.height = marker.properties.iconSize[1] + 'px';
el.addEventListener('click', function() {
window.alert(marker.properties.message);
});
new mapboxgl.Marker(el, {offset: [-marker.properties.iconSize[0]/2, -marker.properties.iconSize[1]/2]})
.setLngLat(marker.geometry.coordinates)
.addTo(map);
});