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

How to pass marker color from feature property? #219

Closed dreadedhamish closed 1 year ago

dreadedhamish commented 1 year ago

I have a large dataset in geojson and I'd like to color the markers using a feature property (called 'Colour' and contains a hex code).

I'm aware I could break up my data to seperate geojson files, but I'll be updating this data frequently and the the process of filtering my data once per marker category, converting them all to geojson, and uploading, is going to get tedious.

I've tried:

Is there an option I'm missing, or it's not possible at this time?

hupe13 commented 1 year ago

Unfortunately it is not possible at the moment. I had this idea when implementing other functions, but I did not find a solution yet. You can, however, group them.

dreadedhamish commented 1 year ago

Thanks for responding - I'll stop trying stuff, It would be a handy feature.

hupe13 commented 1 year ago

It was a similar question in the forum before. In the meantime, I have learned a few things, maybe I will succeed in a new attempt.

hupe13 commented 1 year ago

You can test it: Documentation and examples.

dreadedhamish commented 1 year ago

Having a play now! I'm having trouble getting colours to show. Here is a clone of your example maps (using your denominations.geojson file): https://maps.resilift.com.au/maps/vic-ec8-map-2/ using Version 3.4.4-230503 with Leaflet Map 3.3.0

Shortcode: [leaflet-map height=100vh width=100% lng=13.1399 lat=51.956922 zoom=8 zoomcontrol=1 doubleclickzoom=1] [leaflet-geojson src="https://maps.resilift.com.au/wp-content/uploads/denomination.geojson" circleMarker color=blue fillOpacity=0.1 radius=6 table-view=1] [­geojsonmarker property=color default=blue disableClusteringAtZoom=8 values="green,yellow,red,others" groups="catholic,lutheran,protestant,others"]

(Using the multiple geojson approach still works as expected: https://maps.resilift.com.au/maps/vic-ec8-map/)

hupe13 commented 1 year ago

;-) It is a display issue of the code on my website. I'm working with php-scripts and the WordPress plugin Enlighter to show the code. To disable interpret the code in the Enlighter block I'm using a hidden character "[­". Write two '[[' doesn't do the job. Delete the hidden character after '[', then it works. I should write a note on my page about this. If you know a better solution, please tell me.

dreadedhamish commented 1 year ago

I did try it just modifying my own data first, and when troublshooting I figured I'd try your example to double-check my own setup. I'll have another go.

dreadedhamish commented 1 year ago

Done! I must have copied too much from the example for my own data as well, This is a real timesaver - I was filtering my spreadsheet into individual sheets, one per category, exporting each as a CSV, converting each one using an online convertor, and then uploading them all to my site - no more!

Thanks!

I'm a little confused about the shortcode though - colours (and categories) are in the geojson, and then in the shortcode we point it to the colour key, pass an array of categories, and then colours to match the categories?

hupe13 commented 1 year ago

For now the colors are "hardcoded" in the geojson file. In this first step I found a solution where I can continue, e.g. assign property to color.

dreadedhamish commented 1 year ago

OK - so colours are dictated by the geojson file, groups are how you want them to be sorted (which ones appear in the filter checkbox are) and values is what links them (using the order they appear - correlating with the groups array)?

It doesn't matter that much - it works - i was just struggling to figure out which but did what and it felt like I was passing the data twice.

hupe13 commented 1 year ago

Wait a few days for the next commit.

hupe13 commented 1 year ago

I have changed some things. Please read the documentation /wp-admin/admin.php?page=extensions-leaflet-map-github&tab=geojsonmarker

hupe13 commented 1 year ago

Version 3.4.4. is released. If you have a new issue, ask in the WordPress forum or in the Extensions page please. (I know, there is a new bug with "other". I forgot this. Sorry about that.)