openlayers 5.2.0. Markers with text

368 views Asked by At

I have this piece of code in my template, expecting that the marker will appear with the text "1SSMMMS", but I don't see any text at all in the market

var iconStyle = new ol.style.Style({
     image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
     anchor: [0.5, 46],
     text: "1SSMMMS",
     anchorXUnits: 'fraction',
     anchorYUnits: 'pixels',
     src: '../../../map_marker.png'
    }))
  });

startMarker = new ol.Feature({
     geometry: new ol.geom.Point(ol.proj.transform([lng, lat], 'EPSG:4326', 'EPSG:3857')),
     name: 'The icon',
     population: 4000,
     rainfall: 500
   });

startMarker.setStyle(iconStyle);
1

There are 1 answers

0
JGH On BEST ANSWER

You would need to create the text property (see the doc for default values)

 text: new ol.style.Text({
         font: '11px Calibri,sans-serif',
         text: "1SSMMMS",
         fill: fill
       })