Tell us what you are trying to do?
Just following on from a previous ticket. I'm trying to use a filterable View to output the address field coordinates data to populate a Leaflet map (as neither Google or Azure are currently suitable). We currently have a view with a map (see hidden link as an example) with filterable options. Is it possible to generate the coordinates for the posts that are filtered from the address field so that we can use this data to populate the markers for a separate leaflet map? I guess it's going to require some php but I would be grateful if you could point me in the right direction. A solution is hinted at in the comments here - https://toolset.com/2018/07/toolset-maps-1-5-with-azure-maps-google-street-view-and-ordering-by-distance/#comment-352315 - but I could do with some more help.
Many thanks
If you use Views to create the filtered search system, then you can have Views spit out a data model that contains all the location coordinates. If you do not use Views and use some other filtered search system, then you would have to figure out a way to pass the result IDs into a View filtered by post ID. Then you could use Views to create a data model. What exactly do you need produced by Views - do you have a data model template available? Or is the data passed into the map some other way?
Thanks for getting back to me.
Yes the filtered search system is using Views. The example here - hidden link - shows the View with the filtered search, it outputs the listing cards on the left hand side with the corresponding markers for the map on the right hand side. We are using the Toolset Map and marker shortcodes for the map but what we would like to do is use a Leaflet map which requires the latitude and longitude coordinates data to create the markers so I would like to keep the View as it is but without the Toolset Map/markers and instead to somehow generate the corresponding coordinates data for the listing cards displayed which would then be used to create the markers for a leaflet map (which would update as the View is filtered).
Hope that makes a bit more sense!
We are currently using this plugin - https://wordpress.org/plugins/leaflet-map/ - to generate the Leaflet maps on the rest of the website.
Thanks
Hi Christian, I am starting to get somewhere with this. I've used the leaflet map shortcode from the plugin I linked to earlier in the loop output editor before the loop start and this renders the map fine. I've then added the leaflet marker shortcode within the loop and have used the Address Fields API to output the longitude and latitude, this also seems to work. The problem is that the loop output then breaks the code in the leaflet marker script that is loaded - it replaces "[" with "[*semi-colon*" and "]" with "]*semi-colon*" ( replaced ; with *semi-colon* as just displays bracket otherwise!)
Is there any way around this?
You can see an example here - hidden link - sorry it's a bit of a mess as I took out everything from the loop other than the marker shortcode. If you use inspector you'll see that the map script loads fine without breaking, but the marker script within the loop breaks I thought it might be a shortcode within shortcode issue so I also tried just manually entering the coordinates in the loop editor but this did the same thing to the brackets in the script that runs. (PS If the marker shortcode is run outside the loop then it works fine - see this example - hidden link - where the marker shortcode outside the loop displays fine but the same shortcode within the loop breaks).
Thanks
My first thought would be to run a text string replacement on the values to convert these HTML codes into real brackets, but I'm not sure offhand why you would be seeing the 091 and 093 in the first place. Can you share your Loop code and the code in any Template applied to this Loop?
Another step closer! I've managed to get the markers to render (the script still seems to be generating the html codes instead of the brackets but it seems to work anyway on our production site) - hidden link
The issue now is that it stops working as soon as anything is changed in the search/filter - see this page for how it should work when things are filtered - hidden link
Would it be possible to initiate a private reply so that I can send you all the code as there's also quite a lot javascript which may be conflicting with things?
Thanks
If you're using AJAX to update the results, then you'll probably have to re-initialize your map somehow after the results have been updated. You can use the Frontend Events button in any View's Search and Pagination JS editor to build event listener templates where your code can respond to search or pagination events. I'm attaching a screenshot here that shows where you can find that button.
Yes we are using ajax and that seems to be the culprit, I can get it working ok by doing a full page refresh so I might just have to make do with that for now. I've tried the frontend events button but not had any joy, I can see that it's already been called in the view so maybe it's causing a conflict? I don't understand JS well enough to make any significant edits.
Thanks
If you're not familiar with JS then I think your best bet is a non-AJAX approach, because I'm not familiar with this mapping system and I wouldn't be able to offer any advice. If you're able to figure out how to update the map on-the-fly, I'll be glad to help you trigger that code somehow using the front-end events button.
Thanks Christian. I'll stick with the non-ajax approach for now as it's working fine. If I get anywhere with ajax updating then I'll open another ticket if I need some assistance triggering the code. Thanks