单击传单地图时如何禁用弹出窗口

时间:2020-05-14 07:43:00

标签: reactjs leaflet wms

这是亩问题,当在地图上单击时,它试图打开一个类似这样的弹出窗口,每次在地图上单击时,都向我下载文件,如何防止这种情况...

图层组件的代码:

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;

这就是我在地图中调用它的方式:

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

我在控制台中看到了这一点: enter image description here

但是我不想在单击时发出请求。

2 个答案:

答案 0 :(得分:0)

在传单库中有一个特殊的导入称为Popup:

示例:

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

您可以添加或不添加。如果您导入它,则可以在标记导入中使用它:

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

答案 1 :(得分:0)

identify 将禁用弹出窗口,info_format 将定义输出格式。

将这些添加到选项:

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