Skip to content

Commit

Permalink
expose mvt datasource layer via properties.$layer
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Nov 21, 2023
1 parent 67ef589 commit 7567a96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
15 changes: 9 additions & 6 deletions packages/core/src/providers/MVTProvider/MVTProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
* License-Filename: LICENSE
*/

import {JSUtils, Queue} from '@here/xyz-maps-common';
import MVTTileLoader from '../../loaders/MVT/MVTLoader';
import {Feature} from '../../features/Feature';
import {GeoJSONGeometryType} from '../../features/GeoJSON';

import mvtToGeoJSON from './toGeojson';
import {JSUtils, Queue} from '@here/xyz-maps-common';

import {MVTTile} from './MVTTile';
import {RemoteTileProvider} from '../RemoteTileProvider/RemoteTileProvider';
import {HTTPLoader} from '../../loaders/HTTPLoader'; // => no global tree (tile-tree)!
// import GeoJsonProvider from '../GeoJSONProvider'; // global tree!

import {HTTPLoader} from '../../loaders/HTTPLoader';

class MvtFeature extends Feature {
geometry: { type: GeoJSONGeometryType, coordinates: any[], __xyz: any };
Expand All @@ -54,6 +50,13 @@ export class MVTProvider extends RemoteTileProvider {
'Feature': MvtFeature,
'preProcessor': mvtToGeoJSON
}, config));

// this.__s = this._s;
//
// this._s = function(bbox) {
// debugger;
// return this.__s(bbox);
// };
};

decCoord(feature) {
Expand Down
51 changes: 16 additions & 35 deletions packages/core/src/providers/MVTProvider/toGeojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ interface GeoJsonFeature {
bbox?: number[];
geometry: {
type: string,
coordinates: any[]
coordinates: any[];
_xyz?: any;
}
properties?: {}
properties?: {[name:string]: any}
}

function classifyRings(rings) {
Expand Down Expand Up @@ -222,17 +223,10 @@ const decodeBBox = (vtFeature, x, y, z) => {
// window.tt = 0;

function vtFeatureToGeoJSON(vtFeature, xyz, includeBBox) {
// let s = performance.now();

const geom = decodeBBox(vtFeature, xyz.x, xyz.y, xyz.z);
// const geom = decodeGeometry(vtFeature, x, y, z, includeBBox);
// geom.type = geom.geometry.type;

// window.tt += performance.now() - s;

const result: GeoJsonFeature = {
type: 'Feature',
// geometry: geom.geometry,
geometry: new FeatureGeometry(geom.type, vtFeature, xyz),
properties: vtFeature.properties
};
Expand Down Expand Up @@ -291,15 +285,12 @@ class FeatureGeometry {
}
}

// @
// window.mvtDecodeTime = 0;

export default function mvtPreProcessor(prep) {
taskManager.create({

init: function() {
const layers = [];
let mvt = new VectorTile(new Protobuf(prep.data.mvt));
const mvt = new VectorTile(new Protobuf(prep.data.mvt));
const {tile} = prep;

for (var l in mvt.layers) {
Expand All @@ -311,7 +302,7 @@ export default function mvtPreProcessor(prep) {
y: tile.y,
z: tile.z
},
mvt: mvt,
mvt,
xyzLayers: prep.data.xyz,
layers: layers,
l: 0,
Expand All @@ -324,39 +315,29 @@ export default function mvtPreProcessor(prep) {

exec: function(data) {
let {mvt, xyz, layers, xyzLayers, l, f, geojson} = data;
let layer;
let feature;
let geom;
let _xyz;

while (l < layers.length) {
layer = mvt.layers[layers[l]];
let mvtLayer = mvt.layers[layers[l]];
let xyzLayer = xyzLayers[l];
let mvtLayerName = mvtLayer.name;
// const mvtNs = {layer: layer.name};
_xyz = {x: xyz.x, y: xyz.y, z: xyz.z, l: layer.name};
let _xyz = {x: xyz.x, y: xyz.y, z: xyz.z, l: mvtLayerName};

while (f < layer.length) {
while (f < mvtLayer.length) {
// feature = layer.feature(f++).toGeoJSON( x, y, z );

feature = vtFeatureToGeoJSON(layer.feature(f), _xyz, true);

geom = feature.geometry.type;
let feature = vtFeatureToGeoJSON(mvtLayer.feature(f), _xyz, true);
let geom = feature.geometry.type;

if (geom == 'MultiPolygon' || geom == 'Polygon') {
let xyzFeature = xyzLayers[l] && xyzLayers[l].features[f];
if (xyzFeature) {
feature.geometry._xyz = xyzFeature;
} else {
debugger;
}
feature.geometry._xyz = xyzLayer?.features[f];
}
// feature.id = /*feature.id ||*/ Math.random();

feature.id = ++guid;
f++;

if (feature.properties.layer == UNDEF) {
feature.properties.layer = layer.name;
}
feature.properties.layer ??= mvtLayer.name;
feature.properties.$layer ??= mvtLayer.name;

// feature.properties['@ns:com:here:mvt'] = mvtNs;

geojson.push(feature);
Expand Down

0 comments on commit 7567a96

Please sign in to comment.