Display simple Marker on the Map
This tutorial shows how to add a default Marker to the map.
-
Copy the following code, paste it into your favorite text editor, and save it as a
.html
file. -
Replace YOUR_MAPTILER_API_KEY_HERE with your actual MapTiler API key.
-
The next is up to you. You can start the map in a different place by modifying the
starting position
andstarting zoom
, and you can change the look of the map to any of our styles, or yours, by updating thesource URL
. See what’s available here. -
To create a new marker using a Vector layer. The layer’s data source will be a feature set. Create a feature of type point at the Lng/Lat coordinates of the marker. Create a Style to load the marker image and finally added it to the current map using .addLayer() function. Download the marker image here
const layer = new ol.layer.Vector({ source: new ol.source.Vector({ features: [ new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([16.62662018, 49.2125578])), }) ] }), style: new ol.style.Style({ image: new ol.style.Icon({ anchor: [0.5, 1], crossOrigin: 'anonymous', src: 'https://docs.maptiler.com/openlayers/default-marker/marker-icon.png', }) }) }); map.addLayer(layer);