Skip to content

Commit

Permalink
update worldview example
Browse files Browse the repository at this point in the history
  • Loading branch information
gowin20 committed Dec 4, 2023
1 parent dc5d3ee commit 6ceeb03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
25 changes: 10 additions & 15 deletions examples/worldview.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,29 @@
</head>
<body>
<div id="map"></div>
<script>
<script type="module">
const map = L.map("map", {
minZoom: 2
}).setView([35.7088, 48.8790], 4);

const apiKey = "<YOUR ARCGIS API KEY HERE>";
const apiKey = "< YOUR ARCGIS API KEY HERE >";

const basemapStyle = "arcgis/light-gray";

const getLayer = worldview => {
const getLayer = code => {
return L.esri.Vector.vectorBasemapLayer(basemapStyle, {
apiKey: apiKey,
version: 2,
worldview:worldview
worldview:code
})
}
const worldviewOptions = {
"china":getLayer("china").addTo(map),
"india":getLayer("india"),
"israel":getLayer("israel"),
"japan":getLayer("japan"),
"morocco":getLayer("morocco"),
"pakistan":getLayer("pakistan"),
"southKorea":getLayer("southKorea"),
"unitedArabEmirates":getLayer("unitedArabEmirates"),
"vietnam":getLayer("vietnam")
};

// Retrieve list of supported worldviews from /self url
const selfUrl = 'https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self'
const worldviews = (await (await fetch(selfUrl, {method:'GET'})).json()).worldviews;

// Add leaflet control to map
const worldviewOptions = Object.fromEntries(worldviews.map(worldview => [worldview.name,getLayer(worldview.code)]));
L.control.layers(worldviewOptions, null, { collapsed: false }).addTo(map);

map.on('baselayerchange', e=>{
Expand Down
4 changes: 2 additions & 2 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function getBasemapStyleUrl (style, apikey) {
/**
* Utility to establish a URL for the basemap styles API v2
*
* @param {string} style
* @param {string} token
* @param {string} style
* @param {string} token
* @param {Object} [options] Optional list of options: language, worldview, or places.
* @returns {string} the URL
*/
Expand Down

0 comments on commit 6ceeb03

Please sign in to comment.