Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove mvt_cache reference; create mvt query #1013

Merged
merged 9 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -64,8 +61,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 @@ -126,30 +121,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/location/delete?` +
mapp.utils.paramString({
locale: this.layer.mapview.locale.key,
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.

5 changes: 5 additions & 0 deletions mod/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ module.exports = async (req, res) => {
return res.send(rows.map(row=>Object.values(row)))
}

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