Skip to content

Commit f3a2ad9

Browse files
committed
MultiPoint support
- support for MultiPoint features (MultiLineString and MultiPolygon features were and are working as expected - report any issues you might encounter) - reworked feature styling process: -- now is a switch -- added an error message if feature type is unknown
1 parent d36bd9d commit f3a2ad9

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

leaflet-dataclassification.js

+43-24
Original file line numberDiff line numberDiff line change
@@ -1164,32 +1164,51 @@ L.DataClassification = L.GeoJSON.extend({
11641164
// apply symbology to features
11651165
this.eachLayer(function(layer) {
11661166
if (layer.feature.properties[this._field] == null && nodataignore) {
1167-
layer.remove()
1167+
layer.remove();
11681168
} else {
1169-
if (layer.feature.geometry.type == "Point" || layer.feature.geometry.type == "MultiPoint") {
1170-
var coords = layer.feature.geometry.coordinates;
1171-
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
1172-
style.shape = ps;
1173-
1174-
const svgIcon = L.divIcon({
1175-
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
1176-
className: "",
1177-
iconSize: [25, 25],
1178-
iconAnchor: [17, 25/2],
1179-
});
1180-
layer.setIcon(svgIcon);
1181-
}
1182-
if (layer.feature.geometry.type == "LineString" || layer.feature.geometry.type == "MultiLineString") {
1183-
layer.setStyle((mode_line == "width" ? styleLine_width(layer.feature.properties[this._field]) : styleLine_color(layer.feature.properties[this._field])))/*.addTo(map)*/;
1169+
switch (layer.feature.geometry.type) {
1170+
case "Point":
1171+
var coords = layer.feature.geometry.coordinates;
1172+
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
1173+
style.shape = ps;
1174+
1175+
const svgIcon = L.divIcon({
1176+
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
1177+
className: "",
1178+
iconSize: [25, 25],
1179+
iconAnchor: [17, 25/2],
1180+
});
1181+
layer.setIcon(svgIcon);
1182+
break;
1183+
case "MultiPoint":
1184+
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
1185+
var mpfeatures = layer._layers;
1186+
for (const property in mpfeatures) {
1187+
mpfeatures[property].setIcon(L.divIcon({
1188+
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
1189+
className: "",
1190+
iconSize: [25, 25],
1191+
iconAnchor: [17, 25/2],
1192+
}));
1193+
}
1194+
break;
1195+
case "LineString":
1196+
case "MultiLineString":
1197+
layer.setStyle((mode_line == "width" ? styleLine_width(layer.feature.properties[this._field]) : styleLine_color(layer.feature.properties[this._field])))/*.addTo(map)*/;
1198+
break;
1199+
case "Polygon":
1200+
case "MultiPolygon":
1201+
if (mode_polygon == "hatch") {
1202+
layer._path.style['fill'] = stylePolygon_hatch(layer.feature.properties[this._field], this.options); // this messy workaround is needed due to Leaflet ignoring `className` in layer.setStyle(). See https://github.com/leaflet/leaflet/issues/2662.
1203+
layer._path.style['fill-opacity'] = (options.style.fillOpacity != null ? options.style.fillOpacity : 0.7);
1204+
} else {
1205+
layer.setStyle(stylePolygon_color(layer.feature.properties[this._field], this.options))/*.addTo(map)*/;
1206+
}
1207+
break;
1208+
default:
1209+
console.error('Error: Unknown feature type: ', layer.feature.geometry.type, layer.feature)
1210+
break;
11841211
}
1185-
if (layer.feature.geometry.type == "Polygon" || layer.feature.geometry.type == "MultiPolygon") {
1186-
if (mode_polygon == "hatch") {
1187-
layer._path.style['fill'] = stylePolygon_hatch(layer.feature.properties[this._field], this.options); // this messy workaround is needed due to Leaflet ignoring `className` in layer.setStyle(). See https://github.com/leaflet/leaflet/issues/2662.
1188-
layer._path.style['fill-opacity'] = (options.style.fillOpacity != null ? options.style.fillOpacity : 0.7);
1189-
} else {
1190-
layer.setStyle(stylePolygon_color(layer.feature.properties[this._field], this.options))/*.addTo(map)*/;
1191-
}
1192-
}
11931212
}
11941213
});
11951214

0 commit comments

Comments
 (0)