Skip to content

Commit

Permalink
minor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jul 9, 2019
1 parent 8be1ea0 commit bbc5cbf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/data/feature_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import vt from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import GeoJSONFeature from '../util/vectortile_to_geojson';
import { arraysIntersect } from '../util/util';
import deriveIntegerId from '../util/derive_integer_id';
import { setIntegerId } from '../util/integer_id';
import { OverscaledTileID } from '../source/tile_id';
import { register } from '../util/web_worker_transfer';
import EvaluationParameters from '../style/evaluation_parameters';
Expand Down Expand Up @@ -202,7 +202,7 @@ class FeatureIndex {
}

if (this.deriveIntegerId) {
deriveIntegerId(feature, this.deriveIntegerId);
setIntegerId(feature, this.deriveIntegerId);
}

const geojsonFeature = new GeoJSONFeature(feature, this.z, this.x, this.y);
Expand Down
4 changes: 2 additions & 2 deletions src/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LineBucket from '../data/bucket/line_bucket';
import FillBucket from '../data/bucket/fill_bucket';
import FillExtrusionBucket from '../data/bucket/fill_extrusion_bucket';
import { warnOnce, mapObject, values } from '../util/util';
import deriveIntegerId from '../util/derive_integer_id';
import { setIntegerId } from '../util/integer_id';
import assert from 'assert';
import ImageAtlas from '../render/image_atlas';
import GlyphAtlas from '../render/glyph_atlas';
Expand Down Expand Up @@ -99,7 +99,7 @@ class WorkerTile {
for (let index = 0; index < sourceLayer.length; index++) {
const feature = sourceLayer.feature(index);
if (this.deriveIntegerId) {
deriveIntegerId(feature, this.deriveIntegerId);
setIntegerId(feature, this.deriveIntegerId);
}
features.push({ feature, index, sourceLayerIndex });
}
Expand Down
14 changes: 0 additions & 14 deletions src/util/derive_integer_id.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/util/integer_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow

import murmur3 from 'murmurhash-js';

export function setIntegerId(feature: VectorTileFeature, key: string) {
const value = feature.properties[key];
if (value !== undefined) {
feature.id = getIntegerId(value);
}
}

export function getIntegerId(value: mixed) {
const numValue = +value;
if (!isNaN(numValue) && numValue % 1 === 0) {
return numValue;
}
return murmur3(String(value));
}

0 comments on commit bbc5cbf

Please sign in to comment.