簡體   English   中英

禁用地圖滾動打開街道地圖

[英]Disable map scrolling open street maps

如何在打開的地圖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&amp;layer=mapquest&amp;marker=49.26699244809891%2C-123.19858074188232"></iframe>

我對其他選項持開放態度,例如使用 javascript 來禁用滾動?

嘗試pointer-events: none;

 #mapsource { pointer-events: none; }
 <iframe id= "mapsource" scrollwheel="false" src="http://www.openstreetmap.org/export/embed.html?bbox=-123.21233510971068%2C49.260691198361066%2C-123.18484783172607%2C49.27329289319553&amp;layer=mapquest&amp;marker=49.26699244809891%2C-123.19858074188232"></iframe>

如果控件(放大按鈕、縮小按鈕等)對您很重要,您可以使用如下所示的內容。

# 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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(mymap);
    L.marker([37.980114, 23.729924]).addTo(mymap);

</script>

有一種方法 - 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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(mymap);

我也想做同樣的事情。 禁用鼠標滾動但保持其他一切正常。 這里的選項要么完全禁用地圖,要么根本不起作用。

我最終不得不使用 Leaflet,這是一個與 Open Street Maps 集成的庫。 它輕巧、快速且簡單。 按照他們的快速入門指南設置您的地圖。

要禁用滾動,您必須在初始化地圖時傳遞 Option 參數{scrollWheelZoom:false} ,如下所示:

var mymap = L.map('mapid', {scrollWheelZoom:false}).setView([51.505, -0.09], 13);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM