效果:
通过判断坐标范围生成查询到的点
function onDoubleClick(e) { //矩形绘制完成,移除临时矩形,并停止监听鼠标移动事件 that.tmprect.remove(); map.off('mousemove'); //右下角坐标 latlngs[1] = [e.latlng.lat, e.latlng.lng]; that.rectangle = L.rectangle(latlngs, { color: '#6c54e8', fillOpacity: .2, weight: 5 }) that.rectangle.addTo(map); let len = that.Geojsondata.length let addpoint = [] //获取范围内点 for(let i = 0;i<len;i++){ if((that.Geojsondata[i].lay[0] > that.tmprect._latlngs[0][0].lng) && (that.Geojsondata[i].lay[0] < that.tmprect._latlngs[0][2].lng)){ if((that.Geojsondata[i].lay[1] > that.tmprect._latlngs[0][0].lat) && (that.Geojsondata[i].lay[1] < that.tmprect._latlngs[0][1].lat)){ addpoint.push(that.Geojsondata[i]) } } } console.log(addpoint,'end') let addlen = addpoint.length //marker生成 for(let i = 0;i<addlen;i++){ L.marker([addpoint[i].lay[1], addpoint[i].lay[0]]).addTo(map).bindPopup(addpoint[i].name).openPopup() } }效果: