3

I already have a geojson being consulted and that is plotting these black dots. And then I inserted the leaflet-geoman plugin to give users the freedom to create polygons on the map. Basically draw something there.

enter image description here

For example: Draw a polygon to get only the information inside that polygon.

When using the tool to draw a polygon on the map I wanted to get which black dot is inside the drawing

enter image description here

in short: I have 4 points within my polygon drawing (which does not come from a geojson, the person draws) and I want to get the information from those points that are within that drawn polygon. Each black dot in this one has an id, and I want to know what points are within the space that the person drew.

My geoman-Leaflet code:

      map.pm.addControls({
        position: 'topright',
        // drawCircle: false,
        drawMarker: false,
        drawCircleMarker: false,
        drawRectangle: false,
        cutPolygon: false,
        editPolygon: false,
      });

My black dots on the map code:

  wellheads.forEach(function (d) {
        d.LatLng = new L.latLng(d.latitude, d.longitude);
      });

  const groupWells = g
        .selectAll('g')
        .data(wellheads)
        .enter()
        .append('g')
        .attr('pointer-events', 'visible');

      const points = groupWells
        .append('circle')
        .attr('class', d => {
          if (wellState.selectedWell.guid === d.wellboreGUID) {
            return 'redW';
          } else {
            return 'blackW';
          }
        })
        .attr('id', d => `id-${d.wellboreGUID}`)
        .attr('r', d => {
          if (wellState.selectedWell.guid === d.wellboreGUID) {
            return 1.7;
          } else {
            return 1.0;
          }
        })

6
  • 1
    Yes, it's possible. Please edit your question and part of the code where/when circle is created and you would like to get info about contained points.
    – TomazicM
    Jan 5, 2021 at 17:38
  • @TomazicM I think she creates the circle directly as svg path and not as L.Circle, like that how it is in the question. But I'm also not sure. And can you please create the tag [leaflet-geoman], because this is not leaflet-draw. I would do it by myself but I have not enough reputation on GIS SE Jan 5, 2021 at 17:56
  • @FalkeDesign Whatever kind of circle it is, at the time of creation it has known center and radius, and that's what is needed to get points within radius. As far as new tag is concerned, I don't have enough privilege to create it.
    – TomazicM
    Jan 5, 2021 at 19:18
  • guys, i creat the circle just with the geoman-leaflet, and in the question has the cod. from the moment I add the draw toolbar, I can draw any polygon on the map. i put the code referent from de dots. My dots i made with append circle in another function. I want from the moment I draw a polygon with the geoman-leaflet I can get the ID of each black dot Jan 5, 2021 at 19:30
  • @TomazicM i cannot find the leaflet-geoman, thats why i did not put. Jan 5, 2021 at 19:35

1 Answer 1

1

This could be achieved with turf.js' booleanWithin, by testing each point against the created polygon.

For example you can a listener for when the drawing is complete:

map.on('pm:create', (e) => {  
  feature = e.layer.toGeoJSON();
  wellheads.forEach(function (d) {
        d.within = turf.booleanWithin(turf.point([d.latitude, d.longitude]), feature );
      });
});

This is a basic way to test this, I would recommend using L.marker or L.circle on your maps instead of manually drawing svg paths on the canvas.

10
  • GeoJSON does not have circle geometry. Does leaflet-geoman plugin create some approximate polygon?
    – TomazicM
    Jan 5, 2021 at 20:19
  • It does, but the question wasn't specific to circles, but to a drawn polygon, at least when I answered it. Whatever polygon leaflet-geoman draws should work with turf since it accepts either turf.js geometry or a GeoJSON feature
    – Dror Bogin
    Jan 5, 2021 at 20:22
  • i cannot use l.circle or l.marker, i need just draw a polygon in the map. this polygon or circle is not a ready geojson. is the person who can draw from the geoman-leaflet drawing tool Jan 5, 2021 at 20:31
  • @DrorBogin As I wrote, GeoJSON standard doesn't have circle geometry, see en.wikipedia.org/wiki/GeoJSON#Geometries. As far as question goes, there is image of circle and then statement: "I want to know what is the id of the pins that are within that radius."
    – TomazicM
    Jan 5, 2021 at 20:34
  • @TomazicM as I stated, when I answered the question it was "I was wondering if there is a possibility that I can get the id's of these black dots but that are inside my polygon?". since leaflet-geoman supports multiple polygon types, my answer is true for all of them, whether circular or not.
    – Dror Bogin
    Jan 5, 2021 at 21:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.