The GeoJSONLayer allows you to add features from a GeoJSON file (.geojson). The file is referenced as a hosted file on the web. Because of this, the file must be publicly accessible.
This sample shows how to add an instance of GeoJSONLayer and display it with a Map component.
If GeoJSON files are not on the same domain as your website, a CORS-enabled server or a proxy is required.
How it works
The sample loads earthquake data for the past 30 days from the USGS. The GeoJSONLayer’s url points to this feed. The layer sets its definitionExpression to show earthquakes with a magnitude greater than 3.
const layer = new GeoJSONLayer({ url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson", title: "USGS Earthquakes", copyright: "USGS Earthquakes", popupTemplate: template, definitionExpression: "mag > 3", effect: "drop-shadow(0.5px, 0.5px, 1px, black)", renderer: renderer, orderBy: { field: "mag", }, });The layer’s renderer includes a size visual variable based on the mag field, so higher magnitude earthquakes appear larger. Its minSize and maxSize use $view.scale to adjust the symbol sizes as you zoom.
An opacity visual variable uses Geometry($feature).z to read earthquake depth from the GeoJSON coordinates. Deeper earthquakes appear more opaque, with opacity increasing from 0.25 at 0 km to 1 at 400 km.