1

I am doing a map on Leaflet and I would like to know how to put my polygons highlighted visually in some way when they are covered with a mouse a bit like that: http://www.gistechsolutions.com/leaflet/DEMO/basic/basic_Poly.html

I know you have to use the function highlightFeature but I can't use it.

$(document).ready(function () {
  map = L.map("map").setView([46.227638, 2.213749], 6);
  lControl = L.control.layers().addTo(map);

  fondPlan = L.tileLayer(
    "https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}",
    {
      maxZoom: 17,
    }
  ).addTo(map);
  lControl.addBaseLayer(fondPlan, "Carte topo");

  fondSAT = L.tileLayer("http://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}", {
    maxZoom: 17,
  }).addTo(map);
  lControl.addBaseLayer(fondSAT, "Carte Satellite");

  $.getJSON(
    "geojson/Muron.geojson",
    {},

    function (data) {
      vmuron = L.geoJSON(data, {
        style: function () {
          return {
            color: "#FF0000",
            weight: 2,
            opacity: 0.7,
          };
        },

        onEachFeature: function (feature, layer) {
          contenu =
            "<b>ID: </b>" +
            feature.properties.prefixe +
            feature.properties.section +
            feature.properties.numero +
            "<br>";
          contenu +=
            "<b>Surface: </b>" + feature.properties.contenance + " m² <br>";
          layer.bindTooltip(contenu, {
            permanent: false,
            sticky: false,
            opacity: 1,
            direction: "top",
          });
        },
      });

      vmuron.addTo(map);
      lControl.addOverlay(vmuron, "Muron");
    }
  );
});
  • Can you tell a bit more about "but I can't use it"? What does not work as expected? Is map displayed? Is GeoJSON overlay displayed? Are there any errors in the debugger console? You can see official example of highlighting polygons at Leaflet site: leafletjs.com/examples/choropleth – TomazicM Jun 4 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.