I solved with this code that give-me a point on "lat", "lng" with the "label". The "offsetY" controller the distance between the point and your label on Y axis.
const addMapPoint = (lat, lng, label, offsetY) => {
iconStyle = [
new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [.5, 1],
anchorXUnits: 'fraction',
anchorYUnits: 'fraction',
src: "/static/images/pin.png",
scale: 1
}))
}),
new ol.style.Style({
text: new ol.style.Text({
text: label,
offsetY: offsetY,
scale: 2,
fill: new ol.style.Fill({
color: '#black',
})
})
})
];
const 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: iconStyle
});
map.addLayer(vectorLayer);
}
answered 01 May '20, 15:08

rodrigomartins
11●1●1●1
accept rate: 0%
Which website or app are you talking about?
OpenLayers according to the recent answer. I added the openlayers tag.