I would like to have all the points highlighted within the other highlighted GeoJSON polygon.

enter image description here

Next, I would like to have them displayed in the panel next to or at least in the console (for now).

The problem is, that code I provided doesn't work. I can't see these points anywhere.

var ptsWithin = turf.within(placesLayer.toGeoJSON(), total.toGeoJSON());

map.on('draw:created', function (e) {
  layer = e.layer;

function GetSelection(layer) {

  var shape2 = placesLayer.toGeoJSON() //All facilities
  var ptsWithin = turf.within(total, layer.toGeoJSON());

  alert('Found ' + ptsWithin.features.length + ' features');
  alert("results " + JSON.stringify(ptsWithin));

which I've picked up from here:

Leaflet and Turf.js Points within poly

I also tried another approach:

var eclplaces = total.toGeoJSON().geometry.coordinates
placesLayer.eachLayer(function (layer) {
  if (turf.booleanContains(eclplaces, layer.toGeoJSON().geometry.coordinates)) {

but with no effect at all.

The same as this code:

Determine if a point reside inside a leaflet polygon

And the other options, which I found are here:

https://github.com/hayeswise/Leaflet.PointInPolygon https://stackoverflow.com/questions/31790344/determine-if-a-point-reside-inside-a-leaflet-polygon/31813714#31813714

The worst thing is, that console says nothing in these 2 cases.

Is there any way to highlight and list the points, which are located inside the highlighted polygon?

My full code is here:


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.