diff --git a/src/essence/Basics/Formulae_/Formulae_.js b/src/essence/Basics/Formulae_/Formulae_.js index 3a604ab9..886c1743 100644 --- a/src/essence/Basics/Formulae_/Formulae_.js +++ b/src/essence/Basics/Formulae_/Formulae_.js @@ -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] ) diff --git a/src/essence/Basics/Layers_/Layers_.js b/src/essence/Basics/Layers_/Layers_.js index d6dc3321..e3e7cf51 100644 --- a/src/essence/Basics/Layers_/Layers_.js +++ b/src/essence/Basics/Layers_/Layers_.js @@ -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 && @@ -1919,6 +1921,9 @@ const L_ = { L_.Globe_.litho.setCenter(newView) } } + setTimeout(() => { + L_.setActiveFeature(layer) + }, 300) }, reorderLayers: function (newLayersOrdered) { // Check that newLayersOrdered is valid diff --git a/src/essence/Tools/Kinds/Kinds.js b/src/essence/Tools/Kinds/Kinds.js index f4f2317b..0fe00be6 100644 --- a/src/essence/Tools/Kinds/Kinds.js +++ b/src/essence/Tools/Kinds/Kinds.js @@ -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 = [] diff --git a/src/external/Leaflet/leaflet-pip.js b/src/external/Leaflet/leaflet-pip.js index 5bfbc2d8..a7ee2854 100644 --- a/src/external/Leaflet/leaflet-pip.js +++ b/src/external/Leaflet/leaflet-pip.js @@ -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(