bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

Customize popup text style #134

Closed garageeks closed 1 year ago

garageeks commented 3 years ago

Hi to all, I'm trying to style the popups, which are populated by a GeoJSON features collection. While working directly with LeafletJS, in the OnEachFeature function, I can compose the popup content with html, therefore I assign CSS classes to the title, headings etc. How can I add CSS in the popup content here? I see the relevant OnEachFeature function is in class.geojson-shortcode.php, I could hack it, but perhaps there is a supported way to do this. For instance, I don't know what this does:

window.WPLeafletMapPlugin.template( popup_text, feature.properties );

Thank you for your help Nick

bozdoz commented 3 years ago

check out window.WPLeafletMapPlugin.geojsons: that should be an array of L.GeoJSON layers which you should be able to use to run onEachFeature.

also template is the only function I've written a unit test for! https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/tests/App.test.js

It basically uses properties from your GeoJSON to create a string:

Property: {name} would create a different popup for each layer that has a name property for example.

bozdoz commented 3 years ago

If this works for you, I will close this ticket