-
User StoryI have a map with thousands of markers that all have assigned popups. RationaleThe initial loading of all markers could be much faster if I didn't have to generate each marker's popup content preemptively but instead could provide a generator/callback function that returns popup content. For example, such API would be excellent (I use React for popup content generation but it does not matter): popup.setDOMContentGenerator(
() => renderToDiv(
<div>
<ul>
<li>Marker property: {marker.prop1}</li>
</ul>
</div>
)
); Generator function would be called only when marker is clicked and popup is about to being opened. Currently it's possible to have a hacky workaround that does not work too well:
ImpactIt makes maps faster and at the same time it's very easy to implement. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Why not listen to the marker's click event and create a popup in the callback (not update the popup html, but actually create a popup instance)? |
Beta Was this translation helpful? Give feedback.
-
Can you check the following sample? https://codesandbox.io/p/sandbox/sdd8cd I followed https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/ but the popup is not showing when clicking the marker. I'm not sure what I'm doing wrong. |
Beta Was this translation helpful? Give feedback.
-
The following worked for me, I don't know if this is a react thing or a different issue: marker.getElement().addEventListener("click", () => {
setTimeout(() => {
const popup = new maplibregl.Popup()
.setHTML("<b>popup content</b>")
.setLngLat(marker.getLngLat())
.addTo(map);
}, 0);
}); |
Beta Was this translation helpful? Give feedback.
-
Thanks it solves my problem. |
Beta Was this translation helpful? Give feedback.
The following worked for me, I don't know if this is a react thing or a different issue: