Skip to content

Instantly share code, notes, and snippets.

@lefuturiste
Created August 30, 2021 19:33
Show Gist options
  • Save lefuturiste/b4f1845fc43c0f380eb154f0ddfb422a to your computer and use it in GitHub Desktop.
Save lefuturiste/b4f1845fc43c0f380eb154f0ddfb422a to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.6.1/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.6.1/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([1.303757429122925, 49.15029606636458]),
zoom: 15
})
});
var markers = new ol.layer.Vector({
source: new ol.source.Vector(),
style: new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 1],
src: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png'
})
})
});
map.addLayer(markers);
var marker = new ol.Feature(new ol.geom.Point(ol.proj.fromLonLat([1.303757429122925, 49.15029606636458])));
markers.getSource().addFeature(marker);
map.render()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment