Skip to content

Commit

Permalink
the feature store has been redone.
Browse files Browse the repository at this point in the history
fixed potential issue when data providers receive remote data that's outside of the actual requested bounds.
speedup provider.all()

Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Feb 15, 2024
1 parent 5c6c3ad commit eb2e075
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 147 deletions.
57 changes: 53 additions & 4 deletions packages/core/src/features/RTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,73 @@

import RBush from 'rbush/rbush.min.js';
import {Feature} from './Feature';
import {GeoJSONFeature} from '@here/xyz-maps-core';

type BBox = {
minX: number,
maxX: number,
minY: number,
maxY: number
};


interface FeatureIndex {
clear();
}


class RTree extends RBush {
constructor(d:number) {
constructor(d: number) {
super(d);
}

toBBox(feature: Feature) {
toBBox(feature: GeoJSONFeature): BBox {
const {bbox} = feature;
return {minX: bbox[0], minY: bbox[1], maxX: bbox[2], maxY: bbox[3]};
}

compareMinX(feature1: Feature, feature2: Feature): number {
compareMinX(feature1: GeoJSONFeature, feature2: GeoJSONFeature): number {
return feature1.bbox[0] - feature2.bbox[0];
}

compareMinY(feature1: Feature, feature2: Feature): number {
compareMinY(feature1: GeoJSONFeature, feature2: GeoJSONFeature): number {
return feature1.bbox[1] - feature2.bbox[1];
}

import(data) {
super.fromJSON(data);
}

load?(features: GeoJSONFeature[]): void;

insert?(feature: GeoJSONFeature);

remove?(feature: GeoJSONFeature);

search?(bbox: BBox): GeoJSONFeature[];

clear?(): void;

all?(): GeoJSONFeature[];

// load(features: GeoJSONFeature[]) {
// return super.load(features);
// }
//
// insert(feature: GeoJSONFeature) {
// return super.insert(feature);
// }
//
// remove(feature: GeoJSONFeature) {
// return super.remove(feature);
// }
//
// search(bbox: BBox) {
// return super.propertyIsEnumerable(bbox);
// }
// clear() {
// super.clear();
// }
}

export default RTree;
6 changes: 3 additions & 3 deletions packages/core/src/features/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import {Feature} from '../features/Feature';
import {GeoJSONCoordinate} from '@here/xyz-maps-core';
import {GeoJSONCoordinate, GeoJSONFeature} from '@here/xyz-maps-core';
type Point = number[];
type BBox = number[];
type Coordinates = Array<Point>;
Expand Down Expand Up @@ -56,11 +56,11 @@ const updateLineStringBBox = (lineString: Coordinates, bbox?: BBox) => {
}
};

const calcBBox = (feature: Feature, bbox?: BBox): BBox | false => {
const calcBBox = (feature: GeoJSONFeature, bbox?: BBox): BBox | false => {
const geoType = feature.geometry.type;

if (geoType == 'Point') {
const coordinates = (<Feature<'Point'>>feature).geometry.coordinates;
const coordinates = (feature as GeoJSONFeature<'Point'>).geometry.coordinates;
if (bbox) {
updatePointBBox(<[number, number]>coordinates, bbox);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/providers/EditableFeatureProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ export abstract class EditableFeatureProvider extends FeatureTileProvider {
}
};

_insert(o, tile?) {
_insert(o) {
if (this.blocked[o.id]) {
return null;
}
return super._insert(o, tile);
return super._insert(o);
};

reserveId(createdFeatures, cb) {
Expand Down
Loading

0 comments on commit eb2e075

Please sign in to comment.