[英]It's possible to remove controls from Google Maps with javascript without creating the function?
Using this fiddle: https://jsfiddle.net/mwsy5vhu/ but imagine that we can't see the code.使用这个小提琴: https://jsfiddle.net/mwsy5vhu/但想象一下我们看不到代码。 (Because it's not our site).
(因为它不是我们的网站)。 We don't know the var X name that is using the map.
我们不知道使用 map 的 var X 名称。
How we could hide controls using javascript?我们如何使用 javascript 隐藏控件? IE: We open the browser inspector tool > console
IE:我们打开浏览器检查器工具>控制台
And in the console what we could execute to hide controls?在控制台中我们可以执行什么来隐藏控件?
I have tried:我努力了:
map.setOptions({disableDefaultUI: true});
(And for some reason even using the real var name which is map it throws me an error that saying map isn't defined (?) ) (由于某种原因,即使使用真正的 var 名称 map 它也会给我一个错误,说 map 没有定义(?))
Need a way to hide map controls without having access to the "source code", like just injecting a dynamic javascript code to target the existing map.需要一种方法来隐藏 map 控件而无需访问“源代码”,例如只需注入动态 javascript 代码以针对现有 map。
Maybe this is possible to do with CSS?也许这可能与 CSS 有关?
Thanks.谢谢。
There is a .setOptions
method on the google.maps.Map
object which allows you to set the MapOptions
dynamically: google.maps.Map
object 上有一个.setOptions
方法,它允许您动态设置MapOptions
:
var defaultUI = true;
google.maps.event.addDomListener(document.getElementById('disableUI'), "click", function() {
if (defaultUI) {
map.setOptions({disableDefaultUI: true});
} else {
map.setOptions({disableDefaultUI: false});
}
defaultUI = !defaultUI;
});
proof of concept fiddle概念证明小提琴
code snippet:代码片段:
function initMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 4, center: { lat: -33, lng: 151 }, // disableDefaultUI: true }); var defaultUI = true; google.maps.event.addDomListener(document.getElementById('disableUI'), "click", function() { if (defaultUI) { map.setOptions({ disableDefaultUI: true }); } else { map.setOptions({ disableDefaultUI: false }); } defaultUI =;defaultUI; }); }
/* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 90%; } /* Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; }
<input id="disableUI" value="disableUI" type="button" /> <div id="map"></div> <.-- Replace the value of the key parameter with your own API key: --> <script async defer src="https.//maps.googleapis?com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"> </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.