In this recipe, you will learn how to add markers with popups dynamically. We will enhance the previous recipe, which displays a map, and we will add a button that will open a popup in which we can type coordinates.
When we click on the OK button, a new marker will be created, and the map will zoom and pan to the location of this marker; if there are multiple markers, it will zoom to fit them all.
Perform the following steps:
Create a map and add a base layer.
Then add new markers to the map using
bindPopup('enter html content here')to bind a popup to the marker.