Skip to content

Commit

Permalink
MultiPoint support
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
balladaniel committed Nov 23, 2023
1 parent d36bd9d commit f3a2ad9
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions leaflet-dataclassification.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,32 +1164,51 @@ L.DataClassification = L.GeoJSON.extend({
// apply symbology to features
this.eachLayer(function(layer) {
if (layer.feature.properties[this._field] == null && nodataignore) {
layer.remove()
layer.remove();
} else {
if (layer.feature.geometry.type == "Point" || layer.feature.geometry.type == "MultiPoint") {
var coords = layer.feature.geometry.coordinates;
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
style.shape = ps;

const svgIcon = L.divIcon({
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
className: "",
iconSize: [25, 25],
iconAnchor: [17, 25/2],
});
layer.setIcon(svgIcon);
}
if (layer.feature.geometry.type == "LineString" || layer.feature.geometry.type == "MultiLineString") {
layer.setStyle((mode_line == "width" ? styleLine_width(layer.feature.properties[this._field]) : styleLine_color(layer.feature.properties[this._field])))/*.addTo(map)*/;
switch (layer.feature.geometry.type) {
case "Point":
var coords = layer.feature.geometry.coordinates;
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
style.shape = ps;

const svgIcon = L.divIcon({
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
className: "",
iconSize: [25, 25],
iconAnchor: [17, 25/2],
});
layer.setIcon(svgIcon);
break;
case "MultiPoint":
var style = (mode_point == "color" ? stylePoint_color(layer.feature.properties[this._field]) : stylePoint_size(layer.feature.properties[this._field], this.options))
var mpfeatures = layer._layers;
for (const property in mpfeatures) {
mpfeatures[property].setIcon(L.divIcon({
html: svgCreator({shape: style.shape, size: style.radius, color: style.fillColor}),
className: "",
iconSize: [25, 25],
iconAnchor: [17, 25/2],
}));
}
break;
case "LineString":
case "MultiLineString":
layer.setStyle((mode_line == "width" ? styleLine_width(layer.feature.properties[this._field]) : styleLine_color(layer.feature.properties[this._field])))/*.addTo(map)*/;
break;
case "Polygon":
case "MultiPolygon":
if (mode_polygon == "hatch") {
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.
layer._path.style['fill-opacity'] = (options.style.fillOpacity != null ? options.style.fillOpacity : 0.7);
} else {
layer.setStyle(stylePolygon_color(layer.feature.properties[this._field], this.options))/*.addTo(map)*/;
}
break;
default:
console.error('Error: Unknown feature type: ', layer.feature.geometry.type, layer.feature)
break;
}
if (layer.feature.geometry.type == "Polygon" || layer.feature.geometry.type == "MultiPolygon") {
if (mode_polygon == "hatch") {
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.
layer._path.style['fill-opacity'] = (options.style.fillOpacity != null ? options.style.fillOpacity : 0.7);
} else {
layer.setStyle(stylePolygon_color(layer.feature.properties[this._field], this.options))/*.addTo(map)*/;
}
}
}
});

Expand Down

0 comments on commit f3a2ad9

Please sign in to comment.