Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a google map be removed from an element?

I've been messing around with jQuery-UI's widget factory to create a google map widget.

The widget factory includes pre-built destroy capabilities to remove a widget from an element. I'm interested to know whether there's a way to detach the original element from a Google Map without removing the element from the DOM.

Most of the searching I've done leads to how to remove markers and other layers from a Google Map, rather than removing the map from the DOM.

like image 698
zzzzBov Avatar asked Feb 22 '23 06:02

zzzzBov


1 Answers

I think the simplest way is to create inner div inside the original div and initialize the map for the inner div. When destroying the map, just remove the inner div and that's it.

var $inner = $('<div style="width: 100%; height: 100%"></div>').appendTo('#map_div');
// creation:
var map = new google.maps.Map($inner[0], { ... });
// removal:
$inner.remove();

Without jquery:

document.getElementById('map_div').innerHTML = '<div id="inner_map_div" style="width: 100%; height: 100%"></div>';

// creation:
var map = new google.maps.Map(document.getElementById('inner_map_div'), { ... });

document.getElementById('map_div').innerHTML = ''; // removal
like image 98
Tomas Avatar answered Mar 02 '23 16:03

Tomas