Skip to content

Commit

Permalink
merge mvt query
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Nov 22, 2023
2 parents e1e20ec + 60f11fc commit 9f1420a
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 280 deletions.
6 changes: 0 additions & 6 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const auth = require('../mod/user/auth')
const saml = process.env.SAML_ENTITY_ID && require('../mod/user/saml')

const routes = {
mvt: require('../mod/mvt'),
location: require('../mod/location/_location'),
provider: require('../mod/provider/_provider'),
query: require('../mod/query'),
Expand Down Expand Up @@ -172,11 +171,6 @@ module.exports = async (req, res) => {
return login(req, res)
}

// Layer route
if (req.url.match(/(?<=\/api\/layer)/)) {
return routes.mvt(req, res)
}

// Location route
if (req.url.match(/(?<=\/api\/location)/)) {
return routes.location(req, res)
Expand Down
3 changes: 0 additions & 3 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ app.post(`${process.env.DIR||''}/api/fetch/:template?`, express.json({limit: '5m
app.get(`${process.env.DIR||''}/api/workspace/:key?`, api)


app.get(`${process.env.DIR||''}/api/layer/:format?/:z?/:x?/:y?`, api)


app.get(`${process.env.DIR||''}/api/location/:method?`, api)

app.post(`${process.env.DIR||''}/api/location/:method?`, express.json({limit: '5mb'}), api)
Expand Down
10 changes: 7 additions & 3 deletions lib/layer/Style.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export default layer => {

return function Style(feature) {

// Check for and return existing Styles object.
const Styles = feature.get('Styles')
if (Styles) return Styles
if (layer.style.cache !== null) {

// Check for and return existing Styles object.
const Styles = feature.get('Styles')

if (Styles) return Styles
}

feature.properties = feature.getProperties()

Expand Down
30 changes: 27 additions & 3 deletions lib/layer/format/mvt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ export default layer => {
// Assign empty style object if nullish.
layer.style ??= {}

// Set default layer params if nullish.
layer.params ??= {}

if (layer.mvt_cache) {

console.warn(`Layer ${layer.key} mvt_cache has been disabled.`)
}

// MVT query must not have a viewport, this is defined by the tile extent.
delete layer.params.viewport

layer.reload = () => {

layer.source.clear()
Expand Down Expand Up @@ -42,13 +53,26 @@ export default layer => {

if ((!tableZ || !layer.display) && !layer.clones?.size) return layer.source.clear()

const url = `${layer.mapview.host}/api/layer/mvt/${tileCoord[0]}/${tileCoord[1]}/${tileCoord[2]}?` + mapp.utils.paramString({
// Create a set of feature properties for styling.
layer.params.fields = [...new Set([
Array.isArray(layer.style.theme?.fields) ?
layer.style.theme.fields : layer.style.theme?.field,
layer.style.theme?.field,
layer.style.label?.field
].flat().filter(field => !!field))]

const url = `${layer.mapview.host}/api/query?${mapp.utils.paramString({
template: 'mvt',
z: tileCoord[0],
x: tileCoord[1],
y: tileCoord[2],
locale: layer.mapview.locale.key,
layer: layer.key,
srid: layer.mapview.srid,
table: tableZ,
filter: layer.filter?.current
})
filter: layer.filter?.current,
...layer.params
})}`

return url
}
Expand Down
4 changes: 2 additions & 2 deletions lib/layer/format/vector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default layer => {

// Create a set of feature properties for styling.
layer.params.fields = [...new Set([
// Array.isArray(layer.style.theme?.fields) ?
// layer.style.theme.fields : layer.style.theme?.field,
Array.isArray(layer.style.theme?.fields) ?
layer.style.theme.fields : layer.style.theme?.field,
layer.style.theme?.field,
layer.style.label?.field,
layer.cluster?.label
Expand Down
25 changes: 0 additions & 25 deletions lib/location/decorate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default location => {
trash,
update,
syncFields,
mvt_cache,
updateCallbacks: [],
})

Expand Down Expand Up @@ -49,8 +48,6 @@ async function update() {

if (!Object.keys(newValues).length) return;

await this.mvt_cache()

await mapp.utils.xhr({
method: 'POST',
url:
Expand All @@ -65,8 +62,6 @@ async function update() {
body: JSON.stringify(newValues),
});

await this.mvt_cache()

// Update entry.values with newValues.
// Return dependents from updated entries.
const dependents = this.infoj
Expand Down Expand Up @@ -127,30 +122,10 @@ function flyTo (maxZoom) {
});
}

async function mvt_cache() {

if (!this.layer?.mvt_cache) return;

await mapp.utils.xhr(`${this.layer.mapview.host}/api/query?` +
mapp.utils.paramString({
template: 'mvt_cache_delete_intersects',
locale: this.layer.mapview.locale.key,
layer: this.layer.key,
mvt_cache: this.layer.mvt_cache,
table: this.table,
qID: this.layer.qID,
id: this.id,
geom: this.layer.geom
}))
}

async function trash() {

if(!confirm(mapp.dictionary.confirm_delete)) return;

// Must clear cache before removing location from source.
await this.mvt_cache()

await mapp.utils.xhr(`${this.layer.mapview.host}/api/query?` +
mapp.utils.paramString({
template: 'location_delete',
Expand Down
2 changes: 0 additions & 2 deletions lib/location/get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export default async function (location, list = location.layer.mapview.locations

mapp.location.decorate(Object.assign(location, { infoj }))

location.new && await location.mvt_cache()

// Assign location to mapview.
list[location.hook] = location

Expand Down
194 changes: 0 additions & 194 deletions mod/mvt.js

This file was deleted.

4 changes: 2 additions & 2 deletions mod/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ module.exports = async (req, res) => {
}

if (req.params.value_only || template?.value_only) {

return res.send(Object.values(rows[0])[0])
}
}

// Send the infoj object with values back to the client.
res.send(rows.length === 1 && rows[0] || rows)
Expand Down
8 changes: 4 additions & 4 deletions mod/workspace/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ module.exports = () => {
return cache
}

const view_templates = require('./templates/views')
const view_templates = require('./templates/_views')

const mail_templates = require('./templates/mails')
const mail_templates = require('./templates/_mails')

const msg_templates = require('./templates/msgs')
const msg_templates = require('./templates/_msgs')

const query_templates = require('./templates/queries')
const query_templates = require('./templates/_queries')

async function cacheWorkspace() {

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9f1420a

Please sign in to comment.