Got GeoJSON-based location filtering working.

master
Sander Vocke 6 years ago
parent 0a948f8561
commit e34eb69c00
  1. 2
      package.json
  2. 20
      public/runtime-config.js
  3. 7
      src/database.js
  4. 3
      src/queries.js
  5. 25
      src/userquerywidget.js
  6. 10
      yarn.lock

@ -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",

@ -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",
}
// window['runtimeConfig'] = {
// digikamDbUrl: "/digikam-fatclient-data/digikam4.db",
// photosUrl: "/digikam-fatclient-data/photos",
// thumbsUrl: "/digikam-fatclient-data/thumbs",
// }

@ -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,

@ -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; }

@ -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) {

@ -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"

Loading…
Cancel
Save