Skip to content

Commit

Permalink
Merge branch 'main' into template-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Nov 3, 2023
2 parents 85cb4af + fd75ac6 commit aaee50c
Show file tree
Hide file tree
Showing 22 changed files with 496 additions and 427 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ jobs:
name: Build & Run Tests
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: '18'

- name: Install Dependencies
run: npm install
Expand Down
7 changes: 0 additions & 7 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ module.exports = async (req, res) => {
// Assign from _template if provided as path param.
req.params.template ??= req.params._template

// Decode string params.
Object.entries(req.params)
.filter(entry => typeof entry[1] === 'string')
.forEach(entry => {
req.params[entry[0]] = decodeURIComponent(entry[1])
})

// Short circuit login view or post request.
if (req.params.login || req.body && req.body.login) return login(req, res)

Expand Down
75 changes: 47 additions & 28 deletions lib/layer/decorate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default async layer => {
zoomToExtent,
});

// Warn if outdated layer.edit configuration is used.
if (layer.edit) {
console.warn(`Layer: ${layer.key}, please update edit:{} to use draw:{} as layer.edit has been superseeded with layer.draw to be in line with the OL drawing interaction.`)
layer.draw = Object.assign(layer.draw || {}, layer.edit)
Expand All @@ -22,15 +23,18 @@ export default async layer => {
// Layer must have an empty draw config to allow for role based assignment of drawing methods.
layer.draw ??= {}

// Warn if outdated layer.draw.delete configuration is used.
if (layer.draw?.delete) {
console.warn(`Layer: ${layer.key}, please move draw.delete to use layer.deleteLocation:true.`)
}

// Callback which creates and stores a location from a feature returned by the drawing interaction.
layer.draw.callback = async (feature, params) => {

// If the feature is null, return.
if (!feature) return;

// Get the current table and set new to true.
const location = {
layer,
table: layer.tableCurrent(),
Expand All @@ -56,7 +60,8 @@ export default async layer => {
layer.draw?.defaults || {}))
})

//layer.reload()
// Layer must be reloaded to reflect geometry changes.
layer.reload()

// Get the newly created location.
mapp.location.get(location)
Expand All @@ -70,6 +75,20 @@ export default async layer => {
// Set layer opacity from style.
layer.L.setOpacity(layer.style?.opacity || 1);

// Layer style has multiple hovers and a single hover (incorrect configuration)
if (layer.style?.hovers && layer.style?.hover) {

console.warn(`Layer: ${layer.key}, cannot use both layer.style.hover and layer.style.hovers. Layer.style.hover has been deleted.`)
delete layer.style.hover;
}

// Layer style has multiple labels and a single label (incorrect configuration)
if (layer.style?.labels && layer.style?.label) {

console.warn(`Layer: ${layer.key}, cannot use both layer.style.label and layer.style.labels. Layer.style.label has been deleted.`)
delete layer.style.label;
}

// Layer style has multiple themes.
if (layer.style?.themes) {

Expand All @@ -80,24 +99,31 @@ export default async layer => {
: layer.style.themes[layer.style.theme || Object.keys(layer.style.themes)[0]];
}

// If setLabel is included and labels object exists.
if (layer.style?.theme?.setLabel && layer.style?.labels) {

// Swap the label based on the setLabel key.
layer.style.label = layer.style.labels[layer.style.theme.setLabel]
}

if (layer.style?.theme?.setHover && layer.style?.hovers) {

layer.style.hover = layer.style.hovers[layer.style.theme.setHover]
}

// Warn if outdated layer.hover configuration is used.
// Set layer.style.hover and remove layer.hover.
if (layer.hover) {

console.warn(`Layer: ${layer.key}, layer.hover{} should be defined within layer.style{}.`)
layer.style.hover = layer.hover;
delete layer.hover;
}

// Layer style has multiple themes.
// If setHover is included and hovers object exists.
if (layer.style?.theme?.setHover && layer.style?.hovers) {

// Swap the hover based on the setHover key.
layer.style.hover = layer.style.hovers[layer.style.theme.setHover]
}


// Layer style has multiple hovers
if (layer.style?.hovers) {

// Keep object hover.
Expand All @@ -113,7 +139,7 @@ export default async layer => {
layer.style.hover.method ??= mapp.layer.featureHover;
}

// Layer style has multiple themes.
// Layer style has multiple labels.
if (layer.style?.labels) {

// Keep object label.
Expand All @@ -131,7 +157,7 @@ export default async layer => {

// Check if the role is an object and not null
if (layer.roles[role] !== null && typeof layer.roles[role] === 'object') {

// Extract the role name from negated roles (e.g., "!role" becomes "role")
const negatedRole = role.match(/(?<=^!)(.*)/g)?.[0];

Expand Down Expand Up @@ -191,13 +217,12 @@ export default async layer => {
}

function show() {
/**
* Reveals the layer
*/

// Show the layer
this.display = true;

try { // Add layer to map
try {
// Add layer to map
this.mapview.Map.addLayer(this.L);
} catch {
// Will catch assertation error when layer is already added.
Expand All @@ -217,10 +242,8 @@ function show() {
}

function hide() {
/**
* Hides the layer
*/

// Hide the layer.
this.display = false;

// Remove OL layer from mapview.
Expand All @@ -237,9 +260,8 @@ function hide() {
}

function tableCurrent() {
/**
* Returns the current table
*/

// Return the current table if it exists.

// A layer must have either a table or tables configuration.
if (!this.tables) return this.table;
Expand Down Expand Up @@ -269,9 +291,8 @@ function tableCurrent() {
}

function tableMax() {
/**
* Returns the max table
*/

// Returns the max table

// A layer must have either a table or tables configuration.
if (!this.tables) return this.table;
Expand All @@ -281,9 +302,8 @@ function tableMax() {
}

function tableMin() {
/**
* Returns the min table
*/

// Returns the min table.

// A layer must have either a table or tables configuration.
if (!this.tables) return this.table;
Expand All @@ -293,9 +313,8 @@ function tableMin() {
}

async function zoomToExtent(params) {
/**
* Zooms to a specific extent
*/

// Zooms to a specific extent

// XMLHttpRequest to layer extent endpoint
let response = await mapp.utils.xhr(`${this.mapview.host}/api/query/layer_extent?` +
Expand Down
27 changes: 15 additions & 12 deletions lib/layer/featureHover.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export default function (feature, layer) {
// The hover method must only execute if the display flag is set.
if (!layer.style.hover.display) return;

if (!layer.mapview.interaction.current) return;
// Store current highlight (feature) key.
const featureKey = layer.mapview.interaction?.current?.key?.toString()

// Store current highlight key.
let key = layer.mapview.interaction.current.key.toString()
if (!featureKey) return;

let paramString = mapp.utils.paramString({
const paramString = mapp.utils.paramString({
dbs: layer.dbs,
locale: layer.mapview.locale.key,
layer: layer.key,
Expand All @@ -29,20 +29,23 @@ export default function (feature, layer) {
mapp.utils.xhr(`${layer.mapview.host}/api/query?${paramString}`)
.then(response => {

// Check whether highlight feature is still current.
if (layer.mapview.interaction?.current?.key !== key) return;

// Check whether cursor has position (in map).
if (!layer.mapview.position) return;

// Check whether there is a response to display.
if (!response) return;

if (typeof layer.style.hover.render === 'function') {

const content = layer.style.hover.render(response)
layer.mapview.infotip(content)
return;
}

// Check whether the response label field has a value.
if (response.label == '') return;
if (response.label == '') return;

// Check whether highlight feature is still current.
if (layer.mapview.interaction?.current?.key !== featureKey) return;

// Display the response label as infotip.
layer.mapview.infotip(response.label)
})

}
3 changes: 2 additions & 1 deletion lib/layer/format/_format.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export default {
mvt,
cluster: vector,
geojson: vector,
wkt: vector
wkt: vector,
vector
}
Loading

0 comments on commit aaee50c

Please sign in to comment.