Skip to content

Commit 0fa21f3

Browse files
author
Joe Hawes
committed
Collection rendering improvements
1 parent 90fc936 commit 0fa21f3

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

inc/Front/Waymark_Shortcode.php

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,56 @@ function handle_shortcode($shortcode_data, $content = null) {
7979
//Map Class
8080
$map_class .= ' waymark-collection-id-' . $collection_id;
8181

82-
//Iterate over Collection
83-
foreach ($Collection->Maps as $Map) {
84-
//Ensure we have data
85-
if (!array_key_exists('map_data', $Map->data)) {
86-
continue;
82+
// Collection Maps as GeoJSON
83+
84+
// If we are embedding
85+
if ('embed' === Waymark_Config::get_setting('misc', 'collection_options', 'load_method')) {
86+
$collectionMaps = [
87+
'type' => 'FeatureCollection',
88+
'features' => [],
89+
];
90+
91+
//Iterate over Collection
92+
foreach ($Collection->Maps as $Map) {
93+
//Ensure we have data
94+
if (!array_key_exists('map_data', $Map->data)) {
95+
continue;
96+
}
97+
98+
//Link to Map page?
99+
if (Waymark_Config::get_setting('misc', 'collection_options', 'link_to_maps') == true) {
100+
//Modify map data
101+
$Map->data['map_data'] = Waymark_Helper::add_map_link_to_description($Map->post_id, $Map->post_title, $Map->data['map_data']);
102+
103+
}
104+
105+
//Add to GeoJSON
106+
$collectionMaps['features'] = array_merge($collectionMaps['features'], json_decode($Map->data['map_data'], true)['features']);
87107
}
88108

89-
//Output
90-
$maps_output[$Map->post_id] = array(
91-
'map_id' => $Map->post_id,
92-
'map_title' => $Map->post_title,
93-
'collection_id' => $collection_id,
94-
);
95-
96-
//Link to Map page?
97-
if (Waymark_Config::get_setting('misc', 'collection_options', 'link_to_maps') == true) {
98-
//Modify map data
99-
$modified_map_data = Waymark_Helper::add_map_link_to_description($Map->post_id, $Map->post_title, $Map->data['map_data']);
100-
if ($modified_map_data) {
101-
$maps_output[$Map->post_id]['map_data'] = $modified_map_data;
102-
} else {
103-
$maps_output[$Map->post_id]['map_data'] = $Map->data['map_data'];
109+
// Collection Maps
110+
if (sizeof($collectionMaps['features'])) {
111+
$maps_output[$collection_id] = array(
112+
'map_data' => json_encode($collectionMaps),
113+
);
114+
}
115+
116+
// Loading Maps via HTTP
117+
} else {
118+
//Iterate over Collection
119+
foreach ($Collection->Maps as $Map) {
120+
//Ensure we have data
121+
if (!array_key_exists('map_data', $Map->data)) {
122+
continue;
104123
}
105-
} else {
106-
$maps_output[$Map->post_id]['map_data'] = $Map->data['map_data'];
124+
125+
//Output
126+
$maps_output[$Map->post_id] = array(
127+
'map_id' => $Map->post_id,
128+
'map_title' => $Map->post_title,
129+
'collection_id' => $collection_id,
130+
'map_data' => $Map->data['map_data'],
131+
);
107132
}
108133
}
109134

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ A big thank you to the following projects and their contributors. Without their
116116

117117
### 0.9.30 ###
118118

119-
* Added Marker Clustering! Once enabled, Markers will be grouped together when they are close together. This can help to reduce clutter on the Map. You can enable this feature in Settings > Maps > Clustering, or using the `show_cluster="1"` Shortcode option. There are also settings to adjust the cluster radius and what what zoom level to start clustering at.
119+
* **Marker Clustering**
120+
* Once enabled, Markers will be grouped together when they are close together. This can help to reduce clutter on the Map.
121+
* You can enable this feature in Settings > Maps > Clustering, or using the `show_cluster="1"` Shortcode option.
122+
* There are also settings to adjust the cluster radius and what what zoom level to start clustering at.
120123
* Added `file_start_type` and `file_end_type` options to the <a href="https://www.waymark.dev/docs/shortcodes/#shortcode-files">Shortcode Files</a> feature, which allow you to automatically add a Marker of the specified type to the start and/or end of all Lines in the file. Thanks to <a href="https://wordpress.org/support/users/digbymaass/">digbymaass</a> for the <a href="https://wordpress.org/support/topic/shortcode-option-for-start-marker/">suggestion</a>.
121124
* Stop Elevation plugin from adjusting map bounds. Thanks to <a href="https://wordpress.org/support/users/ellocosolo/">ellocosolo</a> for the <a href="https://wordpress.org/support/topic/map_centre-and-map_zoom-shortcodes-cannot-be-used-at-the-same-time/">report</a>.
122125
* Improved KML error handling when loading from URL.
126+
* Improved rendering of multiple Maps through the Collection Shortcode.
123127
* Minor bug fixes
124128

125129
### 0.9.29.5 ###

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ A big thank you to the following projects and their contributors. Without their
100100

101101
= 0.9.30 =
102102

103-
* Added Marker Clustering! Once enabled, Markers will be grouped together when they are close together. This can help to reduce clutter on the Map. You can enable this feature in Settings > Maps > Clustering, or using the `show_cluster="1"` Shortcode option. There are also settings to adjust the cluster radius and what what zoom level to start clustering at.
103+
* **Marker Clustering**
104+
* Once enabled, Markers will be grouped together when they are close together. This can help to reduce clutter on the Map.
105+
* You can enable this feature in Settings > Maps > Clustering, or using the `show_cluster="1"` Shortcode option.
106+
* There are also settings to adjust the cluster radius and what what zoom level to start clustering at.
104107
* Added `file_start_type` and `file_end_type` options to the <a href="https://www.waymark.dev/docs/shortcodes/#shortcode-files">Shortcode Files</a> feature, which allow you to automatically add a Marker of the specified type to the start and/or end of all Lines in the file. Thanks to <a href="https://wordpress.org/support/users/digbymaass/">digbymaass</a> for the <a href="https://wordpress.org/support/topic/shortcode-option-for-start-marker/">suggestion</a>.
105108
* Stop Elevation plugin from adjusting map bounds. Thanks to <a href="https://wordpress.org/support/users/ellocosolo/">ellocosolo</a> for the <a href="https://wordpress.org/support/topic/map_centre-and-map_zoom-shortcodes-cannot-be-used-at-the-same-time/">report</a>.
106109
* Improved KML error handling when loading from URL.
110+
* Improved rendering of multiple Maps through the Collection Shortcode.
107111
* Minor bug fixes
108112

109113
= 0.9.29.5 =

0 commit comments

Comments
 (0)