React: Leaflet Modal

This entry is part 2 of 9 in the series React: Leaflet
(Last Updated On: )

In this tutorial I will demonstrate how to add a modal dialog to your leaflet map. Refer to the documentation for more information.

Before We Begin:

Node Package Install:

  1. npm install leaflet-modal --save

Edit app/home/leaflet/js/map.jsx:

  1. //Add the leaflet modal package
  2. require("leaflet-modal");
  3. require("leaflet-modal/dist/leaflet.modal.min.css");
  4.  
  5. //Somewhere on your page add the following. You can even put it on a onclick event or whatever
  6.  
  7. //Create a test control for your modal control.
  8. this.modalContainer = L.DomUtil.create("div");
  9. map.openModal({
  10. zIndex: 10000,
  11. element: this.modalContainer, //The container to display in the modal
  12. OVERLAY_CLS: "overlay", //This is a built in class which you can change if you want
  13. MODAL_CLS: "modal", //This is a built in class which you can change if you want
  14. height: 200, width: 200,
  15. MODAL_CONTENT_CLS: "modal-content", //This is a built in class which you can change if you want
  16. CLOSE_CLS: "modal-close-hide" //The property for close class
  17. });

Edit app/home/leaflet/css/map.css:

  1. .modal-close-hide {
  2. /*Class for hiding the modal*/
  3. display: none;
  4. }
Series Navigation<< React: Basic Leaflet Map ExampleReact: Leaflet EasyButton >>