简体   繁体   English

可以在不创建 function 的情况下使用 javascript 从 Google 地图中删除控件吗?

[英]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.

相关问题 从Google Maps删除控件 - Remove Controls from Google Maps 是否可以在不创建全局回调函数的情况下异步初始化Google地图? - Is it possible to initialize Google Maps asynchronously without creating a global callback function? 在没有控件的情况下从Google地图打印地图 - Printing map from google maps without controls 是否可以从 JS 函数调用 Google Maps Javascript API 并将其显示在 ion-content 上? - Is it possible to call Google Maps Javascript API from JS function and display it on ion-content? Using the Google Maps JavaScript API, is it possible to get data from an outside button into the map.data.setStyle function? - Using the Google Maps JavaScript API, is it possible to get data from an outside button into the map.data.setStyle function? 是否可以在javascript函数中从具有纬度和经度的var在Google地图中创建位置名称为var的变量? - Is it possible in a javascript function, to create from var with latitude and longitude of a position in Google maps a var with location name? 运行Google的Javascript Maps API可能有哪些限制? - What limits are possible when running Google's Javascript Maps API? JavaScript的谷歌地图删除图标 - javascript google maps remove icon Google Maps Javascript v3自定义控件子类化标准控件 - Google Maps Javascript v3 custom controls subclassing standard controls 从Javascript Google Maps API中的数组创建新标记 - Creating new markers from an array in Javascript google maps API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM