0

I have an application that uses leaflet.js and geoJSON to create a large polygon area that then gets populated with smaller circles using a mix of jQuery and leaflet.js.

This is where the circles are created:

$.getJSON('http://localhost/json/json.php', function(data){
        $(data.payload.incidents).each(function(key, value) {
            var lati = data.payload.incidents[key].incident.locationlatitude; 
            var longi = data.payload.incidents[key].incident.locationlongitude; 
            var title = data.payload.incidents[key].incident.incidenttitle;
            var desc = data.payload.incidents[key].incident.incidentdescription;
            var mark = L.circle([lati, longi], 50,{
                color: 'red',
                fillColor: '#f03',
                fillOpacity: 0.5
                }).addTo(map); 


            mark.bindPopup("<b>"+title+"</b></br></br>"+desc).openPopup();
            console.log("success");
            }
        })

    });

I have tried to use this line of code to detect the circles:

if(geojson.getBounds().contains(mark){console.log('mark detected')}

but .contains() appears only to be used for rectangles.

This is where the polygons are added to the map. (areaData is geoJSON)

        var geojson
        geojson = L.geoJson(areaData, {
        style: style,
        onEachFeature: onEachFeature
    }).addTo(map);
wtmcm
  • 307
  • 1
  • 4
  • 19
  • 1
    This is WAY too broad... what exactly are the elements? How are they created? Have you tried anything yet? Do you have any code to share? – Lix Oct 09 '13 at 10:37
  • polygon.getBounds() returns a bounding box. It's easy to check if a point is within a box; that's what contains does. Checking for a polygon is harder. There's a good discussion here http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test – kielni Oct 10 '13 at 14:05

1 Answers1

0

Can you try this

if(geojson.getBounds().contains(mark.getLatLng())){console.log('mark detected')}

since contains needs a latLong object and you are providing a L.circle object

Edu
  • 2,520
  • 1
  • 15
  • 15