Move some css rules around, add hash and geometry.type to css classlist

This commit is contained in:
Bryan Housel
2018-08-24 10:39:03 -04:00
parent b0f86cdf31
commit 48e233e4a3
5 changed files with 166 additions and 153 deletions
+2 -4
View File
@@ -37,9 +37,6 @@ function vtToGeoJSON(data, tile, mergeCache) {
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i).toGeoJSON(tile.xyz[0], tile.xyz[1], tile.xyz[2]);
var geometry = feature.geometry;
if (layers.length > 1) {
feature.properties.vt_layer = layerID;
}
// Treat all Polygons as MultiPolygons
if (geometry.type === 'Polygon') {
@@ -59,9 +56,10 @@ function vtToGeoJSON(data, tile, mergeCache) {
if (!feature.geometry.coordinates[0].length) continue; // not actually on this tile
}
// force some unique id generation
// Generate some unique IDs and add some metadata
var featurehash = utilHashcode(stringify(feature));
var propertyhash = utilHashcode(stringify(feature.properties || {}));
feature.__layerID__ = layerID.replace(/[^_a-zA-Z0-9\-]/g, '_');
feature.__featurehash__ = featurehash;
feature.__propertyhash__ = propertyhash;
features.push(feature);
+11 -2
View File
@@ -151,6 +151,15 @@ export function svgData(projection, context, dispatch) {
}
function featureClasses(d) {
return [
'data' + d.__featurehash__,
d.geometry.type,
d.__layerID__ || ''
].join(' ');
}
function drawData(selection) {
var vtService = getService();
var getPath = svgPath(projection).geojson;
@@ -190,7 +199,7 @@ export function svgData(projection, context, dispatch) {
// enter/update
paths = paths.enter()
.append('path')
.attr('class', 'pathdata')
.attr('class', function(d) { return 'pathdata ' + featureClasses(d); })
.merge(paths)
.attr('d', getPath);
@@ -216,7 +225,7 @@ export function svgData(projection, context, dispatch) {
// enter/update
labels = labels.enter()
.append('text')
.attr('class', textClass)
.attr('class', function(d) { return textClass + ' ' + featureClasses(d); })
.merge(labels)
.text(function(d) {
return d.properties.desc || d.properties.name;