1. Trying to get a map showing all projects (number/count) listed by country on a world map.
2. If number/count of projects is clicked it should focus on the country and show all project markers.
FYI CPT Projects are children of CPT 'organisation'
Should work like this example:
hidden link
No active link yet to a page yet.
I need some pointers on how to setup the map as shown in the example.
Best regards, hrbrt
Hello, unfortunately Toolset Maps doesn't have anything exactly like this built-in, and it would take a considerable amount of custom JavaScript and PHP programming to implement it. The main challenge here will be creating the country-specific clusters and programming their functionality. Toolset maps does offer marker clusters, but they are applied at the global level when several posts are shown in the same general area of a map. They are not separated by country, and they are not easily customizable as such. Furthermore there is no simple way to break apart search results into country-based groups like this, because custom field addresses are not separated by component in our system. In other words, country is not isolated as a separate entity from street, number or post code, so it cannot be used easily for grouping. To achieve that, you would have to create a separate custom field to store the country individually for each post, and either manage that value manually (independently of the geocoded address) or use custom JavaScript to parse the components of an address when it is geocoded and store that value with custom PHP.
Let me know your thoughts, but I suspect you're looking for a solution that works somewhat out-of-the-box. In that case, Toolset Maps does not have the features necessary for country-level sorting and filtering of results like this.
Hello Christian,
Thank you for the quick reply. The projects cpt already have a custom field 'country'. So could I make maps cluster the results by country? How is that option triggered?
PHP and Javascript is not an issue for me, just want to make sure it can be done in toolset maps as it ai already in use in this website.
I could get projects data for each countries projects in an array. My issue is how to get the data to show on the map. Is there some kind of developers documentation on how maps handles all the data?
Best regards, hrbrt
Clustering in Toolset Maps is triggered by the proximity of markers in the visible area. This built-in feature is not customizable based on country, unfortunately, only by the few options shown here: https://toolset.com/documentation/user-guides/maps/customizing-cluster-markers-with-javascript-functions/
Nothing in these options helps you cluster by country, unfortunately.
I could get projects data for each countries projects in an array. My issue is how to get the data to show on the map. Is there some kind of developers documentation on how maps handles all the data?
There is limited information available, but you can see a bit about how the JavaScript objects holding marker information are structured here: https://toolset.com/documentation/user-guides/maps/programmatically-change-map-settings/
When you load a page with a Toolset Map, you can find all the available maps data in the browser console if you want to poke around the JavaScript objects:
Use the get_map() method to get a Toolset Map object, as explained in the "How to programmatically change map settings" article above. From there, you can use the Google Maps JavaScript API to interact with that map object and its corresponding markers, add your own drawing layers, etc. Everything after you call get_map() to get a map object is custom code that falls outside the scope of our support policy, as there is no public Toolset Maps JavaScript API for interactions or further customization: https://toolset.com/toolset-support-policy/
One thing I was thinking you could do is set up one map just for the country cluster markers and another map just for the results. Basically you would create a CPT for "CountryMarkers", including an address field you would use to place a marker at the center of each country, and other custom field values to build the marker text or details. Then create a map View of that CPT to display custom markers on the map to represent each cluster. The problem then becomes how to transition between showing the "cluster" country markers and the actual data markers. I can't think of an elegant solution to that. You can add click handlers to the cluster markers, but that leads into the realm of custom code which isn't supported in the forums.
Hello Christian,
Thank you for all the information. I have been testing something with clustering and it seems to work pretty okay for now. So I will try this option before I will dive into the code and docs. For now I wil close the issue. Thanks again for your effort!
My issue is resolved now. Thank you!