UNPKG

ol-cesium

Version:

OpenLayers Cesium integration library

59 lines (50 loc) 1.63 kB
/** * @module examples.image-static */ const exports = {}; import OLCesium from 'olcs/OLCesium.js'; import {transform} from 'ol/proj.js'; import olView from 'ol/View.js'; import {defaults as olControlDefaults} from 'ol/control.js'; import olSourceOSM from 'ol/source/OSM.js'; import olLayerTile from 'ol/layer/Tile.js'; import olMap from 'ol/Map.js'; import {Image as ImageLayer} from 'ol/layer.js'; import {getCenter} from 'ol/extent.js'; import Static from 'ol/source/ImageStatic.js'; const imageExtent = [-40, 50, -10, 65]; Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0MzAyNzUyYi0zY2QxLTQxZDItODRkOS1hNTA3MDU3ZTBiMDUiLCJpZCI6MjU0MSwiaWF0IjoxNTMzNjI1MTYwfQ.oHn1SUWJa12esu7XUUtEoc1BbEbuZpRocLetw6M6_AA'; const ol2d = new olMap({ layers: [ new olLayerTile({ source: new olSourceOSM() }), new ImageLayer({ source: new Static({ url: 'data/image-static.png', crossOrigin: '', projection: 'EPSG:4326', imageExtent }) }) ], controls: olControlDefaults({ attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ collapsible: false }) }), target: 'map', view: new olView({ center: transform(getCenter(imageExtent), 'EPSG:4326', 'EPSG:3857'), zoom: 4, projection: 'EPSG:3857' }) }); const ol3d = new OLCesium({ map: ol2d }); const scene = ol3d.getCesiumScene(); scene.terrainProvider = Cesium.createWorldTerrain(); ol3d.setEnabled(true); document.getElementById('enable').addEventListener('click', () => ol3d.setEnabled(!ol3d.getEnabled())); export default exports;