Skip to content

Commit 822e09f

Browse files
committed
Housekeeping
1 parent db91d21 commit 822e09f

File tree

3 files changed

+91
-86
lines changed

3 files changed

+91
-86
lines changed

inc/Helpers/Waymark_GeoJSON.php

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,120 @@
22

33
class Waymark_GeoJSON {
44

5-
static public function string_to_feature_collection($string = '') {
6-
if(is_string($string)) {
7-
return json_decode($string, true, 512, JSON_OBJECT_AS_ARRAY);
5+
static public function string_to_feature_collection($string = '') {
6+
if (is_string($string)) {
7+
return json_decode($string, true, 512, JSON_OBJECT_AS_ARRAY);
88
}
99

10-
return false;
11-
}
10+
return false;
11+
}
1212

13-
static public function get_feature_count($FeatureCollection = []) {
14-
if(is_string($FeatureCollection)) {
15-
$FeatureCollection = self::string_to_feature_collection($FeatureCollection);
13+
static public function get_feature_count($FeatureCollection = []) {
14+
if (is_string($FeatureCollection)) {
15+
$FeatureCollection = self::string_to_feature_collection($FeatureCollection);
1616
}
17-
18-
if($FeatureCollection && isset($FeatureCollection['features']) && is_array($FeatureCollection['features'])) {
17+
18+
if ($FeatureCollection && isset($FeatureCollection['features']) && is_array($FeatureCollection['features'])) {
1919

2020
return sizeof($FeatureCollection['features']);
21-
}
21+
}
2222

23-
return false;
24-
}
23+
return false;
24+
}
2525

26-
static public function update_feature_property($FeatureCollection = [], $property_key = null, $property_value = null) {
27-
if(is_string($FeatureCollection)) {
28-
$FeatureCollection = self::string_to_feature_collection($FeatureCollection);
26+
static public function update_feature_property($FeatureCollection = [], $property_key = null, $property_value = null) {
27+
if (is_string($FeatureCollection)) {
28+
$FeatureCollection = self::string_to_feature_collection($FeatureCollection);
2929
}
3030

3131
//Feature Collection
32-
if($FeatureCollection && isset($FeatureCollection['features'])) {
32+
if ($FeatureCollection && isset($FeatureCollection['features'])) {
3333

3434
//Each Feature
35-
foreach($FeatureCollection['features'] as &$Feature) {
36-
if(! isset($Feature['properties']) || ! is_array($Feature['properties'])) {
35+
foreach ($FeatureCollection['features'] as &$Feature) {
36+
if (!isset($Feature['properties']) || !is_array($Feature['properties'])) {
3737
$Feature['properties'] = [];
3838
}
39-
39+
4040
$Feature['properties'][$property_key] = $property_value;
4141
}
42-
}
42+
}
43+
44+
return $FeatureCollection;
45+
}
4346

44-
return $FeatureCollection;
45-
}
46-
4747
static public function clean_feature_descriptions($FeatureCollection = []) {
4848
//Feature Collection
49-
if($FeatureCollection && isset($FeatureCollection['features'])) {
49+
if ($FeatureCollection && isset($FeatureCollection['features'])) {
5050

5151
//Each Feature
52-
foreach($FeatureCollection['features'] as &$Feature) {
53-
if(isset($Feature['properties']['description'])) {
54-
$bad = ['"'];
52+
foreach ($FeatureCollection['features'] as &$Feature) {
53+
if (isset($Feature['properties']['description'])) {
54+
$bad = ['"'];
5555
$good = ['\"'];
5656
$Feature['properties']['description'] = str_replace($bad, $good, $Feature['properties']['description']);
5757
}
5858
}
59-
}
59+
}
6060

6161
return $FeatureCollection;
6262
}
63+
64+
static public function features_by_overlay_type(Array $FeatureCollection = []) {
65+
66+
// Waymark_Helper::debug($FeatureCollection);
67+
68+
$overlays = array(
69+
'markers' => array(),
70+
'lines' => array(),
71+
'shapes' => array(),
72+
);
73+
74+
foreach ($FeatureCollection['features'] as $feature) {
75+
76+
// Waymark_Helper::debug($feature);
77+
78+
//Ensure feature properties has type
79+
if (!isset($feature['properties']['type'])) {
80+
continue;
81+
}
82+
83+
if (isset($feature['geometry']['type'])) {
84+
switch ($feature['geometry']['type']) {
85+
case 'Point':
86+
//Circle
87+
if (isset($feature['properties']['radius'])) {
88+
$type = 'shapes';
89+
//Marker
90+
} else {
91+
$type = 'markers';
92+
}
93+
94+
break;
95+
96+
case 'LineString':
97+
case 'MultiLineString':
98+
$type = 'lines';
99+
100+
break;
101+
case 'Polygon':
102+
$type = 'shapes';
103+
104+
break;
105+
}
106+
}
107+
108+
//Add to Array if we have a type
109+
if (isset($type)) {
110+
$overlays[$type][$feature['properties']['type']][] = $feature;
111+
}
112+
}
113+
114+
// Order markers/lines/shapes by type
115+
foreach ($overlays as &$overlay) {
116+
ksort($overlay);
117+
}
118+
119+
return $overlays;
120+
}
63121
}

inc/Helpers/Waymark_Helper.php

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -532,59 +532,6 @@ static public function add_map_link_to_description($map_id = null, $map_title =
532532
return Waymark_Helper::set_map_data_property($map_data, 'description', $desc_append, true);
533533
}
534534

535-
static public function map_data_to_objects($map_data) {
536-
$objects = array(
537-
'markers' => array(),
538-
'lines' => array(),
539-
'shapes' => array(),
540-
);
541-
542-
$FeatureCollection = json_decode($map_data);
543-
544-
//Ensure valid data
545-
if ($FeatureCollection && sizeof($FeatureCollection->features)) {
546-
foreach ($FeatureCollection->features as $feature) {
547-
if (isset($feature->geometry->type)) {
548-
switch ($feature->geometry->type) {
549-
case 'Point':
550-
//Waymark_Helper::debug($feature);
551-
552-
//Circle
553-
if (isset($feature->properties->radius)) {
554-
$objects['shapes'][$feature->properties->type][] = $feature->properties;
555-
//Marker
556-
} else {
557-
$objects['markers'][$feature->properties->type][] = $feature->properties;
558-
}
559-
560-
break;
561-
562-
case 'LineString':
563-
case 'MultiLineString':
564-
$objects['lines'][$feature->properties->type][] = $feature->properties;
565-
566-
break;
567-
case 'Polygon':
568-
$objects['shapes'][$feature->properties->type][] = $feature->properties;
569-
570-
break;
571-
}
572-
}
573-
}
574-
575-
//Sort by size of child array
576-
foreach ($objects as $type => &$objs) {
577-
//Thanks! https://stackoverflow.com/a/9455586/569788
578-
uasort($objs, function ($a, $b) {
579-
return (count($b) - count($a));
580-
});
581-
}
582-
583-
}
584-
585-
return $objects;
586-
}
587-
588535
public static function convert_single_value_to_array($value_in) {
589536
//Array
590537
if (is_array($value_in)) {
@@ -652,7 +599,7 @@ public static function multi_use_as_key($array_in, $as_key = false) {
652599
return $array_out;
653600
}
654601

655-
public static function get_object_types($type = 'marker', $use_key = false, $as_options = false) {
602+
public static function get_overlay_types($type = 'marker', $use_key = false, $as_options = false) {
656603
$object_types = Waymark_Config::get_item($type . 's', $type . '_types', true);
657604

658605
//Use keys

inc/Waymark_Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ public static function get_map_config() {
345345
$map_config['tile_layers'] = $tile_layers;
346346

347347
//Object Types
348-
$map_config['marker_types'] = Waymark_Helper::get_object_types('marker');
349-
$map_config['line_types'] = Waymark_Helper::get_object_types('line');
350-
$map_config['shape_types'] = Waymark_Helper::get_object_types('shape');
348+
$map_config['marker_types'] = Waymark_Helper::get_overlay_types('marker');
349+
$map_config['line_types'] = Waymark_Helper::get_overlay_types('line');
350+
$map_config['shape_types'] = Waymark_Helper::get_overlay_types('shape');
351351

352352
//Editor Options
353353
$map_config['map_options'] = array(

0 commit comments

Comments
 (0)