Skip to content Skip to sidebar Skip to footer

Display Multiple Markers On Openlayers 5 Dynamically With Pop-up Window

I am trying to display two Markers on the Map which i already saved in an array. I want the Markers to be dynamically displayed and with a Pop-up window for each one. here is the c

Solution 1:

event.target.getFeatures() is used for select interactions. For pointermove on a map try replacing

if (map.hasFeatureAtPixel(event.pixel) === true) {  
    var coordinate = event.coordinate;
    const features = event.target.getFeatures();
    const batteryCharge  = features.get(0).get('batteryCharge');

with

const features = map.getFeaturesAtPixel(event.pixel);
if (features.length > 0) {
    var coordinate = event.coordinate;
    const batteryCharge = features[0].get('batteryCharge');

Post a Comment for "Display Multiple Markers On Openlayers 5 Dynamically With Pop-up Window"