NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I have looked at this webpage: link text [] and I learned from it how to make markers on Openstreetmap. But I can't figure out how to make simple text labels appear beside the markers. My question is what is the simplest way to add labels to point markers ?

Here is "my" html code, which executes fine, but I want very much to place labels beside some or all of the point markers.

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <title>OpenStreetMap &amp; OpenLayers - Marker Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="" type="text/css">
    <script src="" type="text/javascript"></script>

    /* OSM & OL example code provided by */
    var map;
    var mapLat = 48.7776;
        var mapLng = 9.2325;
    var mapDefaultZoom = 18;

    function initialize_map() {
      map = new ol.Map({
        target: "map",
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM({
                      url: "{z}/{x}/{y}.png"
        view: new ol.View({
            center: ol.proj.fromLonLat([mapLng, mapLat]),
            zoom: mapDefaultZoom

    function add_map_point(lat, lng) {
      var vectorLayer = new ol.layer.Vector({
        source:new ol.source.Vector({
          features: [new ol.Feature({
                geometry: new ol.geom.Point(ol.proj.transform([parseFloat(lng), parseFloat(lat)], 'EPSG:4326', 'EPSG:3857')),
        style: new{
          image: new{
            anchor: [0.5, 0.5],
            anchorXUnits: "fraction",
            anchorYUnits: "fraction",
            src: ""


<body onload="initialize_map(); 
  <div id="map" style="width: 100vw; height: 100vh;"></div>

asked 17 Sep '20, 06:53

funOne's gravatar image

accept rate: 0%

edited 17 Sep '20, 21:48

TZorn's gravatar image



Could you fix/edit your question please? The links have gone missing.

(17 Sep '20, 07:41) TZorn

I tried to paste my entire html document into a code block, but about half of it did not arrive inside the code block, and I don't know why not. If there is somebody who knows how to edit my question, so as to format the text so that everything between "<!DOCTYPE html>" and "</html>" appears as code, then I thank you.

(17 Sep '20, 20:39) funOne

Without knowing what you have tried so far (your question does not include links) I suggest you have a look at uMap. There you are flexible to add markers with text labels of different kinds and appearances. Chose one of the instances given on the wiki page I linked to and give it a try.

permanent link

answered 17 Sep '20, 08:34

TZorn's gravatar image

accept rate: 15%

Thank you for telling me about uMap. That would be a perfectly good solution, except that their tiles won't load to a zoom level greater than 17 in the area that I am concerned with. Here is the map I created with uMap: [ ]. An alternative solution might be something like what is contained in this script here: [ ]. There you can see markers, but there are also text labels with the markers. I have tried to download the html source code of that page and to load it from my own computer, but that doesn't work, possibly because my browser doesn't know where to find some remote scripts that are given with reltive path names. So I am not even able to dissect that example, which is surprisingly the only example of Openlayers that I could find where label appear beside markers.

At the end of the day, all I want to do is place a marker at a location in WGS84 coordinates and place a text label beside the marker, and then zoom in to level 19. Any help is appreciated!

(17 Sep '20, 20:22) funOne

@funOne for me tiles are loading to a max zoom of 20 with that umap link. If the server has not had to display that area recently it can take a while to render depending on server load.

Note also that the umap background can be changed to's default if you wish (although that only goes to z19).

You can set the starting view with the diagonal arrows pointing inward to dot icon on the right.

(17 Sep '20, 21:17) InsertUser

I have waited for more than one hour, in which time the tile still has not loaded. Thanks for suggesting that I try changing from umap background to openstreetmap background. Openstreetmap background tile loads within 4.2 seconds: good enough. You mentioned how to set the starting view using the graphical interface. But how to set the starting map background to use Openstreetmap rather than OSM-Fr?

(17 Sep '20, 23:26) funOne

You can change the starting layer also in the right hand editing panel. It's the same icon as in the left hand panel.

(18 Sep '20, 08:21) TZorn

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 17 Sep '20, 06:53

question was seen: 10,380 times

last updated: 18 Sep '20, 08:21

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum