Skip to content

Commit

Permalink
Fix click on vectortile
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Dec 7, 2023
1 parent 692d025 commit 857606d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
6 changes: 5 additions & 1 deletion src/essence/Basics/Layers_/Layers_.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,11 @@ const L_ = {
let layerUrl = s.url
if (!F_.isUrlAbsolute(layerUrl))
layerUrl = L_.missionPath + layerUrl
if (s.type === 'tile' || s.type === 'data') {
if (
s.type === 'tile' ||
s.type === 'data' ||
s.type === 'vectortile'
) {
// Make sure all tile layers follow z-index order at start instead of element order
L_.layers.layer[s.name].setZIndex(
L_._layersOrdered.length +
Expand Down
54 changes: 28 additions & 26 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ async function makeLayer(layerObj, evenIfOff, forceGeoJSON) {

var vectorTileOptions = {
layerName: layerObj.name,
rendererFactory: L.canvas.tile,
rendererFactory: L.svg.tile,
vectorTileLayerStyles: layerObj.style.vtLayer || {},
interactive: true,
minZoom: layerObj.minZoom,
Expand All @@ -975,8 +975,8 @@ async function makeLayer(layerObj, evenIfOff, forceGeoJSON) {

L_.layers.layer[layerObj.name] = L.vectorGrid
.protobuf(layerUrl, vectorTileOptions)
.on('click', function (e) {
let layerName = e.sourceTarget._layerName
.on('click', function (e, b, x) {
let layerName = e.target.options.layerName
let vtId = L_.layers.layer[layerName].vtId
clearHighlight()
L_.layers.layer[layerName].highlight = e.layer.properties[vtId]
Expand All @@ -1001,36 +1001,38 @@ async function makeLayer(layerObj, evenIfOff, forceGeoJSON) {
geometry: {},
})

Map_.activeLayer = e.sourceTarget._layer
Map_.activeLayer = e.layer
if (Map_.activeLayer) L_.Map_._justSetActiveLayer = true

let p = e.sourceTarget._point

for (var i in e.layer._renderer._features) {
if (
e.layer._renderer._features[i].feature._pxBounds.min
.x <= p.x &&
e.layer._renderer._features[i].feature._pxBounds.max
.x >= p.x &&
e.layer._renderer._features[i].feature._pxBounds.min
.y <= p.y &&
e.layer._renderer._features[i].feature._pxBounds.max
.y >= p.y &&
e.layer._renderer._features[i].feature.properties[
vtId
] != e.layer.properties[vtId]
) {
L_.layers.layer[layerName].activeFeatures.push({
type: 'Feature',
properties:
e.layer._renderer._features[i].feature
.properties,
geometry: {},
})
if (p) {
for (var i in e.layer._renderer._features) {
if (
e.layer._renderer._features[i].feature._pxBounds.min
.x <= p.x &&
e.layer._renderer._features[i].feature._pxBounds.max
.x >= p.x &&
e.layer._renderer._features[i].feature._pxBounds.min
.y <= p.y &&
e.layer._renderer._features[i].feature._pxBounds.max
.y >= p.y &&
e.layer._renderer._features[i].feature.properties[
vtId
] != e.layer.properties[vtId]
) {
L_.layers.layer[layerName].activeFeatures.push({
type: 'Feature',
properties:
e.layer._renderer._features[i].feature
.properties,
geometry: {},
})
}
}
}

timedSelect(e.sourceTarget._layer, layerName, e)
timedSelect(e.layer, layerName, e)

L.DomEvent.stop(e)
})
Expand Down

0 comments on commit 857606d

Please sign in to comment.