1.引入GeoJSONLayer
import GeoJSONLayer from '@arcgis/core/layers/GeoJSONLayer'
或者
require(["esri/layers/GeoJSONLayer"], function(GeoJSONLayer){
const geojsonlayer = new GeoJSONLayer({
url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson", copyright: "USGS Earthquakes" });
map.add(geojsonlayer); // adds the layer to the map
});
// create a geojson layer from geojson feature collection
const geojson = {
type: "FeatureCollection",
features: [
{
type: "Feature",
id: 1,
eometry: {
type: "Polygon",
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
properties: {
type: "single",
recordedDate: "2018-02-07T22:45:00-08:00" }
}
]
};
// create a new blob from geojson featurecollection
const blob = new Blob([JSON.stringify(geojson)], {
type: "application/json"
});
// URL reference to the blob
const url = URL.createObjectURL(blob);
// create new geojson layer using the blob url
const layer = new GeoJSONLayer({
url
});
this.map.add(layer) // 加载至当前地图