-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(landing): correct attribution example (#2118)
* docs(attribution): improve example usage * fix(landing): correct attribution example
- Loading branch information
Showing
2 changed files
with
59 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 53 additions & 57 deletions
110
packages/landing/static/examples/index.openlayers.attribution.wmts.3857.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>OpenLayers WMTS Basemaps Demo</title> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" | ||
type="text/css" | ||
/> | ||
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script> | ||
$ATTR_FILE | ||
</head> | ||
|
||
<body> | ||
<div id="map" style="width: 800px; height: 600px;"></div> | ||
<script> | ||
(async () => { | ||
const apiKey = localStorage.getItem('api-key'); | ||
if (! apiKey) { | ||
throw new Error('Missing api-key in localStorage'); | ||
} | ||
|
||
const projection = 'EPSG:3857'; | ||
const baseUrl = 'https://basemaps.linz.govt.nz/v1/tiles/aerial/' + projection; | ||
const loadingWmts = fetch(baseUrl+'/WMTSCapabilities.xml?api='+apiKey); | ||
const attributions = new BasemapsAttribution(projection); | ||
const loadingAttrs = attributions.load(baseUrl+'/attribution.json?api='+apiKey); | ||
|
||
const parser = new ol.format.WMTSCapabilities(); | ||
const wmtsXml = parser.read(await (await loadingWmts).text()); | ||
const options = ol.source.WMTS.optionsFromCapabilities(wmtsXml, { | ||
layer: 'aerial', | ||
matrixSet: projection, | ||
}); | ||
|
||
const view = new ol.View({ | ||
center: [19467552, -5074414], | ||
zoom: 6, | ||
}); | ||
|
||
const source = new ol.source.WMTS(options); | ||
|
||
const map = new ol.Map({ | ||
target: 'map', | ||
layers: [new ol.layer.Tile({ source, projection })], | ||
controls: ol.control.defaults({ attributionOptions: { collapsed: false, collapsible: false } }), | ||
view, | ||
}); | ||
|
||
await loadingAttrs; | ||
map.addEventListener('moveend', () => { | ||
source.setAttributions(attributions.renderList( | ||
attributions.filter(view.calculateExtent(), view.getZoom()))); | ||
}); | ||
})(); | ||
</script> | ||
</body> | ||
</html> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>OpenLayers WMTS Basemaps Demo</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" | ||
type="text/css" /> | ||
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script> | ||
$ATTR_FILE | ||
</head> | ||
|
||
<body> | ||
<div id="map" style="width: 800px; height: 600px;"></div> | ||
<script> | ||
(async () => { | ||
const apiKey = localStorage.getItem('api-key'); | ||
if (!apiKey) throw new Error('Missing api-key in localStorage'); | ||
|
||
const projection = 'EPSG:3857'; | ||
const baseUrl = 'https://basemaps.linz.govt.nz/v1/tiles/aerial/' + projection; | ||
const loadingWmts = fetch(baseUrl + '/WMTSCapabilities.xml?api=' + apiKey); | ||
|
||
const parser = new ol.format.WMTSCapabilities(); | ||
const wmtsXml = parser.read(await (await loadingWmts).text()); | ||
const options = ol.source.WMTS.optionsFromCapabilities(wmtsXml, { | ||
layer: 'aerial', | ||
matrixSet: projection, | ||
}); | ||
|
||
const view = new ol.View({ center: [19467552, -5074414], zoom: 6, }); | ||
|
||
const source = new ol.source.WMTS(options); | ||
|
||
const map = new ol.Map({ | ||
target: 'map', | ||
layers: [new ol.layer.Tile({ source, projection })], | ||
controls: ol.control.defaults({ attributionOptions: { collapsed: false, collapsible: false } }), | ||
view, | ||
}); | ||
|
||
const attributions = await BasemapsAttribution.load(baseUrl + '/attribution.json?api=' + apiKey); | ||
// Ignore the hillshade layers from attribution | ||
attributions.isIgnored = a => a.collection.title.toLowerCase().includes('geographx') | ||
map.addEventListener('moveend', () => { | ||
// Transform the extent into Lat/Long | ||
const extent = ol.proj.transformExtent(view.calculateExtent(), projection, 'EPSG:4326'); | ||
const filtered = attributions.filter(extent, view.getZoom()); | ||
source.setAttributions(attributions.renderList(filtered)); | ||
}); | ||
})(); | ||
</script> | ||
</body> | ||
|
||
</html> |