Skip to content

VectorLayer identify Ignore collided geometry #2446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/geometry/Marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const options: MarkerOptionsType = {
* });
*/
export class Marker extends CenterMixin(Geometry) {
isPoint: boolean
isPoint: boolean;
//@internal Has it already collided
_collided: boolean;
/**
* @param {Coordinate} coordinates - coordinates of the marker
* @param {Object} [options=null] - construct options defined in [Marker]{@link Marker#options}
Expand Down
15 changes: 14 additions & 1 deletion src/layer/VectorLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Painter from '../renderer/geometry/Painter';
import CollectionPainter from '../renderer/geometry/CollectionPainter';
import Coordinate from '../geo/Coordinate';
import Point from '../geo/Point';
import { LineString, Curve } from '../geometry';
import { LineString, Curve, Marker } from '../geometry';
import PointExtent from '../geo/PointExtent';
import { VectorLayerCanvasRenderer } from '../renderer';
import { LayerJSONType } from './Layer';
Expand Down Expand Up @@ -169,6 +169,19 @@ class VectorLayer extends OverlayLayer {
if (!geometries || !geometries.length) {
return [];
}
const filterGeos = [];
let idx = 0;
for (let i = 0, len = geometries.length; i < len; i++) {
const geo = geometries[i];
// Ignore collided Points
if (geo.isPoint && (geo as Marker)._collided === true) {
continue;
}
filterGeos[idx] = geo;
idx++;
}
geometries = filterGeos;

const filter = options['filter'],
hits: Geometry[] = [];
const tolerance = options['tolerance'];
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/layer/vectorlayer/VectorLayerCanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,20 @@ class VectorLayerRenderer extends OverlayLayerCanvasRenderer {
setToRedraw(): this {
super.setToRedraw();
this._resetProgressiveRender();
this._resetGeosCollisionState();
return this;
}

_resetGeosCollisionState() {
const geos = this.layer._geoList || [];
for (let i = 0, len = geos.length; i < len; i++) {
const geo = geos[i];
if (geo.isPoint) {
geo._collided = false;
}
}
}

//@internal
_geoIsCollision(geo: GeoType, collisionIndex: any) {
if (!geo) {
Expand All @@ -99,6 +110,7 @@ class VectorLayerRenderer extends OverlayLayerCanvasRenderer {
geo.bbox[2] = extent.xmax + bufferSize;
geo.bbox[3] = extent.ymax + bufferSize;
if (collisionIndex.collides(geo.bbox)) {
geo._collided = true;
return true;
}
collisionIndex.insertBox(geo.bbox);
Expand Down Expand Up @@ -451,7 +463,7 @@ class VectorLayerRenderer extends OverlayLayerCanvasRenderer {
glScale,
glRes,
//@internal
_2DExtent,
_2DExtent,
glExtent,
containerExtent,
offset
Expand Down
Loading