Popup data does not change from one icon to another without closing the popup first

VAT refund for a conference ticket in Sweden

Why are special aircraft used for the carriers in the United States Navy?

Canadian citizen, on US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

How can I handle a player who pre-plans arguments about my rulings on RAW?

What Does the Heart In Gyms Mean?

Toast materialize

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

Is there a frame of reference in which I was born before I was conceived?

Book about a time-travel war fought by computers

In iTunes 12 on macOS, how can I reset the skip count of a song?

Is the withholding of funding notice allowed?

At what level can a party fight a mimic?

Source for Cremation Specifically Not Jewish

I encountered my boss during an on-site interview at another company. Should I bring it up when seeing him next time?

What happened to QGIS 2.x LTR?

Difference between 'stomach' and 'uterus'

What am I? I am in theaters and computer programs

If nine coins are tossed, what is the probability that the number of heads is even?

Inverse of the covariance matrix of a multivariate normal distribution

Reason why dimensional travelling would be restricted

How can I create a Table like this in Latex?

I can't die. Who am I?

Rationale to prefer local variables over instance variables?

The need of reserving one's ability in job interviews



Popup data does not change from one icon to another without closing the popup first














0















I am working on an application that will display markers on an OpenStreetMap.



I can get the markers to display correctly on the map via my function, and I have assigned each marker details specific to a member, which displays just fine except if I click on another marker, before clicking somewhere on the map to close the currently displayed popup. The details displayed in the new popup over the new marker remains the same as the last marker if I do not close the popup.



I tried clearing the field using "content: ''," as you can see, but that didn't change the behavior.



How do I ensure if a user clicks on one marker, then clicks another marker it will display the features of the new marker?



Here is my html:



<!DOCTYPE html>
<head>
<title>Multiple Markers with Popups</title>
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="js/fn_mapMarkers.js"></script>
<style>
#map {
position: relative;
}
</style>
</head>
<body>
<div id="map"><div id="popup"></div></div>
</body>
<script>
var markers = [
['John', 'Doe',-86.1581,39.7684,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['John', 'Smith',-122.3321,47.6062,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Jane', 'Doe',-90.0490,35.1495,3,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Jane', 'Smith',-74.0060,40.7128,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Joe', 'Dirt',-112.0740,33.4484,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Jane', 'Dirt',-97.3301,37.6872,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Someone', 'Special',-81.3792,28.5383,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
['Something', 'Special',-90.0715,29.9511,2,'<a href="http://linkToProfile.org">LinkToProfile</a>']
];
mapMarkers(markers, [-98.5795,39.8283]);
</script>
</html>


And the Javascript file:



function mapMarkers(memberInfo, mapCenter){

var baseLayerMap = new ol.layer.Tile({
source: new ol.source.OSM()
});

var map = new ol.Map({
target: 'map',
layers: [baseLayerMap],
view: new ol.View({
center: ol.proj.fromLonLat(mapCenter),
zoom: 4
})
});

var element = document.getElementById('popup');

var popup = new ol.Overlay ({
element: element,
positioning: 'bottom-center',
stopEvent: false,
offset: [0, -20]
});

map.addOverlay(popup);

var iconStyle_1 = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 26],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker.png'
})
});

var iconStyle_2 = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 26],
anchorXUnits: "fraction",
anchorYUnits: "pixel",
src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker2.png'
})
});

var iconStyle_3 = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 26],
anchorXUnits: "fraction",
anchorYUnits: "pixel",
src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_3cc483.png'
})
});

var iconStyle_4 = new ol.style.Style({
image: new ol.style.Icon({
anchor: [0.5, 26],
anchorXUnits: "fraction",
anchorYUnits: "pixel",
src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_53b3e8.png'
})
});

var markers = [];
var i;
for (i = 0; i < memberInfo.length; i++) {
// Add a marker for each active member
markers.push(new ol.Feature({
type: 'click',
desc: memberInfo[i][0] + " " + memberInfo[i][1] + "<br>" + memberInfo[i][5],
geometry: new ol.geom.Point(
ol.proj.fromLonLat([memberInfo[i][2],memberInfo[i][3]])
)
}));
switch (memberInfo[i][4]) {
case 1:
markers[i].setStyle(iconStyle_1);
break;
case 2:
markers[i].setStyle(iconStyle_2);
break;
case 3:
markers[i].setStyle(iconStyle_3);
break;
case 4:
markers[i].setStyle(iconStyle_4);
break;
}
}

var vectorMarkerSource = new ol.source.Vector({
features: markers
});

var vectorMarkerLayer = new ol.layer.Vector({
source: vectorMarkerSource
});

map.addLayer(vectorMarkerLayer);

map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature) {
return feature;
});
if (feature) {
var coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
$(element).popover({
content: '',
placement: 'top',
html: true,
content: feature.get('desc')
});
$(element).popover('show');
} else {
$(element).popover('destroy');
}
});

map.on('pointermove', function(e) {
if (e.dragging) {
$(element).popover('destroy');
return;
}
var pixel = map.getEventPixel(e.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTargetElement().style.cursor = hit ? 'pointer' : '';
});
}








share



























    0















    I am working on an application that will display markers on an OpenStreetMap.



    I can get the markers to display correctly on the map via my function, and I have assigned each marker details specific to a member, which displays just fine except if I click on another marker, before clicking somewhere on the map to close the currently displayed popup. The details displayed in the new popup over the new marker remains the same as the last marker if I do not close the popup.



    I tried clearing the field using "content: ''," as you can see, but that didn't change the behavior.



    How do I ensure if a user clicks on one marker, then clicks another marker it will display the features of the new marker?



    Here is my html:



    <!DOCTYPE html>
    <head>
    <title>Multiple Markers with Popups</title>
    <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="js/fn_mapMarkers.js"></script>
    <style>
    #map {
    position: relative;
    }
    </style>
    </head>
    <body>
    <div id="map"><div id="popup"></div></div>
    </body>
    <script>
    var markers = [
    ['John', 'Doe',-86.1581,39.7684,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['John', 'Smith',-122.3321,47.6062,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Jane', 'Doe',-90.0490,35.1495,3,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Jane', 'Smith',-74.0060,40.7128,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Joe', 'Dirt',-112.0740,33.4484,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Jane', 'Dirt',-97.3301,37.6872,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Someone', 'Special',-81.3792,28.5383,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
    ['Something', 'Special',-90.0715,29.9511,2,'<a href="http://linkToProfile.org">LinkToProfile</a>']
    ];
    mapMarkers(markers, [-98.5795,39.8283]);
    </script>
    </html>


    And the Javascript file:



    function mapMarkers(memberInfo, mapCenter){

    var baseLayerMap = new ol.layer.Tile({
    source: new ol.source.OSM()
    });

    var map = new ol.Map({
    target: 'map',
    layers: [baseLayerMap],
    view: new ol.View({
    center: ol.proj.fromLonLat(mapCenter),
    zoom: 4
    })
    });

    var element = document.getElementById('popup');

    var popup = new ol.Overlay ({
    element: element,
    positioning: 'bottom-center',
    stopEvent: false,
    offset: [0, -20]
    });

    map.addOverlay(popup);

    var iconStyle_1 = new ol.style.Style({
    image: new ol.style.Icon({
    anchor: [0.5, 26],
    anchorXUnits: 'fraction',
    anchorYUnits: 'pixels',
    opacity: 0.75,
    src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker.png'
    })
    });

    var iconStyle_2 = new ol.style.Style({
    image: new ol.style.Icon({
    anchor: [0.5, 26],
    anchorXUnits: "fraction",
    anchorYUnits: "pixel",
    src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker2.png'
    })
    });

    var iconStyle_3 = new ol.style.Style({
    image: new ol.style.Icon({
    anchor: [0.5, 26],
    anchorXUnits: "fraction",
    anchorYUnits: "pixel",
    src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_3cc483.png'
    })
    });

    var iconStyle_4 = new ol.style.Style({
    image: new ol.style.Icon({
    anchor: [0.5, 26],
    anchorXUnits: "fraction",
    anchorYUnits: "pixel",
    src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_53b3e8.png'
    })
    });

    var markers = [];
    var i;
    for (i = 0; i < memberInfo.length; i++) {
    // Add a marker for each active member
    markers.push(new ol.Feature({
    type: 'click',
    desc: memberInfo[i][0] + " " + memberInfo[i][1] + "<br>" + memberInfo[i][5],
    geometry: new ol.geom.Point(
    ol.proj.fromLonLat([memberInfo[i][2],memberInfo[i][3]])
    )
    }));
    switch (memberInfo[i][4]) {
    case 1:
    markers[i].setStyle(iconStyle_1);
    break;
    case 2:
    markers[i].setStyle(iconStyle_2);
    break;
    case 3:
    markers[i].setStyle(iconStyle_3);
    break;
    case 4:
    markers[i].setStyle(iconStyle_4);
    break;
    }
    }

    var vectorMarkerSource = new ol.source.Vector({
    features: markers
    });

    var vectorMarkerLayer = new ol.layer.Vector({
    source: vectorMarkerSource
    });

    map.addLayer(vectorMarkerLayer);

    map.on('click', function(evt) {
    var feature = map.forEachFeatureAtPixel(evt.pixel,
    function(feature) {
    return feature;
    });
    if (feature) {
    var coordinates = feature.getGeometry().getCoordinates();
    popup.setPosition(coordinates);
    $(element).popover({
    content: '',
    placement: 'top',
    html: true,
    content: feature.get('desc')
    });
    $(element).popover('show');
    } else {
    $(element).popover('destroy');
    }
    });

    map.on('pointermove', function(e) {
    if (e.dragging) {
    $(element).popover('destroy');
    return;
    }
    var pixel = map.getEventPixel(e.originalEvent);
    var hit = map.hasFeatureAtPixel(pixel);
    map.getTargetElement().style.cursor = hit ? 'pointer' : '';
    });
    }








    share

























      0












      0








      0








      I am working on an application that will display markers on an OpenStreetMap.



      I can get the markers to display correctly on the map via my function, and I have assigned each marker details specific to a member, which displays just fine except if I click on another marker, before clicking somewhere on the map to close the currently displayed popup. The details displayed in the new popup over the new marker remains the same as the last marker if I do not close the popup.



      I tried clearing the field using "content: ''," as you can see, but that didn't change the behavior.



      How do I ensure if a user clicks on one marker, then clicks another marker it will display the features of the new marker?



      Here is my html:



      <!DOCTYPE html>
      <head>
      <title>Multiple Markers with Popups</title>
      <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
      <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
      <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
      <script src="js/fn_mapMarkers.js"></script>
      <style>
      #map {
      position: relative;
      }
      </style>
      </head>
      <body>
      <div id="map"><div id="popup"></div></div>
      </body>
      <script>
      var markers = [
      ['John', 'Doe',-86.1581,39.7684,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['John', 'Smith',-122.3321,47.6062,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Doe',-90.0490,35.1495,3,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Smith',-74.0060,40.7128,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Joe', 'Dirt',-112.0740,33.4484,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Dirt',-97.3301,37.6872,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Someone', 'Special',-81.3792,28.5383,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Something', 'Special',-90.0715,29.9511,2,'<a href="http://linkToProfile.org">LinkToProfile</a>']
      ];
      mapMarkers(markers, [-98.5795,39.8283]);
      </script>
      </html>


      And the Javascript file:



      function mapMarkers(memberInfo, mapCenter){

      var baseLayerMap = new ol.layer.Tile({
      source: new ol.source.OSM()
      });

      var map = new ol.Map({
      target: 'map',
      layers: [baseLayerMap],
      view: new ol.View({
      center: ol.proj.fromLonLat(mapCenter),
      zoom: 4
      })
      });

      var element = document.getElementById('popup');

      var popup = new ol.Overlay ({
      element: element,
      positioning: 'bottom-center',
      stopEvent: false,
      offset: [0, -20]
      });

      map.addOverlay(popup);

      var iconStyle_1 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: 'fraction',
      anchorYUnits: 'pixels',
      opacity: 0.75,
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker.png'
      })
      });

      var iconStyle_2 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker2.png'
      })
      });

      var iconStyle_3 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_3cc483.png'
      })
      });

      var iconStyle_4 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_53b3e8.png'
      })
      });

      var markers = [];
      var i;
      for (i = 0; i < memberInfo.length; i++) {
      // Add a marker for each active member
      markers.push(new ol.Feature({
      type: 'click',
      desc: memberInfo[i][0] + " " + memberInfo[i][1] + "<br>" + memberInfo[i][5],
      geometry: new ol.geom.Point(
      ol.proj.fromLonLat([memberInfo[i][2],memberInfo[i][3]])
      )
      }));
      switch (memberInfo[i][4]) {
      case 1:
      markers[i].setStyle(iconStyle_1);
      break;
      case 2:
      markers[i].setStyle(iconStyle_2);
      break;
      case 3:
      markers[i].setStyle(iconStyle_3);
      break;
      case 4:
      markers[i].setStyle(iconStyle_4);
      break;
      }
      }

      var vectorMarkerSource = new ol.source.Vector({
      features: markers
      });

      var vectorMarkerLayer = new ol.layer.Vector({
      source: vectorMarkerSource
      });

      map.addLayer(vectorMarkerLayer);

      map.on('click', function(evt) {
      var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature) {
      return feature;
      });
      if (feature) {
      var coordinates = feature.getGeometry().getCoordinates();
      popup.setPosition(coordinates);
      $(element).popover({
      content: '',
      placement: 'top',
      html: true,
      content: feature.get('desc')
      });
      $(element).popover('show');
      } else {
      $(element).popover('destroy');
      }
      });

      map.on('pointermove', function(e) {
      if (e.dragging) {
      $(element).popover('destroy');
      return;
      }
      var pixel = map.getEventPixel(e.originalEvent);
      var hit = map.hasFeatureAtPixel(pixel);
      map.getTargetElement().style.cursor = hit ? 'pointer' : '';
      });
      }








      share














      I am working on an application that will display markers on an OpenStreetMap.



      I can get the markers to display correctly on the map via my function, and I have assigned each marker details specific to a member, which displays just fine except if I click on another marker, before clicking somewhere on the map to close the currently displayed popup. The details displayed in the new popup over the new marker remains the same as the last marker if I do not close the popup.



      I tried clearing the field using "content: ''," as you can see, but that didn't change the behavior.



      How do I ensure if a user clicks on one marker, then clicks another marker it will display the features of the new marker?



      Here is my html:



      <!DOCTYPE html>
      <head>
      <title>Multiple Markers with Popups</title>
      <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">
      <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
      <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
      <script src="js/fn_mapMarkers.js"></script>
      <style>
      #map {
      position: relative;
      }
      </style>
      </head>
      <body>
      <div id="map"><div id="popup"></div></div>
      </body>
      <script>
      var markers = [
      ['John', 'Doe',-86.1581,39.7684,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['John', 'Smith',-122.3321,47.6062,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Doe',-90.0490,35.1495,3,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Smith',-74.0060,40.7128,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Joe', 'Dirt',-112.0740,33.4484,1,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Jane', 'Dirt',-97.3301,37.6872,4,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Someone', 'Special',-81.3792,28.5383,2,'<a href="http://linkToProfile.org">LinkToProfile</a>'],
      ['Something', 'Special',-90.0715,29.9511,2,'<a href="http://linkToProfile.org">LinkToProfile</a>']
      ];
      mapMarkers(markers, [-98.5795,39.8283]);
      </script>
      </html>


      And the Javascript file:



      function mapMarkers(memberInfo, mapCenter){

      var baseLayerMap = new ol.layer.Tile({
      source: new ol.source.OSM()
      });

      var map = new ol.Map({
      target: 'map',
      layers: [baseLayerMap],
      view: new ol.View({
      center: ol.proj.fromLonLat(mapCenter),
      zoom: 4
      })
      });

      var element = document.getElementById('popup');

      var popup = new ol.Overlay ({
      element: element,
      positioning: 'bottom-center',
      stopEvent: false,
      offset: [0, -20]
      });

      map.addOverlay(popup);

      var iconStyle_1 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: 'fraction',
      anchorYUnits: 'pixels',
      opacity: 0.75,
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker.png'
      })
      });

      var iconStyle_2 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker2.png'
      })
      });

      var iconStyle_3 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_3cc483.png'
      })
      });

      var iconStyle_4 = new ol.style.Style({
      image: new ol.style.Icon({
      anchor: [0.5, 26],
      anchorXUnits: "fraction",
      anchorYUnits: "pixel",
      src: '//raw.githubusercontent.com/jonataswalker/map-utils/master/images/marker_53b3e8.png'
      })
      });

      var markers = [];
      var i;
      for (i = 0; i < memberInfo.length; i++) {
      // Add a marker for each active member
      markers.push(new ol.Feature({
      type: 'click',
      desc: memberInfo[i][0] + " " + memberInfo[i][1] + "<br>" + memberInfo[i][5],
      geometry: new ol.geom.Point(
      ol.proj.fromLonLat([memberInfo[i][2],memberInfo[i][3]])
      )
      }));
      switch (memberInfo[i][4]) {
      case 1:
      markers[i].setStyle(iconStyle_1);
      break;
      case 2:
      markers[i].setStyle(iconStyle_2);
      break;
      case 3:
      markers[i].setStyle(iconStyle_3);
      break;
      case 4:
      markers[i].setStyle(iconStyle_4);
      break;
      }
      }

      var vectorMarkerSource = new ol.source.Vector({
      features: markers
      });

      var vectorMarkerLayer = new ol.layer.Vector({
      source: vectorMarkerSource
      });

      map.addLayer(vectorMarkerLayer);

      map.on('click', function(evt) {
      var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature) {
      return feature;
      });
      if (feature) {
      var coordinates = feature.getGeometry().getCoordinates();
      popup.setPosition(coordinates);
      $(element).popover({
      content: '',
      placement: 'top',
      html: true,
      content: feature.get('desc')
      });
      $(element).popover('show');
      } else {
      $(element).popover('destroy');
      }
      });

      map.on('pointermove', function(e) {
      if (e.dragging) {
      $(element).popover('destroy');
      return;
      }
      var pixel = map.getEventPixel(e.originalEvent);
      var hit = map.hasFeatureAtPixel(pixel);
      map.getTargetElement().style.cursor = hit ? 'pointer' : '';
      });
      }






      openlayers popup





      share












      share










      share



      share










      asked 2 mins ago









      SouthernYankee65SouthernYankee65

      11




      11






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f314512%2fpopup-data-does-not-change-from-one-icon-to-another-without-closing-the-popup-fi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f314512%2fpopup-data-does-not-change-from-one-icon-to-another-without-closing-the-popup-fi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...