【发布时间】:2020-12-29 16:32:42
【问题描述】:
我目前在我的 React 项目中使用 MapBox GL JS。
我想知道如何在交互结束后在特定坐标处显示一些文本。我从函数 getMinCoords()
获取位置坐标我目前的代码如下
stop() {
let nextState = this.state;
if (nextState !== INTERACTION_STATES.completed) {
nextState = INTERACTION_STATES.abort;
}
if (this.vertices.length > 2) {
this.annotation.geometries = [{
type: 'Polygon',
coordinates: this.getPolygonCoordinates(),
properties: {
annotationType: 'polygon',
},
}];
} else {
this.annotation.geometries = [];
}
console.log(this.getMinCoords());
this.mapViewer.off('click', this.onClickCallback);
this.asset.dataUpdated();
this.setState(nextState);
this.flushState();
}
处理注解的函数如下:
this.geometries.forEach((geometry) => {
switch (geometry.type) {
case 'Point':
case 'LineString':
case 'Polygon': {
const styleProps = AssetStyle.getStyles(geometry, styles);
const feature = GeoJSONUtil.featureFromGeometry(geometry, this.properties);
if (this.properties.annotationType === 'label') {
styleProps.textAnchor = 'center';
}
feature.properties = { ...feature.properties, ...styleProps };
features.push(feature);
break;
}
在刷新状态之前,我想在 getMinCoords 返回的坐标处显示区域。我有另一个函数 getArea(),它返回区域。我只需要在地图上显示它
【问题讨论】:
标签: reactjs mapbox geojson mapbox-gl-js