How to switch back from ImageMapType to normal map
NickName:user3792705 Ask DateTime:2015-10-16T04:59:49

How to switch back from ImageMapType to normal map

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

More about “How to switch back from ImageMapType to normal map” related questions

How to switch back from ImageMapType to normal map

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.41...

Show Detail

How to switch between ImageMapType and StyledMapType

In google map v3, I want to switch between ImageMapType and StyledMapType at different zoom levels. But I got error: Uncaught RangeError: Maximum call stack size exceeded Here is test code: var

Show Detail

google map imageMapType crashes iOS safari

I am loading custom png tiles onto a google map, and it seems that performance is killing the app in iOS Safari, and making it crawl with most other browsers. I believe that this is due to the numb...

Show Detail

Authorization Header in ImageMapType Typescript

I'm currently working with Google Maps Javascript API V3 in Angular. I'm trying to retrieve some tiles from the server, but I can't seem to be able to authorize the requests. The current implementa...

Show Detail

Google Maps with satellite base Map and imageMapType overlay increase zoom

I am displaying an ImageMapType as overlay over a satellite mapType base map. The base map seems to be limiting the max zoom to 19 in my area, if I change to a Road mapType I get a a couple of more

Show Detail

How to remove poi when using ImageMapType's getTileUrl method?

I am trying to remove the poi when Modifying the Map Type Registry. The issue I am having is that when I use ImageMapType's getTileUrl method, the styles I add to options dissapear. Please take a l...

Show Detail

Google Maps API V3 - Prevent ImageMapType from wrapping

Please note: This question is very similar to this one I found on stackoverflow. Google Maps v3 ImageMapType Prevent Wrapping However, the above question and answer did not work for my example /

Show Detail

Clip Google Maps JS API ImageMapType to a polygon

How can I clip a MapType in Google Maps to an arbitrary polygon. For example, if I have a custom ImageMapType that covers a large area (i.e. all the world), but I want to show it only inside a given

Show Detail

Google Maps V3 KML Layer over ImageMapType

I have a pretty little custom map created through MapTiler and it was dead easy to get it to render with GMaps. The basics of the few lines of code needed are below. I have a lovely little KML lay...

Show Detail

Google Maps API: Refresh ImageMapType Overlay

I'm using the Google Maps JavaScript API to display weather from a tile server. The tile server is available here: http://mesonet.agron.iastate.edu/ogc/ I'm displaying that tile server using an

Show Detail