Import Mapping Libraries from a URL
To use this pattern, the key is to add
type="module" to your
X.XXis the version number, like
.jsto the end.
<script type="module"> import MapView from 'https://js.arcgis.com/4.22/@arcgis/core/views/MapView.js';
When using code-sharing websites like CodePen, you do not have control over the
<script> tag, so you might think using this pattern will not work. Luckily, these websites have embraced ES Modules and have a solution.
CodePen will automatically add the
type="module" tag to your
<script> tag if it detects that you’re using ES Modules. Details on that here.
In CodeSandbox, if you use the “esm-react” environment you can use ES Modules.
Leaflet and Esri Leaflet
import * as L from "https://cdn.skypack.dev/[email protected]"; import * as esriLeaflet from "https://cdn.skypack.dev/[email protected]"; import * as esriLeafletVector from "https://cdn.skypack.dev/[email protected]";
I periodically write about technology, maps, open data, and other software topics. To get updates about new posts: