From 8c37a9babcb668a4f7fa17da557e3f246544a5b3 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Tue, 29 Oct 2024 16:20:35 +0000 Subject: [PATCH 1/2] MVT reload doesn't refresh source --- lib/layer/format/mvt.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/layer/format/mvt.mjs b/lib/layer/format/mvt.mjs index b6aa30ab8..429992eaf 100644 --- a/lib/layer/format/mvt.mjs +++ b/lib/layer/format/mvt.mjs @@ -88,6 +88,9 @@ export default function MVT(layer) { layer.source.clear() layer.source.refresh() + + // Reset source tiles to force refresh. + layer.source.sourceTiles_ = {}; layer.featureSource.refresh() if (callback instanceof Function) callback(layer) @@ -108,7 +111,7 @@ export default function MVT(layer) { layer.source = new ol.source.VectorTile({ format: new ol.format.MVT(), transition: layer.transition, - cacheSize: layer.cacheSize + cacheSize: layer.cacheSize || 0 }) // Assign wkt properties load method. From 3f8d99209c992a8737b358a99ad421a6a0849c17 Mon Sep 17 00:00:00 2001 From: Robert Hurst Date: Wed, 30 Oct 2024 11:10:44 +0200 Subject: [PATCH 2/2] Update tests --- tests/lib/layer/format/_format.test.mjs | 4 +- tests/lib/layer/format/mvt.test.mjs | 167 ++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 tests/lib/layer/format/mvt.test.mjs diff --git a/tests/lib/layer/format/_format.test.mjs b/tests/lib/layer/format/_format.test.mjs index 74ee052f3..c0810a05f 100644 --- a/tests/lib/layer/format/_format.test.mjs +++ b/tests/lib/layer/format/_format.test.mjs @@ -1,5 +1,7 @@ import { vectorTest } from './vector.test.mjs'; +import { mvtTest } from './mvt.test.mjs'; export const formatTest = { - vectorTest + vectorTest, + mvtTest } \ No newline at end of file diff --git a/tests/lib/layer/format/mvt.test.mjs b/tests/lib/layer/format/mvt.test.mjs new file mode 100644 index 000000000..305b91d91 --- /dev/null +++ b/tests/lib/layer/format/mvt.test.mjs @@ -0,0 +1,167 @@ +export function mvtTest() { + codi.describe('Layer Format: MVT', () => { + const mvt_layer = { + 'group': 'layer', + 'name': 'mvt_test', + 'format': 'mvt', + 'table': 'test.mvt_test', + 'geom': 'geom_3857', + 'srid': '3857', + 'qID': 'id', + 'infoj': [ + { + 'type': 'pin', + 'label': 'ST_PointOnSurface', + 'field': 'pin', + 'fieldfx': 'ARRAY[ST_X(ST_PointOnSurface(geom_3857)),ST_Y(ST_PointOnSurface(geom_3857))]' + } + ], + 'style': { + 'default': { + 'strokeWidth': '0', + 'fillColor': '#fff', + 'fillOpacity': 0.4, + 'strokeColor': null + }, + 'themes': { + 'theme_1': { + 'title': 'theme_1', + 'type': 'categorized', + 'field': 'numeric_field', + 'cat': { + '1': { + 'label': 'Lowest', + 'style': { + 'fillColor': '#3193ED' + } + }, + '2': { + 'label': '-', + 'style': { + 'fillColor': '#5DC29A' + } + }, + '3': { + 'label': '-', + 'style': { + 'fillColor': '#8FE15A' + } + }, + '4': { + 'label': '-', + 'style': { + 'fillColor': '#D8D758' + } + }, + '5': { + 'label': '-', + 'style': { + 'fillColor': '#FFB956' + } + }, + '6': { + 'label': '-', + 'style': { + 'fillColor': '#FE8355' + } + }, + '7': { + 'label': '-', + 'style': { + 'fillColor': '#FA5652' + } + }, + '8': { + 'label': 'Highest', + 'style': { + 'fillColor': '#F0304D' + } + } + } + }, + 'theme_2': { + 'title': 'theme_2', + 'type': 'categorized', + 'field': 'numeric_field', + 'cat': { + '1': { + 'label': 'Lowest', + 'style': { + 'fillColor': '#6B2E94' + } + }, + '2': { + 'label': '-', + 'style': { + 'fillColor': '#8B44B8' + } + }, + '3': { + 'label': '-', + 'style': { + 'fillColor': '#9B6FCD' + } + }, + '4': { + 'label': '-', + 'style': { + 'fillColor': '#89A7D6' + } + }, + '5': { + 'label': '-', + 'style': { + 'fillColor': '#70C1C9' + } + }, + '6': { + 'label': '-', + 'style': { + 'fillColor': '#52C4A3' + } + }, + '7': { + 'label': '-', + 'style': { + 'fillColor': '#38B77C' + } + }, + '8': { + 'label': 'Highest', + 'style': { + 'fillColor': '#1FA855' + } + } + } + } + } + } + + } + + /** + * @description MVT: Create basic layer + * @function it + */ + codi.it('MVT: Create basic layer', () => { + mapp.layer.formats[mvt_layer.format]?.(mvt_layer); + + codi.assertTrue(Object.hasOwn(mvt_layer, 'reload'), 'The mvt layer needs to have a reload function') + codi.assertTrue(Object.hasOwn(mvt_layer, 'featureSource'), 'The mvt layer needs to have a featureSource') + codi.assertTrue(Object.hasOwn(mvt_layer, 'source'), 'The mvt layer needs to have a source') + codi.assertTrue(Object.hasOwn(mvt_layer, 'L'), 'The mvt layer needs to have an openlayer object') + }); + + /** + * @description MVT: Reload should remove sourceTiles + * @function it + */ + codi.it('MVT: Reload should remove sourceTiles', () => { + mapp.layer.formats[mvt_layer.format]?.(mvt_layer); + + mvt_layer.source.sourceTiles_ = { tile: 'foo' }; + mvt_layer.reload(); + codi.assertEqual(mvt_layer.source.sourceTiles_, {}, 'The sourceTiles needs to be cleared'); + }); + }); +} \ No newline at end of file