reactjs - 如何从 react-leaflet 调用 getFeatureInfo?
问题描述
我有来自 github 的示例如何添加 wms 层: https ://github.com/PaulLeCam/react-leaflet/blob/master/example/components/wms-tile-layer.js
但是如何从 wms 层单击获取FeatureInfo?
解决方案
react-leafletWMSTileLayer
组件实现L.TileLayer
了不支持 GetFeatureInfo
的核心传单:
没有 GetCapabilities 支持,没有图例支持,也没有 GetFeatureInfo 支持。
GetFeatureInfo
例如, 您可以考虑使用支持 Leaflet 的 WMS 插件leaflet.wms
安装步骤:
安装leaflet.wms
包:
npm i leaflet.wms
为 WMS 层引入一个组件:
import React, { Component } from 'react';
import { withLeaflet, 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;
}
结果
推荐阅读
- javascript - 尝试将 eventListener 添加到组件,但它破坏了我的应用程序
- javascript - 缩放时重新缩放轴
- javascript - IE 11 'ng' 未定义错误
- c++ - CLion 如何终止正在运行的进程?
- android - Intent 和 lambda 并且需要在每次运行之前进行清理
- java - Spring Logging 被添加到 System.out 但不是文件(log4j)
- java - @PostContruct 在服务器启动期间给出 NullPointerException
- asp.net - Asp.net Facebook 登录
- laravel - 如何在 Laravel 5.6 中使用 cartalyst sentinel 和 tymon jwt?
- ruby - Ruby:将整数转换为 32 位二进制数(或字符串)