GeoJSON styling on import #5
Replies: 1 comment 1 reply
-
Hello! Thanks for your feedback! I'm grateful that this plugin is being useful to you!. So, when you are using GeoJson in leaflet, you have this callback called "style". Using this you can, for each feature in your GeoJson Feature Collection, add some styling stuff using the Path Options. Because i want the most things being customizable in this plugin, i "opened this window" that you can make your own styling callback function. But this is optional as you can see bellow: style: (feat) => {
// simplestyle-spec to leaflet path style
const featStyle = simpleStyleToLeafletStyle(feat);
if (Object.keys(featStyle).length) {
return featStyle;
}
}, This code above is from the source code. I made a custom styling function based on simplestyle-spec from mapbox! A lot of KML comes with this styling by default, so i chose it. Explaining the code above to you, because you asked for an example, it's quite simple: The arrow function will receive a feature from the feature collection on each iteration as an argument, so, i use this feature object to pass to another function made by me called "simpleStyleToLeafletStyle" that reads it's properties, search for keys that follow the simplestyle-spec and convert to "Path Options". And then, if it applied any style, return the style to the Feature. Resulting in one of these: Here it's a GeoJson with properties that follow the simplestyle-spec File: Here it's a GeoJson with empty properties: File: So... you have the option to use this default styling function made by me just not overwriting the styling option like you did style: () => {}, // Overwrite the default BFL GeoJSON style function I hope this explanation can be anyway helpful for you! Feel free to ask more questions and thank you again for the feedback. Regards, |
Beta Was this translation helpful? Give feedback.
-
First of all thanks for a great plugin. It works well!
I had problems when importing GeoJSON. As I understand color and styles can be set by default when importing data here:
style: () => {}, // Overwrite the default BFL GeoJSON style function
Could you help me with an example? I don't understand object oriented programming very well and any example of how to access the settings would be helpful. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions