gpt4 book ai didi

javascript - 我无法让 esri-leaflet 与 ReactJS 一起工作 --> 未定义的 basemapLayer

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:56:49 25 4
gpt4 key购买 nike

在 npm 安装 esri-leafletleaflet 包后,出现以下错误

enter image description here

这是我的 map 组件:

import React from 'react'
import ReactDOM , {render} from 'react-don'

import L from 'esri-leaflet'
// import L from 'leaflet' <-- won't work as well


class Map extends React.Component{

componentDidMount(){

let element = this.refs.mapRef

// let map = L.map(element).setView([-41.2858, 174.78682], 14);
var map = L.map(this.refs.mapRef).setView([45.528, -122.680], 13)

L.esri.basemapLayer("Streets").addTo(map);

console.log("ESRI::",L.esri);

var parks = L.esri.featureLayer({
url: "https://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Portland_Parks/FeatureServer/0",
style: function() {
return {
color: "#70ca49",
weight: 2
};
}
}).addTo(map);
}


render(){
return(
<div>
<h1>Maps page</h1>
<div id='map' ref="mapRef" style={{height: "380px"}}></div>
</div>
)
}

}

export default Map

可能是什么问题?

最佳答案

使用 npm i leaflet@1.0.0-rc.1 命令安装 1.0.0-rc.1 版本的 leaflet , esri-leaflet 不需要指定版本,所以它只是 npm i esri-leaflet。这是您对组件的要求:

require('leaflet');
import esri from 'esri-leaflet';

然后通过 esri 使用图层,它应该可以工作:

esri.basemapLayer...
esri.featureLayer...

关于javascript - 我无法让 esri-leaflet 与 ReactJS 一起工作 --> 未定义的 basemapLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38500397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com