我在if句子中替换图像时遇到很大问题。我先删除图像。但是当我在if句子里面时,我无法放置一个新的图像。
var image= 'garage.png';
var imageUrl = image,
imageBounds = L.latLngBounds([
[63.431004174, 10.397958755],
[63.430433118, 10.399938226]])
var map = L.mapbox.map('map', 'examples.map-i86nkdio').fitBounds(imageBounds);
var overlay = L.imageOverlay(imageUrl, imageBounds).addTo(map);
map.removeLayer(overlay);
// this is the if that appears later in the code //
function changeImages(newValue){
var slider = newValue;
if(slider < 5){
var image = 'garageAltered.png';
var imageUrl = image,imageBounds = L.latLngBounds([
[63.431004174, 10.397958755],
[63.430433118, 10.399938226]])
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
.fitBounds(imageBounds);
var overlay = L.imageOverlay(imageUrl, imageBounds).addTo(map);
}
}