Skip to content

Commit

Permalink
#390 InfoTool - Clicks Intersect Polygons (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jun 28, 2023
1 parent e6a5e0d commit 9fac207
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 19 deletions.
36 changes: 31 additions & 5 deletions src/essence/Basics/Formulae_/Formulae_.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,15 +1718,41 @@ var Formulae_ = {
},
}
},
pointsInPoint(point, layers) {
var points = []
// searchRadiusInDegrees = [lng, lng, lat, lat] bbox
pointsInPoint(point, layers, searchRadiusInDegrees) {
const points = []

var l = layers._layers
const l = layers._layers

if (l == null) return points

for (var i in l) {
if (
for (let i in l) {
if (searchRadiusInDegrees != null) {
if (
l[i].feature.geometry.coordinates[0] >
Math.min(
searchRadiusInDegrees[0],
searchRadiusInDegrees[1]
) &&
l[i].feature.geometry.coordinates[0] <
Math.max(
searchRadiusInDegrees[0],
searchRadiusInDegrees[1]
) &&
l[i].feature.geometry.coordinates[1] >
Math.min(
searchRadiusInDegrees[2],
searchRadiusInDegrees[3]
) &&
l[i].feature.geometry.coordinates[1] <
Math.max(
searchRadiusInDegrees[2],
searchRadiusInDegrees[3]
)
) {
points.push(l[i])
}
} else if (
l[i].feature.geometry.coordinates[0] == point[0] &&
l[i].feature.geometry.coordinates[1] == point[1]
)
Expand Down
7 changes: 6 additions & 1 deletion src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,9 @@ const L_ = {
selectPoint(activePoint) {
if (activePoint == null) return false
// Backward pre-uuid compatibility
activePoint.layerUUID = L_.asLayerUUID(activePoint.layerUUID)
activePoint.layerUUID = L_.asLayerUUID(
activePoint.layerUUID || activePoint.layerName
)

if (
activePoint.layerUUID != null &&
Expand Down Expand Up @@ -1919,6 +1921,9 @@ const L_ = {
L_.Globe_.litho.setCenter(newView)
}
}
setTimeout(() => {
L_.setActiveFeature(layer)
}, 300)
},
reorderLayers: function (newLayersOrdered) {
// Check that newLayersOrdered is valid
Expand Down
73 changes: 62 additions & 11 deletions src/essence/Tools/Kinds/Kinds.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,69 @@ var Kinds = {
}
}
}
features = L.leafletPip
.pointInLayer(
[e.latlng.lng, e.latlng.lat],
L_.layers.layer[layerName]
)
.concat(
F_.pointsInPoint(
[e.latlng.lng, e.latlng.lat],
L_.layers.layer[layerName]

// To better intersect points on click we're going to buffer out a small bounding box
const mapRect = document
.getElementById('map')
.getBoundingClientRect()

const wOffset = e.containerPoint?.x || mapRect.width / 2
const hOffset = e.containerPoint?.y || mapRect.height / 2

let nwLatLong = Map_.map.containerPointToLatLng([
wOffset - 15,
hOffset - 15,
])
let seLatLong = Map_.map.containerPointToLatLng([
wOffset + 15,
hOffset + 15,
])
// If we didn't have a container click point, buffer out e.latlng
if (e.containerPoint == null) {
const lngDif =
Math.abs(nwLatLong.lng - seLatLong.lng) / 2
const latDif =
Math.abs(nwLatLong.lat - seLatLong.lat) / 2
nwLatLong = {
lng: e.latlng.lng - lngDif,
lat: e.latlng.lat - latDif,
}
seLatLong = {
lng: e.latlng.lng + lngDif,
lat: e.latlng.lat + latDif,
}
}

// Find all the intersected points and polygons of the click
Object.keys(L_.layers.layer).forEach((lName) => {
if (
L_.layers.on[lName] &&
L_.layers.data[lName].type === 'vector' &&
L_.layers.layer[lName]
) {
features = features.concat(
L.leafletPip
.pointInLayer(
[e.latlng.lng, e.latlng.lat],
L_.layers.layer[lName]
)
.concat(
F_.pointsInPoint(
[e.latlng.lng, e.latlng.lat],
L_.layers.layer[lName],
[
nwLatLong.lng,
seLatLong.lng,
nwLatLong.lat,
seLatLong.lat,
]
)
)
.reverse()
)
)
.reverse()
}
})

if (features[0] == null) features = [feature]
else {
const swapFeatures = []
Expand Down
3 changes: 1 addition & 2 deletions src/external/Leaflet/leaflet-pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@
p = p.concat().reverse()

var results = []
if (typeof layer.eachLayer === 'feature') {
if (typeof layer.eachLayer === 'function') {
layer.eachLayer(function (l) {
if (first && results.length) return

if (
isPoly(l) &&
gju.pointInPolygon(
Expand Down

0 comments on commit 9fac207

Please sign in to comment.