I am not sure how to switch back from ImageMapType to normal map. The problem is described in code as followings (pseudo code):
var myMap;
var curLabLocation = new google.maps.LatLng(36.415793, -121.084421);
var mapOptions = {
zoom: 21,
streetViewControl: false,
center: curLabLocation,
mapTypeId: google.maps.MapTypeId.MAP
};
var $map = $('#map-canvas');
myMap = new google.maps.Map($map[0], mapOptions);
// A) Switch to image type map. NO problem
var imageMapType = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
// Simply empty. How to delete this????? After B)
// this function still working, which prevent
// normal map to show up.
return null;
},
tileSize: new google.maps.Size(256, 256),
maxZoom: 23,
minZoom: 22,
name: 'image type map'
});
myMap.mapTypes.set('imagetypemap', imageMapType);
myMap.setMapTypeId('imagetypemap');
// Now, it works fine with ImageMapType.
// B) Switch back to normal map. Problem is the map is empty due
// to getTileUrl: function(coord, zoom) {} still working.
myMap.setMapTypeId(google.maps.MapTypeId.MAP);
// I tried this. But not working. myMap.overlayMapTypes.length=0 before clear() is called. So, this is not right way to clear ImageMapType.
myMap.overlayMapTypes.clear();
myMap.setMapTypeId(google.maps.MapTypeId.MAP);
Do I need to re-create the map object? Is there way not to re-create the map object? If no, how to do it?
Copyright Notice:Content Author:「user3792705」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/33158449/how-to-switch-back-from-imagemaptype-to-normal-map