React: Leaflet html Controls

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

In this tutorial I will demonstrate how to add html controls to your leaflet map. Refer to the documentation for more information.

Before We Begin:

Really you can create any html control just substitute div for whatever you want. Below are just some basic examples.

Div

  1. var divContainer = L.DomUtil.create("div", "myClassName");

Image

  1. var img = L.DomUtil.create("img", "myClassName");

Label

  1. var label = L.DomUtil.create("label", "myClassName");

Span

  1. var span = L.DomUtil.create("span", "myClassName");

Input

  1. var input = L.DomUtil.create("input", "myClassName");

BR

  1. var br = L.DomUtil.create("br", "myClassName");

You can modify the html control with additional values such as

  1. #style
  2. divContainer.style.display = "";
  3.  
  4. #id
  5. divContainer.id = "myId";
  6.  
  7. #name
  8. divContainer.name = "myId";
  9.  
  10. #img src
  11. divContainer.src = "";
  12.  
  13. #title
  14. divContainer.title = "";
  15.  
  16. #innerHTML
  17. divContainer.innerHTML = "";
  18.  
  19. #type
  20. divContainer.type= "checkbox";
  21.  
  22. #checked
  23. divContainer.checked= false;
  24.  
  25.  

Parent Control

You can add the control to a parent control in the following way.

  1. var divContainer = L.DomUtil.create("div", "myClassName");
  2.  
  3. var subContainer = L.DomUtil.create("div", "myClassName", divContainer);
Series Navigation<< React: Leaflet EasyButtonReact: Leaflet DomEvent >>