成员变量
# static convertFeature
将Common的要素对象转为Leaflet的要素对象
示例
添加要素图层-原生接口
// ES5引入方式
const { IGSFeatureLayer } = zondy.Layer
const { FeatureLayerUtil, leaflet } = zondy
const { SimpleFillSymbol } = zondy.Symbol
// ES6引入方式
import * as leaflet from '@mapgis/leaflet'
import { IGSFeatureLayer,SimpleFillSymbol } from "@mapgis/webclient-common"
import { FeatureLayerUtil } from "@mapgis/webclient-leaflet-plugin"
// 通过Common库创建一个要素图层对象
const featureLayer = new IGSFeatureLayer({
// 服务基地址
url: 'http://{ip}:{port}/igs/rest/services/{服务名}/FeatureServer'
})
// 查询要素,并绘制要素
featureLayer.queryFeatures({
// 指定要查询的子图层ID
layerId: '0',
// 指定查询结果的坐标系
outSrs: 'EPSG:4326',
// 指定查询数量
resultRecordCount: 100000
}).then((res) => {
// 创建一个Leaflet的要素图层
const featureLayerLeaflet = leaflet.featureGroup()
// 获取Leaflet的地图视图对象
const mapView = view.getInnerView()
// 添加要素图层
featureLayerLeaflet.addTo(mapView)
// 获取查询到的要素
const features = res.features
// 循环绘制要素
features.forEach((feature) => {
// 指定绘制要素的符号,根据不同几何类型设置不同的符号,示例中使用的是区几何
feature.symbol = new SimpleFillSymbol({
color: 'rgba(244, 122, 31, 0.5)'
})
// 将要素对象转为Leaflet的几何对象
const graphic = FeatureLayerUtil.convertFeature(feature)
// 添加并绘制几何对象
featureLayerLeaflet.addLayer(graphic)
})
})