From e34eb69c008742cdd5f0722c4e1c0197eda70814 Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Sun, 2 Feb 2020 16:28:41 +0059 Subject: [PATCH] Got GeoJSON-based location filtering working. --- package.json | 2 +- public/runtime-config.js | 20 ++++++++++---------- src/database.js | 7 ++++--- src/queries.js | 3 ++- src/userquerywidget.js | 25 +++++++++++++++---------- yarn.lock | 10 +++++----- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 352e585..10ae7a6 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,10 @@ "date-fns": "^2.0.0", "eslint": "^6.8.0", "eslint-plugin-react-hooks": "^2.3.0", + "geojson-utils": "^1.1.0", "leaflet": "^1.6.0", "lodash": "^4.17.15", "object-hash": "^2.0.1", - "point-in-polygon": "^1.0.1", "prop-types": "^15.6.0", "react": "^16.12.0", "react-dom": "^16.12.0", diff --git a/public/runtime-config.js b/public/runtime-config.js index d5434a5..c36dd2b 100644 --- a/public/runtime-config.js +++ b/public/runtime-config.js @@ -7,15 +7,15 @@ // } // Home config -// window['runtimeConfig'] = { -// digikamDbUrl: "https://192.168.1.101/digikam-fatclient-data/digikam4.db", -// photosUrl: "https://192.168.1.101/digikam-fatclient-data/photos", -// thumbsUrl: "https://192.168.1.101/digikam-fatclient-data/thumbs", -// } +window['runtimeConfig'] = { + digikamDbUrl: "https://192.168.1.101/digikam-fatclient-data/digikam4.db", + photosUrl: "https://192.168.1.101/digikam-fatclient-data/photos", + thumbsUrl: "https://192.168.1.101/digikam-fatclient-data/thumbs", +} // Production config -window['runtimeConfig'] = { - digikamDbUrl: "/digikam-fatclient-data/digikam4.db", - photosUrl: "/digikam-fatclient-data/photos", - thumbsUrl: "/digikam-fatclient-data/thumbs", -} \ No newline at end of file +// window['runtimeConfig'] = { +// digikamDbUrl: "/digikam-fatclient-data/digikam4.db", +// photosUrl: "/digikam-fatclient-data/photos", +// thumbsUrl: "/digikam-fatclient-data/thumbs", +// } \ No newline at end of file diff --git a/src/database.js b/src/database.js index e5e83da..6f6cc0a 100644 --- a/src/database.js +++ b/src/database.js @@ -50,9 +50,10 @@ export function regexp_match(string, regex) { } export function is_in_geo_polygon_from_store(lat, long, polygon_hash) { - const poly = get_polygon_from_store(polygon_hash); - var inside = require('point-in-polygon'); - return inside([lat, long], poly); + const geojson = get_polygon_from_store(polygon_hash); + var gju = require('geojson-utils'); + return gju.pointInPolygon({ "type": "Point", "coordinates": [long, lat] }, + geojson); } // Digikam stores its tree of tags as individual tags, diff --git a/src/queries.js b/src/queries.js index 338c3a4..e13520c 100644 --- a/src/queries.js +++ b/src/queries.js @@ -317,7 +317,8 @@ export class LocationFilter extends ResultFilter { // We need to store our polygon in said state and then return the query to guarantee that // it will have access to said polygon. const hash = add_polygon_to_store(this.polygon); - return 'IS_IN_GEO_POLYGON(ImagePositions.latitude, ImagePositions.longitude, "' + hash + '")'; + return '(ImagePositions.latitudeNumber NOT NULL AND ImagePositions.longitudeNumber NOT NULL AND ' + + 'IS_IN_GEO_POLYGON(ImagePositions.latitudeNumber, ImagePositions.longitudeNumber, "' + hash + '"))'; } simplify() { return this; } diff --git a/src/userquerywidget.js b/src/userquerywidget.js index 3f2d322..96d8a9b 100644 --- a/src/userquerywidget.js +++ b/src/userquerywidget.js @@ -66,26 +66,31 @@ export function EditLocationFilterExpression(props) { const { onChange, filter } = props; const [map, setMap] = useState(null); const [proposal, setProposal] = useState(filter.polygon); - const [polyLayers, setPolyLayers] = useState([]); + const [geoLayers, setGeoLayers] = useState([]); const classes = useStyles(); const _ = require('lodash'); function updateProposal(result) { - // TODO: handle multi-polies - const polygon = result.geojson.coordinates[0].map(longlat => [ longlat[1], longlat[0] ]); - - // Show the polyline on the map - polyLayers.forEach(layer => { + geoLayers.forEach(layer=> { map.removeLayer(layer); }); - var polyline = L.polyline(polygon, { color: 'blue' }).addTo(map); - map.flyToBounds(polyline.getBounds()); - setPolyLayers([polyline]); + var layer = L.geoJSON(result.geojson).addTo(map); + map.flyToBounds(layer.getBounds()); + setGeoLayers([layer]); + + // // Show the polyline on the map + // polyLayers.forEach(layer => { + // map.removeLayer(layer); + // }); + // var polyline = L.polyline(polygon, { color: 'blue' }).addTo(map); + // map.flyToBounds(polyline.getBounds()); + // setPolyLayers([polyline]); // Update the proposed polygon console.log("Updated proposal:", result); - setProposal(polygon); + // result.geojson.coordinates[0].map(longlat => [longlat[1], longlat[0]]); + setProposal(result.geojson); } function onSearch(query) { diff --git a/yarn.lock b/yarn.lock index a5764ac..36058f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4832,6 +4832,11 @@ gensync@^1.0.0-beta.1: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.1.tgz#58f4361ff987e5ff6e1e7a210827aa371eaac269" integrity sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== +geojson-utils@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/geojson-utils/-/geojson-utils-1.1.0.tgz#e8ffb4c81c0a75b3e306f5187265d6f23040f50b" + integrity sha1-6P+0yBwKdbPjBvUYcmXW8jBA9Qs= + get-caller-file@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" @@ -7782,11 +7787,6 @@ pnp-webpack-plugin@1.5.0: dependencies: ts-pnp "^1.1.2" -point-in-polygon@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/point-in-polygon/-/point-in-polygon-1.0.1.tgz#d59b64e8fee41c49458aac82b56718c5957b2af7" - integrity sha1-1Ztk6P7kHElFiqyCtWcYxZV7Kvc= - popper.js@^1.14.1: version "1.16.1" resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.16.1.tgz#2a223cb3dc7b6213d740e40372be40de43e65b1b"