如何在打开的地图iframe
中禁用鼠标互动或滚动?
我有以下内容,我把属性scrollwheel="false"
通过css有没有办法可以通过css禁用滚动或交互?
<iframe id= "mapsource" scrollwheel="false" src="http://www.openstreetmap.org/export/embed.html?bbox=-123.21233510971068%2C49.260691198361066%2C-123.18484783172607%2C49.27329289319553&layer=mapquest&marker=49.26699244809891%2C-123.19858074188232"></iframe>
我对其他选项开放,例如使用javascript来禁用滚动?
答案 0 :(得分:2)
如果控件(放大按钮,缩小按钮等)对您来说很重要,则可以使用以下内容。
# The magic - set the pointer-events to none to simply disable the
# scrolling on the map BUT NOT the functionality of the buttons!
# This happens only using leaflet api!
<style>
#map {
width: 100%;
height: 300px;
pointer-events: none;
}
</style>
# The map element
<div id="map"></div>
# The css link from leaflet
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
# The js link from leaflet
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script>
# Custom source code to initialize the map
<script>
var mymap = L.map("map").setView([37.980114, 23.729924], 17);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);
L.marker([37.980114, 23.729924]).addTo(mymap);
</script>
答案 1 :(得分:2)
我也想这样做。禁用鼠标滚动,但保持其他所有功能正常。这里的选项要么完全禁用了地图,要么根本不起作用。
我最终不得不使用Leaflet,这是一个与Open Street Maps集成的库。轻巧,快捷,容易。按照他们的Quick Start guide设置地图。
要禁用滚动,必须在初始化地图时传递Option参数{scrollWheelZoom:false}
,如下所示:
var mymap = L.map('mapid', {scrollWheelZoom:false}).setView([51.505, -0.09], 13);
答案 2 :(得分:1)
尝试pointer-events: none;
#mapsource {
pointer-events: none;
}
&#13;
<iframe id= "mapsource" scrollwheel="false" src="http://www.openstreetmap.org/export/embed.html?bbox=-123.21233510971068%2C49.260691198361066%2C-123.18484783172607%2C49.27329289319553&layer=mapquest&marker=49.26699244809891%2C-123.19858074188232"></iframe>
&#13;
答案 3 :(得分:1)
有一种方法-https://venues.here.com/documentation/sdk/v1/example/disable-zoom-wheel-scroll
map.scrollWheelZoom.disable();
此实现也可以正常工作,但在第一个示例中,您可以有条件地使用它
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
scrollWheelZoom: false,
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mymap);