@@ -141,16 +141,16 @@ static public function get_map_meta($Map, $context = 'map_single') {
141
141
142
142
//Select
143
143
if (in_array ($ setting_meta ['meta_type ' ], array ('select ' )) && array_key_exists ('meta_options ' , $ setting_meta )) {
144
- $ options_array = Waymark_Helper ::comma_string_to_array ($ setting_meta ['meta_options ' ]);
144
+ $ options_array = self ::comma_string_to_array ($ setting_meta ['meta_options ' ]);
145
145
146
146
//Only if option exists
147
147
if (isset ($ options_array [$ Map ->data [$ meta_key ]])) {
148
148
$ data ['meta_value ' ] = $ options_array [$ Map ->data [$ meta_key ]];
149
149
}
150
150
//Multi-Select
151
151
} elseif (in_array ($ setting_meta ['meta_type ' ], array ('select_multi ' )) && array_key_exists ('meta_options ' , $ setting_meta )) {
152
- $ options_array = Waymark_Helper ::comma_string_to_array ($ setting_meta ['meta_options ' ]);
153
- $ values_array = Waymark_Helper ::array_string_to_array ($ Map ->data [$ meta_key ]);
152
+ $ options_array = self ::comma_string_to_array ($ setting_meta ['meta_options ' ]);
153
+ $ values_array = self ::array_string_to_array ($ Map ->data [$ meta_key ]);
154
154
155
155
//Build output
156
156
$ data ['meta_value ' ] = '' ;
@@ -199,13 +199,13 @@ static public function get_map_meta($Map, $context = 'map_single') {
199
199
$ map_meta ['export_data ' ] = array (
200
200
'meta_key ' => 'export_data ' ,
201
201
'meta_title ' => esc_html__ ('Export ' , 'waymark ' ),
202
- 'meta_value ' => Waymark_Helper ::map_export_html ($ Map ),
202
+ 'meta_value ' => self ::map_export_html ($ Map ),
203
203
'meta_info ' => '<a data-title=" ' . esc_attr__ ('This will download the Overlays currently displayed by the Map in the selected format. ' , 'waymark ' ) . '" href="#" onclick="return false;" class="waymark-tooltip">?</a> ' ,
204
204
'meta_group ' => '' ,
205
205
);
206
206
}
207
207
208
- // Waymark_Helper ::debug($map_meta);
208
+ // self ::debug($map_meta);
209
209
210
210
return $ map_meta ;
211
211
}
@@ -228,13 +228,13 @@ static public function get_collection_meta($Collection, $context = 'shortcode')
228
228
$ map_meta ['export_data ' ] = array (
229
229
'meta_key ' => 'export_data ' ,
230
230
'meta_title ' => esc_html__ ('Export ' , 'waymark ' ),
231
- 'meta_value ' => Waymark_Helper ::collection_export_html ($ Collection ),
231
+ 'meta_value ' => self ::collection_export_html ($ Collection ),
232
232
'meta_info ' => '<a data-title=" ' . esc_attr__ ('This will download the Overlays currently displayed by the Map in the selected format. ' , 'waymark ' ) . '" href="#" onclick="return false;" class="waymark-tooltip">?</a> ' ,
233
233
'meta_group ' => '' ,
234
234
);
235
235
}
236
236
237
- // Waymark_Helper ::debug($map_meta);
237
+ // self ::debug($map_meta);
238
238
239
239
return $ map_meta ;
240
240
}
@@ -250,7 +250,7 @@ static public function get_meta_groups() {
250
250
static public function group_meta ($ meta_array , $ meta_groups = []) {
251
251
if (!$ meta_groups ) {
252
252
//Get Groups
253
- $ meta_groups = Waymark_Helper ::get_meta_groups ();
253
+ $ meta_groups = self ::get_meta_groups ();
254
254
}
255
255
256
256
//Sort into groups
@@ -275,10 +275,10 @@ static public function map_meta_html($meta_array = array()) {
275
275
//Do we have data?
276
276
if (is_array ($ meta_array ) && sizeof ($ meta_array )) {
277
277
//Get Meta Groups
278
- $ meta_groups = Waymark_Helper ::get_meta_groups ();
278
+ $ meta_groups = self ::get_meta_groups ();
279
279
280
280
//Sort into groups
281
- $ meta_grouped = Waymark_Helper ::group_meta ($ meta_array , $ meta_groups );
281
+ $ meta_grouped = self ::group_meta ($ meta_array , $ meta_groups );
282
282
283
283
//Container
284
284
$ out = '<!-- START Parameter Container --> ' . "\n" ;
@@ -533,7 +533,7 @@ static public function add_map_link_to_description($map_id = null, $map_title =
533
533
}
534
534
$ desc_append .= '</b>.</div> ' ;
535
535
536
- return Waymark_Helper ::set_map_data_property ($ map_data , 'description ' , $ desc_append , true );
536
+ return self ::set_map_data_property ($ map_data , 'description ' , $ desc_append , true );
537
537
}
538
538
539
539
public static function convert_single_value_to_array ($ value_in ) {
@@ -547,7 +547,7 @@ public static function convert_single_value_to_array($value_in) {
547
547
$ count = 0 ;
548
548
foreach ($ multi as $ m ) {
549
549
$ array_out [$ count ][$ key ] = $ m ;
550
- // Waymark_Helper ::debug($m, false);
550
+ // self ::debug($m, false);
551
551
552
552
$ count ++;
553
553
}
@@ -677,7 +677,7 @@ static public function map_export_html($Map) {
677
677
678
678
$ element = (is_admin ()) ? 'div ' : 'form ' ;
679
679
680
- $ out = '< ' . $ element . ' action=" ' . Waymark_Helper ::http_url () . '" method="post" id="waymark-map-export- ' . $ Map ->post_id . '" class="waymark-map-export" data-map_id=" ' . $ Map ->post_id . '" data-map_slug=" ' . sanitize_title ($ Map ->post_title ) . '"> ' . "\n" ;
680
+ $ out = '< ' . $ element . ' action=" ' . self ::http_url () . '" method="post" id="waymark-map-export- ' . $ Map ->post_id . '" class="waymark-map-export" data-map_id=" ' . $ Map ->post_id . '" data-map_slug=" ' . sanitize_title ($ Map ->post_title ) . '"> ' . "\n" ;
681
681
$ out .= ' <select name="export_format"> ' . "\n" ;
682
682
$ out .= ' <option value="gpx">GPX</option> ' . "\n" ;
683
683
$ out .= ' <option value="kml">KML</option> ' . "\n" ;
@@ -694,15 +694,15 @@ static public function map_export_html($Map) {
694
694
}
695
695
696
696
static public function collection_export_html ($ Collection ) {
697
- // Waymark_Helper ::debug($Collection);
697
+ // self ::debug($Collection);
698
698
699
699
if (!isset ($ Collection ->collection_id )) {
700
700
return false ;
701
701
}
702
702
703
703
$ element = (is_admin ()) ? 'div ' : 'form ' ;
704
704
705
- $ out = '< ' . $ element . ' action=" ' . Waymark_Helper ::http_url () . '" method="post" id="waymark-map-export- ' . $ Collection ->collection_id . '" class="waymark-map-export" data-collection_id=" ' . $ Collection ->collection_id . '" data-collection_slug=" ' . $ Collection ->slug . '"> ' . "\n" ;
705
+ $ out = '< ' . $ element . ' action=" ' . self ::http_url () . '" method="post" id="waymark-map-export- ' . $ Collection ->collection_id . '" class="waymark-map-export" data-collection_id=" ' . $ Collection ->collection_id . '" data-collection_slug=" ' . $ Collection ->slug . '"> ' . "\n" ;
706
706
$ out .= ' <select name="export_format"> ' . "\n" ;
707
707
$ out .= ' <option value="gpx">GPX</option> ' . "\n" ;
708
708
$ out .= ' <option value="kml">KML</option> ' . "\n" ;
@@ -740,7 +740,7 @@ static public function repeatable_setting_option_array($tab, $section, $key) {
740
740
//If exists
741
741
if (array_key_exists ($ key , $ s )) {
742
742
//Add as option
743
- $ options_array [Waymark_Helper ::make_key ($ s [$ key ])] = $ s [$ key ];
743
+ $ options_array [self ::make_key ($ s [$ key ])] = $ s [$ key ];
744
744
}
745
745
}
746
746
@@ -973,9 +973,20 @@ static function allowable_file($ext = '', $mime = false, $file_image = 'file') {
973
973
return false ;
974
974
}
975
975
976
+ /**
977
+ * build_icon_data
978
+ *
979
+ * Builds the data necessary to render an icon
980
+ *
981
+ * @param array $type Type data
982
+ * @return array Icon data
983
+ * @since 2024.1
984
+ * @access public
985
+ * @static
986
+ */
976
987
static public function build_icon_data (Array $ type = []) {
977
988
978
- // Waymark_helper ::debug($type);
989
+ // self ::debug($type);
979
990
980
991
// If Type key not set
981
992
if (!isset ($ type ['type_key ' ])) {
@@ -1085,9 +1096,18 @@ static public function build_icon_data(Array $type = []) {
1085
1096
return $ icon_data ;
1086
1097
}
1087
1098
1099
+ /**
1100
+ * build_icon_html
1101
+ * Builds the HTML for an icon
1102
+ * @param array $icon_data Icon data
1103
+ * @return string HTML
1104
+ * @since 2024.1
1105
+ * @access public
1106
+ * @static
1107
+ */
1088
1108
static public function build_icon_html (Array $ icon_data = []) {
1089
1109
1090
- // Waymark_helper ::debug($icon_data);
1110
+ // self ::debug($icon_data);
1091
1111
1092
1112
$ icon_html = '<div class=" ' . $ icon_data ['className ' ] . '"> ' ;
1093
1113
@@ -1102,6 +1122,17 @@ static public function build_icon_html(Array $icon_data = []) {
1102
1122
1103
1123
}
1104
1124
1125
+ /**
1126
+ *
1127
+ * Converts old background options to new ones
1128
+ *
1129
+ * @param string $colour Colour
1130
+ * @return string Colour
1131
+ * @since 2024.1
1132
+ * @access public
1133
+ * @static
1134
+ *
1135
+ */
1105
1136
public static function get_marker_background (String $ colour = '' ) {
1106
1137
$ old_background_options = [
1107
1138
'red ' ,
@@ -1159,15 +1190,28 @@ public static function get_marker_background(String $colour = '') {
1159
1190
return $ colour ;
1160
1191
}
1161
1192
1193
+ /**
1194
+ *
1195
+ * Builds the HTML content for an overlay
1196
+ *
1197
+ * @param array $feature Feature array
1198
+ * @param string $feature_type Feature type
1199
+ * @param array $type_data Type data
1200
+ * @return string HTML content
1201
+ * @since 2024.1
1202
+ * @access public
1203
+ * @static
1204
+ *
1205
+ */
1162
1206
public static function build_overlay_content (Array $ feature = [], String $ feature_type = 'marker ' , Array $ type_data = []) {
1163
1207
$ content = '<div class="waymark-overlay-content waymark-overlay- ' . $ feature_type . '"> ' . "\n" ;
1164
1208
1165
1209
// If we don't have type data
1166
1210
if (empty ($ type_data )) {
1167
1211
// Get Type Data
1168
- $ type_data = Waymark_Helper ::get_type_data ($ feature_type , $ feature ['properties ' ]['type_key ' ]);
1212
+ $ type_data = self ::get_type_data ($ feature_type , $ feature ['properties ' ]['type_key ' ]);
1169
1213
1170
- Waymark_Helper ::debug ($ type_data );
1214
+ self ::debug ($ type_data );
1171
1215
1172
1216
}
1173
1217
@@ -1204,7 +1248,7 @@ public static function build_overlay_content(Array $feature = [], String $featur
1204
1248
// break;
1205
1249
// }
1206
1250
1207
- $ content .= Waymark_Helper ::type_to_text ($ feature_type , $ type_data , 'small ' );
1251
+ $ content .= self ::type_to_text ($ feature_type , $ type_data , 'small ' );
1208
1252
1209
1253
break ;
1210
1254
@@ -1256,7 +1300,21 @@ public static function build_overlay_content(Array $feature = [], String $featur
1256
1300
return $ content ;
1257
1301
}
1258
1302
1259
- //Represent Type as text
1303
+ /**
1304
+ *
1305
+ * Represent Type as text
1306
+ *
1307
+ * Outputs a textual representation of a type, coloured according to the type's colour Settings
1308
+ * https://www.waymark.dev/docs/settings/
1309
+ *
1310
+ * @param string $feature_type - marker, line, shape
1311
+ * @param array $type_data - array of type data, must have these keys: type_key, type_title, marker_colour, icon_colour
1312
+ * @param string $ele - HTML element to use to wrap the output
1313
+ * @return string
1314
+ * @since 2024.1
1315
+ * @access public
1316
+ * @static
1317
+ */
1260
1318
public static function type_to_text (String $ feature_type = '' , Array $ type_data = [], String $ ele = 'span ' ) {
1261
1319
$ preview_class = 'waymark-type-text waymark- ' . $ feature_type . '-type ' ;
1262
1320
$ preview_style = '' ;
@@ -1279,4 +1337,138 @@ public static function type_to_text(String $feature_type = '', Array $type_data
1279
1337
1280
1338
return '< ' . $ ele . ' class=" ' . $ preview_class . '" style=" ' . $ preview_style . '"> ' . $ type_data [$ feature_type . '_title ' ] . '</ ' . $ ele . '> ' ;
1281
1339
}
1340
+
1341
+ /**
1342
+ *
1343
+ * Creates the HTML strucuture for the overlays list
1344
+ *
1345
+ * $overlays must have one of these keys: markers, lines, shapes containing an array of overlays
1346
+ * Waymark_GeoJSON::features_by_overlay_type() is a good way to get this data
1347
+ *
1348
+ * Markers/Lines/Shapes are displayed separately and divided into types
1349
+ * Types are displayed as a header with a count
1350
+ * Each overlay is displayed as a list item
1351
+ * Each overlay has a title, description and image
1352
+ *
1353
+ * @param array $overlays An array containing 'marker' => [ $markers ], 'line' => [ $lines ], 'shape' => [ $shapes ]
1354
+ * @return string
1355
+ * @since 2024.1
1356
+ * @access public
1357
+ * @static
1358
+ *
1359
+ */
1360
+ public static function overlays_list_html (Array $ overlays = []) {
1361
+ $ out = '' ;
1362
+
1363
+ if (!sizeof ($ overlays )) {
1364
+ return $ out ;
1365
+ }
1366
+
1367
+ // $overlays must have one of these keys: markers, lines, shapes
1368
+ if (!array_key_exists ('markers ' , $ overlays ) && !array_key_exists ('lines ' , $ overlays ) && !array_key_exists ('shapes ' , $ overlays )) {
1369
+ return $ out ;
1370
+ }
1371
+
1372
+ // self::debug($overlays);
1373
+
1374
+ foreach ($ overlays as $ overlay_type => $ overlay ) {
1375
+ // $overlay must be an array
1376
+ if (!is_array ($ overlay )) {
1377
+ continue ;
1378
+ }
1379
+
1380
+ $ out .= '<div class="waymark-overlays-list"> ' . "\n" ;
1381
+
1382
+ switch ($ overlay_type ) {
1383
+ case 'markers ' :
1384
+ // Wrapper
1385
+ $ out .= '<div class="waymark-overlay-list waymark-overlay-markers"> ' . "\n" ;
1386
+ $ out .= ' <div class="waymark-title"> ' . __ ('Markers ' , 'waymark ' ) . '</div> ' . "\n" ;
1387
+ $ out .= ' <div class="waymark-overlays"> ' . "\n" ;
1388
+
1389
+ // Every marker type
1390
+ foreach ($ overlay as $ marker_type => $ markers ) {
1391
+ // Ensure we have markers
1392
+ if (!sizeof ($ markers )) {
1393
+ continue ;
1394
+ }
1395
+
1396
+ // Get type data
1397
+ $ type_data = self ::get_type_data ('marker ' , $ marker_type );
1398
+
1399
+ if (!$ type_data ) {
1400
+ continue ;
1401
+ }
1402
+
1403
+ // Wrapper for Type
1404
+ $ out .= ' <div class="waymark-type waymark-type- ' . $ marker_type . '"> ' . "\n" ;
1405
+
1406
+ //Output Title, Icon and count
1407
+ $ icon_data = self ::build_icon_data ($ type_data );
1408
+ $ icon_html = self ::build_icon_html ($ icon_data );
1409
+
1410
+ $ out .= ' <div class="waymark-header" style="background-color: ' . $ type_data ['marker_colour ' ] . ';color: ' . $ type_data ['icon_colour ' ] . ';"> ' . "\n" ;
1411
+ $ out .= ' <div class="waymark-icon"> ' . $ icon_html . '</div> ' . "\n" ;
1412
+ $ out .= ' <div class="waymark-title"> ' . $ type_data ['marker_title ' ] . '</div> ' . "\n" ;
1413
+ $ out .= ' <div class="waymark-count"> ' . sizeof ($ markers ) . '</div> ' . "\n" ;
1414
+ $ out .= ' </div> ' . "\n" ;
1415
+
1416
+ // Iterate over markers
1417
+ foreach ($ markers as $ marker ) {
1418
+ $ out .= self ::build_overlay_content ($ marker , 'marker ' , $ type_data );
1419
+ }
1420
+
1421
+ $ out .= ' </div> ' . "\n" ;
1422
+ }
1423
+
1424
+ $ out .= ' </div> ' . "\n" ;
1425
+ $ out .= '</div> ' . "\n" ;
1426
+
1427
+ break ;
1428
+ case 'lines ' :
1429
+ // Get valid line types
1430
+ $ line_types = self ::get_overlay_types ('line ' , 'line_title ' );
1431
+
1432
+ // Wrapper
1433
+ $ out .= '<div class="waymark-overlays waymark-lines"> ' . "\n" ;
1434
+
1435
+ // Every line type
1436
+ foreach ($ overlay as $ line_type => $ lines ) {
1437
+ // Ensure is valid line type
1438
+ if (!array_key_exists ($ line_type , $ line_types )) {
1439
+ continue ;
1440
+ }
1441
+
1442
+ $ out .= '<li> ' . $ line_type . ' ( ' . sizeof ($ lines ) . ')</li> ' . "\n" ;
1443
+ }
1444
+ $ out .= '</div> ' . "\n" ;
1445
+
1446
+ break ;
1447
+ case 'shapes ' :
1448
+ // Get valid shape types
1449
+ $ shape_types = self ::get_overlay_types ('shape ' , 'shape_title ' );
1450
+
1451
+ // Wrapper
1452
+ $ out .= '<div class="waymark-overlays waymark-shapes"> ' . "\n" ;
1453
+
1454
+ // Every shape type
1455
+ foreach ($ overlay as $ shape_type => $ shapes ) {
1456
+
1457
+ // Ensure is valid shape type
1458
+ if (!array_key_exists ($ shape_type , $ shape_types )) {
1459
+ continue ;
1460
+ }
1461
+
1462
+ $ out .= '<li> ' . $ shape_type . ' ( ' . sizeof ($ shapes ) . ')</li> ' . "\n" ;
1463
+ }
1464
+ $ out .= '</div> ' . "\n" ;
1465
+
1466
+ break ;
1467
+ }
1468
+ }
1469
+
1470
+ $ out .= '</div> ' . "\n" ;
1471
+
1472
+ return $ out ;
1473
+ }
1282
1474
}
0 commit comments