I’ve successfully added OSM as a new base map type to my Google Maps API aplication.
Next I’ve added a new overlay map type, which adds hill shading to the map.
The documentation on overlay map types on https://developers.google.com/maps/documentation/javascript/maptypes?hl=en#OverlayMapTypes says:
“[…]you can add the map type to an existing MapType[…]”
“Overlay map types will display on top of any base map they are attached to.”
And “The following example is identical to the previous one except that we’ve created a tile overlay MapType on top of the ROADMAP map type:”
But in the code example the overlay map type is always shown on either map type you chose.
-
How can I make my hillshading overlay map type to be only shown on map type “roadmap” and my custom “OSM” map type? EDIT: To be more precise: Actually I want to know, if there is a way to do this automatically like the docs above suggest. I know, how to do this manually by listening to the maptypeid_changed event.
-
Is there a way to add my overlay map type to the mapTypeControl as a checkbox like it’s done with “Labels” on the default satellite map type or “terrain” on the roadmap map type?
EDIT: Until some days ago the official docs above suggested a way to do this, but did not describe it exactly and the linked example was broken (404-link). Thy user here found the same issue: Google maps api: Customising the MapTypeControl for separate map overlays
EDIT:
I’ve posted the jsFiddl of my current solution below.
Well, looks like there is no native way, to bind an overlay map type to a base map type or to use Googles map type control for overlay map type.
So here is what I have finally done, to work around this issue: http://jsfiddle.net/lejared/720L7wu0/3/
I’ve build a custom control (with the look an feel of the native Google maps controls). This Control toggles my overlay map type (Hillshading). You can define a array of base map types suitable for this overlay map type. The control will than show/hide itself automatically if a suitable base map type is selected.
2017-02-01: Updates fiddle to match new native look of googles map controls.