admin管理员组文章数量:1310263
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.
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.
Share Improve this question asked Dec 1, 2011 at 18:35 zzzzBovzzzzBov 179k56 gold badges327 silver badges371 bronze badges2 Answers
Reset to default 6I 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
Instead of .remove()
, you can also use the jQuery function .empty()
on the div
which contains the map.
This function deletes everything, but the div
. So you don't need to have an outer and an inner div
.
本文标签: javascriptCan a google map be removed from an elementStack Overflow
版权声明:本文标题:javascript - Can a google map be removed from an element? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741842450a2400582.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论