【发布时间】:2021-10-15 20:39:46
【问题描述】:
堆栈:Reactjs、Leafletjs、EsriLeafletjs
我正在尝试在传单地图容器上的 GeoJson 中显示一个多边形。我的主要问题是当我使用 Leaflet.geoJson(data) 它返回无效的 JSON 对象。
请看...
我的 JSON 文件如下所示。它包含一个多边形。 https://gist.githubusercontent.com/UmairMughal901/d43ee77a9be27f2dcd006038fe8f07e7/raw/8650f4f3585ff0c1706da7a434251cfc70f1907b/map.geojson
我的地图组件
import React, { useEffect, useRef } from 'react';
import * as L from 'leaflet';
import 'leaflet/dist/leaflet.css';
import * as EL from "esri-leaflet";
import axios from 'axios';
import { GeoJSON } from 'react-leaflet';
export default function Mapfun() {
const mapCanvas = useRef(null);
const dataParcel = axios.get('https://gist.githubusercontent.com/UmairMughal901/d43ee77a9be27f2dcd006038fe8f07e7/raw/8650f4f3585ff0c1706da7a434251cfc70f1907b/map.geojson').then(resp => {
console.log(resp.data);
});
useEffect(() => {
mapCanvas.current = L.map('mapdiv', {
center: [31, 72],
zoom: 6,
layers: [
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}),
EL.featureLayer({ url: 'http://localhost:6080/arcgis/rest/services/Pu/PB_/MapServer/11' }),
//Main Issue here
L.geoJSON(dataParcel),
]
})
}
);
//todo
return (
<div id='mapdiv' style={{ width: '100%' }}>
</div>
)
}
【问题讨论】:
标签: reactjs leaflet geojson react-leaflet