Skip to content

Commit

Permalink
Fix: geodatasets_search last, Next/Prev and with restrict to geom type
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Nov 8, 2024
1 parent 066447a commit 34fa2e8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
22 changes: 20 additions & 2 deletions API/Backend/Geodatasets/routes/geodatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ router.post("/entries", function (req, res, next) {
* req.body.value
* req.body.id (specific feature id instead of key:value)
* req.body.orderBy
* req.body.restrictToGeometryType
* req.body.offset (i.e. if -1, then return feature previous to key:val) (can also be 'first' or 'last')
*/
router.post("/search", function (req, res, next) {
Expand Down Expand Up @@ -424,19 +425,36 @@ router.post("/search", function (req, res, next) {
)}, ${Utils.forceAlphaNumUnder(parseFloat(maxy))}, 4326), geom)`;
}

const geometryTypes = [
"Point",
"LineString",
"Polygon",
"MultiPoint",
"MultiLineString",
"MultiPolygon",
];

const geomTypeWhere =
geometryTypes.indexOf(req.body.restrictToGeometryType) != -1
? " AND geometry_type = :geomtype"
: "";

let q =
`SELECT properties, ST_AsGeoJSON(geom), id FROM ${Utils.forceAlphaNumUnder(
table
)}` +
(req.body.last || offset != null
? `${where} ORDER BY id ${offset != null ? "ASC" : "DESC LIMIT 1"}`
: " WHERE properties ->> :key = :value");
? `${where}${geomTypeWhere} ORDER BY id ${
offset != null && !req.body.last ? "ASC" : "DESC LIMIT 1"
}`
: ` WHERE properties ->> :key = :value${geomTypeWhere}`);

sequelize
.query(q + ";", {
replacements: {
orderBy: orderBy || "id",
key: req.body.key,
geomType: req.body.restrictToGeometryType,
value:
typeof req.body.value === "string"
? req.body.value.replace(/[`;'"]/gi, "")
Expand Down
14 changes: 11 additions & 3 deletions API/Backend/Users/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ router.post("/login", function (req, res) {
clearLoginSession(req);

req.session.regenerate((err) => {
let MMGISUser = req.cookies.MMGISUser
? JSON.parse(req.cookies.MMGISUser)
: false;
let MMGISUser;
try {
let userCookie = req.cookies.MMGISUser;
if (typeof userCookie === "string" && userCookie.endsWith("}undefined"))
userCookie = userCookie.substring(0, userCookie.length - 9);

MMGISUser = userCookie ? JSON.parse(userCookie) : false;
} catch (err) {
res.send({ status: "failure", message: "Malformed MMGISUser cookie." });
return;
}
let username = req.body.username || (MMGISUser ? MMGISUser.username : null);

if (username == null) {
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Disable Globe more thoroughly when off
Additional Body Metadata for Draw Webhooks
Remove restriction on Layer names
Check for empty time configs in TimeControl
Dropdown in the topbar for a selected features properties links
Dropdown in the topbar for a selected feature's properties links

#### Fixed

Expand Down
1 change: 1 addition & 0 deletions src/essence/Ancillary/Description.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
}
#mainDescNavPopoverExtent,
#mainDescNavPopoverTimeExtent,
#mainDescNavPopoverGeometryType,
#mainDescNavPopoverPanTo {
display: flex;
justify-content: space-between;
Expand Down
40 changes: 40 additions & 0 deletions src/essence/Ancillary/Description.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const Description = {
`<div>Restrict to Time Range</div>`,
`<div class="mmgis-checkbox"><input type="checkbox" ${false ? 'checked ' : ''}id="checkbox_dp15"/><label for="checkbox_dp15"></label></div>`,
`</div>`,
`<div id="mainDescNavPopoverGeometryType">`,
`<div>Restrict to Geometry Type</div>`,
`<div class="mmgis-checkbox"><input type="checkbox" ${false ? 'checked ' : ''}id="checkbox_dp155"/><label for="checkbox_dp155"></label></div>`,
`</div>`,
`<div id="mainDescNavPopoverPanTo">`,
`<div>Pan To Feature</div>`,
`<div class="mmgis-checkbox"><input type="checkbox" ${false ? 'checked ' : ''}id="checkbox_dp2"/><label for="checkbox_dp2"></label></div>`,
Expand Down Expand Up @@ -234,6 +238,7 @@ const Description = {
if (
properties.indexOf(p) === -1 &&
p.indexOf('images') !== 0 &&
p.indexOf('style') !== 0 &&
p[0] !== '_'
)
properties.push(p)
Expand Down Expand Up @@ -402,6 +407,22 @@ const Description = {
) {
hasTimeBounds = true
}

let geomTypeRestriction = false
if (
$('#mainDescNavPopoverGeometryType input').is(
':checked'
)
) {
geomTypeRestriction =
active?.feature?.geometry?.type || false
}
if (geomTypeRestriction) {
features = features.filter((f) => {
return geomTypeRestriction === f?.geometry?.type
})
}

// Limit to current map extent if checkbox is true
let hasBounds = false
const b = Description.Map_.map.getBounds()
Expand Down Expand Up @@ -478,6 +499,7 @@ const Description = {
direction === 'last'
? direction
: offset,
restrictToGeometryType: geomTypeRestriction,
}

if (hasBounds) {
Expand Down Expand Up @@ -552,6 +574,22 @@ const Description = {
features[i].properties._ || {}
features[i].properties._.id = i
}

// Reapply restrictions in this case
if (geomTypeRestriction) {
features = features.filter((f) => {
return (
geomTypeRestriction ===
f?.geometry?.type
)
})
}

if (hasBounds) {
features = features.filter((f) => {
return booleanIntersects(bounds, f)
})
}
}

if (
Expand Down Expand Up @@ -755,13 +793,15 @@ const Description = {
return
}
if (
!hasBounds &&
Description.navPopoverField === NAV_DEFAULT_FIELD &&
direction === 'previous'
) {
resolve(-1)
return
}
if (
!hasBounds &&
Description.navPopoverField === NAV_DEFAULT_FIELD &&
direction === 'next'
) {
Expand Down

0 comments on commit 34fa2e8

Please sign in to comment.