I’m trying to integrate “pinning” functionality into my OpenLayers popups. Right now, when the user clicks on a “pin” image I’ve placed inside a popup, I want the source to toggle between the pinned.png image and an unpinned.png image.
I’m trying to do so like this:
var pHtml = marker.feature.data.popupContentHTML;
marker.feature.data.popupContentHTML = pHtml.replace("pinned.png", "unpinned.png");
This seems to change the popupContentHTML variable (because when I console.log it, the “pinned.png” has been replaced with “unpinned.png” for the marker), but the HTML on-screen does not change.
Is there an easier way to do this, or is there a way to refresh the popup to display the new popupContentHTML?
There’s a setter function for the HTML content that also updates the DOM element for the popup. It’s called
setContentHTML.