1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| import Feature from 'ol/Feature.js'; import Map from 'ol/Map.js'; import Point from 'ol/geom/Point.js'; import View from 'ol/View.js'; import {Icon, Style} from 'ol/style.js'; import {Stamen, Vector as VectorSource} from 'ol/source.js'; import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer.js';
const iconFeature = new Feature({ geometry: new Point([0, 0]), });
const vectorSource = new VectorSource({ features: [iconFeature], });
const vectorLayer = new VectorLayer({ source: vectorSource, });
const rasterLayer = new TileLayer({ source: new Stamen({ layer: 'toner', }), });
const map = new Map({ layers: [rasterLayer, vectorLayer], target: document.getElementById('map'), view: new View({ center: [0, 0], zoom: 2, }), });
const gifUrl = 'data/globe.gif'; const gif = gifler(gifUrl); gif.frames( document.createElement('canvas'), function (ctx, frame) { if (!iconFeature.getStyle()) { iconFeature.setStyle( new Style({ image: new Icon({ img: ctx.canvas, imgSize: [frame.width, frame.height], opacity: 0.8, }), }) ); } ctx.clearRect(0, 0, frame.width, frame.height); ctx.drawImage(frame.buffer, frame.x, frame.y); map.render(); }, true );
map.on('pointermove', function (e) { const pixel = map.getEventPixel(e.originalEvent); const hit = map.hasFeatureAtPixel(pixel); map.getTarget().style.cursor = hit ? 'pointer' : ''; });
|