Skip to content

Commit

Permalink
fix: mvt tile pick fix #2273
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Feb 20, 2024
1 parent c9551aa commit 7a16166
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
14 changes: 9 additions & 5 deletions examples/demos/tile/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { LineLayer, PolygonLayer, Scene, Source } from '@antv/l7';
// @ts-ignore
import * as allMap from '@antv/l7-maps';
import { Protocol } from 'pmtiles';
const protocol = new Protocol();
Scene.addProtocol('pmtiles', protocol.tile);

export function MapRender(option: {
map: string;
Expand Down Expand Up @@ -41,11 +39,17 @@ export function MapRender(option: {
// 绿地
const fill = new PolygonLayer({
sourceLayer: 'CHN_Districts',
featureId:'adcode',
})
.source(source)
.shape('fill')
// .color('#f00');
.color('adcode', getColorByAdcode);

fill.on('click', (e) => {
console.log(e);
});

const line = new LineLayer({
sourceLayer: 'CHN_Districts_L',
})
Expand All @@ -70,9 +74,9 @@ export function MapRender(option: {
.color('#de2d26');

scene.addLayer(fill);
scene.addLayer(line);
scene.addLayer(line2);
scene.addLayer(line3);
// scene.addLayer(line);
// scene.addLayer(line2);
// scene.addLayer(line3);
// scene.addLayer(line2);
// const debugerLayer = new TileDebugLayer({ usage: 'basemap' });
// scene.addLayer(debugerLayer);
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/services/interaction/PickingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,16 @@ export default class PickingService implements IPickingService {
for (const layer of layers
.filter((layer) => layer.needPick(target.type))
.reverse()) {
if (!layer.tileLayer) {
layer.hooks.beforePickingEncode.call();
}
await useFramebufferAsync(this.pickingFBO, async () => {
clear({
framebuffer: this.pickingFBO,
color: [0, 0, 0, 0],
stencil: 0,
depth: 1,
});
// 渲染需要拾取的图层
layer.layerPickService.pickRender(target);
});

if (!layer.tileLayer) {
layer.hooks.afterPickingEncode.call();
}

const isPicked = await this.pickFromPickingFBO(layer, target);
this.layerService.pickedLayerId = isPicked ? +layer.id : -1;
if (isPicked && !layer.getLayerConfig().enablePropagation) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/layer/LayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default class LayerService
public renderTileLayerMask(layer: ILayer) {
let maskindex = 0;
const { enableMask = true } = layer.getLayerConfig();
let maskCount = layer.tileMask ? 1 : 0;
let maskCount = layer.tileMask ? 1 : 0; // 瓦片裁剪 线图层或者面图层
const masklayers = layer.masks.filter((m) => m.inited);

maskCount = maskCount + (enableMask ? masklayers.length : 1);
Expand Down
1 change: 0 additions & 1 deletion packages/layers/src/core/BaseLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}>
this.clearModels();
return this;
}

this.hooks.beforeRender.call();
this.models.forEach((model) => {
model.draw(
Expand Down
3 changes: 3 additions & 0 deletions packages/layers/src/core/LayerPickService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ export default class BaseLayerPickService implements ILayerPickService {
if (layer.tileLayer) {
return layer.tileLayer.pickRender(target);
}
// 渲染瓦片图层的拾取
layer.hooks.beforePickingEncode.call();
layerService.renderTileLayerMask(layer);
layer.renderModels({
ispick: true,
});
layer.hooks.afterPickingEncode.call();
}

public async pick(layer: ILayer, target: IInteractionTarget) {
Expand Down
3 changes: 1 addition & 2 deletions packages/source/src/parser/geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getFeatureID(feature: Feature<Geometries, Properties>, key?: string) {
}

// @ts-ignore
if (typeof feature.properties[key] * 1 === 'number') {
if (typeof (feature.properties[key] * 1) === 'number') {
// @ts-ignore
return feature.properties[key] * 1;
}
Expand Down Expand Up @@ -90,7 +90,6 @@ export default function geoJSON(
if (featureId === null) {
featureId = featureIndex;
}

const sortedID = featureId;

const coord = getCoords(currentFeature);
Expand Down
1 change: 0 additions & 1 deletion packages/source/src/source/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default class VectorSource implements ITileSource {
for (let i = 0; i < vectorTile.length; i++) {
const vectorTileFeature = vectorTile.feature(i);
const feature = vectorTileFeature.toGeoJSON(this.x, this.y, this.z);

features.push({
...feature,
properties: {
Expand Down

0 comments on commit 7a16166

Please sign in to comment.