TransWikia.com

Show Label on Map in Open Layers

Geographic Information Systems Asked by SudarshanK on August 4, 2021

I am working on a process to show location on the map along with its label. I have figured out the way to show the marker location but not the but I cannot figure out the way to show the label.

Here is my code:

var positionFeature = new ol.Feature();
positionFeature.setStyle(new ol.style.Style({
    image: new ol.style.Circle({
        radius: 6,
        fill: new ol.style.Fill({
            color: '#3399CC'
        }),
        stroke: new ol.style.Stroke({
            color: '#fff',
            width: 2
        })
    })
}));
var labelFeature = new ol.Feature();
labelFeature.setStyle(new ol.style.Style({
    text: new ol.style.Text({
        font: '14px Calibri,sans-serif',
        overflow: true,
        text: item.item.val.NAME,
        fill: new ol.style.Fill({
            color: "#000",
        }),
        stroke: new ol.style.Stroke({
            color: '#fff',
            width: 3,
        }),
    }),
}))

Geocoordinates = ol.proj.fromLonLat([it.LONG, it.LAT]);

positionFeature.setGeometry(Geocoordinates ?
    new ol.geom.Point(Geocoordinates) : null);
view.animate({
    center: Geocoordinates,
    duration: 200,
    zoom: 10                        
});

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP