簡體   English   中英

單擊 leaflet map 時如何禁用彈出窗口

[英]How to disable popup when is clicked on the leaflet map

這是 mu 問題,當單擊 map 時,它會嘗試打開類似這樣的彈出窗口,並在每次單擊 map 時向我下載一個文件,如何防止這種情況發生……

圖層組件的代碼:

import { useLeaflet } from "react-leaflet";
import * as WMS from "leaflet.wms";

function CustomWMSLayer(props) {
  const { url, options, layers } = props;
  const ctx = useLeaflet();
  const map = ctx.map;

  // Add WMS source/layers
  const source = WMS.source(url, options);

  for (let name of layers) {
    source.getLayer(name).addTo(map);
  }

  return null;
}

export default CustomWMSLayer;

這就是我在 map 中調用它的方式:

  <CustomWMSLayer
              layers={["Sentinel-2"]}
              options={{
                format: "image/vnd.jpeg-png",
                transparent: "true",
                tiled: "true",
                crossOrigin: null,
              }}
              url="https://kade.si/cgi-bin/mapserv?"
            />

我在控制台中看到了這個: 在此處輸入圖像描述

但我不想在點擊時提出請求..

leaflet 庫中有一個名為 Popup 的特殊導入:

例子:

 import { Map, TileLayer, Marker, Popup } from "react-leaflet";

您可以添加或不添加。 如果您導入它,您將在標記導入中使用它:

<Marker position={position} icon={myIcon}>
          <Popup>This is the address</Popup>
</Marker>

identify將禁用彈出窗口, info_format將定義 output 格式。

將這些添加到選項中:

    options={{
        format: "image/vnd.jpeg-png",
        transparent: "true",
        tiled: "true",
        crossOrigin: null,
        identify: false,
        info_format: 'application/json',
    }}

暫無
暫無

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

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