Skip to content

Instantly share code, notes, and snippets.

@Siedlerchr
Created May 23, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Siedlerchr/35718703bb7974a19c96e1c2d795de64 to your computer and use it in GitHub Desktop.
Save Siedlerchr/35718703bb7974a19c96e1c2d795de64 to your computer and use it in GitHub Desktop.
OpenLayers map with overlay image
import 'ol/ol.css';
import Map from 'ol/map';
import View from 'ol/view';
import TileLayer from 'ol/layer/tile';
import OSM from 'ol/source/osm';
import Proj from 'ol/proj';
import Projection from 'ol/proj/projection';
import Coordinate from 'ol/coordinate';
import ImageStatic from 'ol/source/imagestatic';
import Image from 'ol/layer/image';
import Extent from 'ol/extent';
import Attribution from 'ol/attribution';
import Overlay from 'ol/overlay';
const coordinate = [16.3725, 48.208889];
let map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
})
],
view: new View({
center: Proj.fromLonLat(coordinate),
zoom: 4
})
});
let markerDiv = $("#marker")[0];
let marker = new Overlay({
position: Proj.fromLonLat(coordinate),
positioning: 'center-center',
element: markerDiv,
stopEvent: false
});
map.addOverlay(marker);
//HTML Stuff:
<div id="map" class="map"></div>
<div style="display: none;">
<img src ="overlayimage.jpg" id="marker" title="Marker">
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment