Re initialize gmap3 card

Is it possible to initialize the gmap3 map by default (lat, long, zoom, etc.)?

I tried to destroy on the map and then repeat the initialization, but it does not work.

Check out my jsfiddle here - http://jsfiddle.net/vlowe/z9dDE/1/

+4
source share
2 answers

Wrap the map element in a container div, and then when you want to reset on the map, just delete the entire div and recreate it. This should solve the problem.

According to the gmap3 documentation, you still need to call destroy on the map before deleting the dom element.

HTML code

<div> <div id="map"></div> </div> <a href="#" onclick="restore();">restore</a> 

Javascript

 var dlat = 53.9783997; // default map latitude var dlng = -1.5666347; // default map longitude var dzoom = 6; // default map zoom var dmaptype = "roadmap"; // default map type // create gmap $('#map').gmap3({ action: 'init', options: { center: [dlat, dlng], zoom: dzoom, mapTypeId: dmaptype, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, navigationControl: true, scrollwheel: true, streetViewControl: true } }); function restore() { $('#map').gmap3({ action: 'destroy' }); var container = $('#map').parent(); $('#map').remove(); container.append('<div id="map"></div>'); // create new gmap $('#map').gmap3({ action: 'init', options: { center: [dlat, dlng], zoom: dzoom, mapTypeId: dmaptype, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, navigationControl: true, scrollwheel: true, streetViewControl: true } }); }​ 
+4
source

Here's an alternative method: instead of destroying the map and completely re-creating it, you can save the original state and restore it to that state as follows: http://jsfiddle.net/UvAL3/1/

(these functions existed as part of the API in V2)

+3
source

All Articles