一个获取geojson数据后构建graphic加载到地图上的示例
createMap() {
esriLoader.dojoRequire([
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/Basemap",
"esri/layers/MapImageLayer",
"esri/geometry/SpatialReference",
"dojo/domReady!"
], (Map,MapView,Graphic,Basemap,MapImageLayer, SpatialReference) => {
baselayer().then(l => {
this.map = new Map({
basemap: new Basemap({
baseLayers: [
l
],
})
});
let view = new MapView({
container: "MyMapDiv",
map: this.map,
center: [120.2, 30.26],
zoom: 12,
spatialReference: new SpatialReference({ wkid: 4326 })
});
let geojsonUrl = "https://lxqjss.github.io/data/jiangganoutline.geojson";
fetch(geojsonUrl).then(function(response) {
return response.json();
}).then(function(data) {
// console.log(data);
let outlineArr = data.features[0].geometry.coordinates;
console.log(outlineArr[0]);
let polygon = {
type: "polygon",
rings: outlineArr
};
let fillSymbol = {
type: "simple-fill",
color: [0, 0, 0, 0.5],
outline: {
color: [0, 0, 0],
width: 1
}
};
let polygonGraphic = new Graphic({
geometry: polygon,
symbol: fillSymbol
});
view.graphics.addMany([polygonGraphic]);
}).catch(function(e) {
console.log("Oops, error");
});
更多关于es2015 fetch的介绍参考# 传统 Ajax 已死,Fetch 永生