Skip to content

Commit

Permalink
Merge pull request #1009 from dbauszus-glx/mvt-clear-source
Browse files Browse the repository at this point in the history
mvt clear source and refresh
  • Loading branch information
RobAndrewHurst authored Nov 21, 2023
2 parents 9176a0d + a5ea34e commit b3e97f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/layer/decorate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ export default async layer => {
layer.draw?.defaults || {}))
})

// Check whether feature is loaded on MVT update.
if (layer.format === 'mvt') {

layer.features = []

// Concat layer.features array with features from tileloadend
layer.source.on('tileloadend', concatFeatures);

function concatFeatures(e) {

layer.features = layer.features.concat(e.tile.getFeatures())
}

setTimeout(checkFeature, 1000)

function checkFeature() {

let found = layer.features?.find(F => F.properties?.id === location.id)

if (found) {

layer.source.un('tileloadend', concatFeatures);
} else {

layer.reload()
}
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion lib/layer/format/mvt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default layer => {

layer.reload = () => {

//layer.source.clear()
layer.source.clear()
layer.source.refresh()
layer.tilesLoaded = []
layer.featureSource.refresh()
Expand Down

0 comments on commit b3e97f6

Please sign in to comment.