hupe13 / extensions-leaflet-map-github

WordPress Plugin Extensions for Leaflet Map - Github Version
GNU General Public License v2.0
13 stars 2 forks source link

Leaflet.FeatureGroup.SubGroup not working correctly when marker has attributes of multiple categories #8

Closed praul closed 1 year ago

praul commented 1 year ago

Hi there and thanks for your plugin. It seems to provide some features I need and is way more handy than messing with leaflet myself.

I'm trying to implement a filterable map. Markers can have multiple categories. When I filter using leaflet-optiongroup, only one category is aknowledged.

Example: Marker 1 has categories (a,b) Marker 2 has categories (b)

When I try to hide category b, only marker 2 disappears. When I hide category a and select category b, marker 1 does not appear.

I fear this is expected behaviour as markers can only be in one group? Is there a way to mitigate this?

My shortcodes for reference:

[leaflet-extramarker extraClasses="my_category_a my_category_b" lat="123" lng="456" scrollwheeel="1"]
Example Popup Text
[/leaflet-extramarker]

[leaflet-extramarker extraClasses="my_category_b" lat="456" lng="789" scrollwheeel="1"]
Example Popup Text 2
[/leaflet-extramarker]

[leaflet-optiongroup option="extraClasses" values="my_category_a, my_category_b" groups="Example Group A, Example Group B" substr=1]

Danke und beste Grüße :)

hupe13 commented 1 year ago

For now, a marker may only be in one category.

praul commented 1 year ago

Thanks for your reply. Is there a way to add classes to the marker div? ExtraClasses don't seem to render in html.

image

If one could add classes to the marker div, I could code a filter function myself.

hupe13 commented 1 year ago

"extraClasses" wird zum Klassifizieren missbraucht, das Attribut gehört zum Leaflet Plugin https://github.com/coryasilva/Leaflet.ExtraMarkers. Wären Marker in einer Geojson-Datei was für dich? Entweder [geojsonmarker] oder [leaflet-featuregroup]. Zwar wird dort auch nur eine Property behandelt, aber da könnte man ansetzen, um einem Marker mehrere Eigenschaften zuzuweisen und danach zu gruppieren.

praul commented 1 year ago

Hmm, ich glaube das wären mir zuviele Schritte. Die Datenquelle für die Marker sind Custom Post Types mit entsprechenden Metafeldern, aus denen ich dann die Shortcodes generiere. Der leaflet-marker Shortcode aus dem Basisplugin ermöglicht ja die IconClass welche als Klasse auch ins Dom gerendert wird. Ich glaub ich bastel mir darauf aufbauend dann ne ganz einfache js Funktion welche die Marker anhand von ihren Klassen ein- und ausblendet. Ich hätte das hier als sauberere Lösung empfunden und war mir nicht sicher, ob ich was übersehe :) Danke dir, kannst zumachen

hupe13 commented 1 year ago

Ich glaub ich bastel mir darauf aufbauend dann ne ganz einfache js Funktion welche die Marker anhand von ihren Klassen ein- und ausblendet.

Falls der Code für die Allgemeinheit interessant sein könnte, kannst du ihn mir ja zukommen lassen.

praul commented 1 year ago

Okay, keine Ahnung ob das für dich interessant ist, da das ganze erstmal ein eher hackiger Ansatz ist: https://github.com/praul/extensions-leaflet-map-filterbox

Funktioniert gut, benutzt allerdings keinerlei Leaflet-Funktionen sondern ausschließlich css Klassen und jQuery zum einblenden/ausblenden.