Implement simplestyle for GeoJSON
This commit is contained in:
parent
0e462aac86
commit
4e719daee1
2 changed files with 17 additions and 3 deletions
|
|
@ -10,13 +10,27 @@ BR.Track = {
|
|||
* @returns {Object} to pass as `options` parameter to `L.geoJson`
|
||||
*/
|
||||
getGeoJsonOptions: function (layersControl) {
|
||||
// https://github.com/mapbox/simplestyle-spec/tree/master/1.1.0
|
||||
const styleMapping = [
|
||||
['stroke', 'color'],
|
||||
['stroke-width', 'weight'],
|
||||
['stroke-opacity', 'opacity'],
|
||||
['fill', 'fillColor'],
|
||||
['fill-opacity', 'fillOpacity'],
|
||||
];
|
||||
return {
|
||||
style: function (geoJsonFeature) {
|
||||
var currentLayerId = layersControl.getActiveBaseLayer().layer.id;
|
||||
return {
|
||||
var currentLayerId = layersControl?.getActiveBaseLayer().layer.id;
|
||||
const featureStyle = {
|
||||
color: currentLayerId === 'cyclosm' ? 'yellow' : 'blue',
|
||||
weight: 4,
|
||||
};
|
||||
for (const [simpleStyle, leafletStyle] of styleMapping) {
|
||||
if (geoJsonFeature?.properties?.[simpleStyle]) {
|
||||
featureStyle[leafletStyle] = geoJsonFeature.properties[simpleStyle];
|
||||
}
|
||||
}
|
||||
return featureStyle;
|
||||
},
|
||||
interactive: false,
|
||||
filter: function (geoJsonFeature) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue