开放层 5.2.0。带文字的标记

openlayers 5.2.0. Markers with text

我的模板中有这段代码,希望标记与文本 "1SSMMMS" 一起出现,但我根本看不到任何文本市场

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);

您需要创建 text 属性(请参阅 doc 了解默认值)

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