Skip to content

Commit

Permalink
Helper improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
morehawes committed Jan 10, 2024
1 parent 2ed5717 commit b97f558
Showing 1 changed file with 51 additions and 22 deletions.
73 changes: 51 additions & 22 deletions inc/Helpers/Waymark_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,16 @@ public static function multi_use_as_key($array_in, $as_key = false) {
return $array_out;
}

public static function get_overlay_types($type = 'marker', $use_key = false, $as_options = false) {
$object_types = Waymark_Config::get_item($type . 's', $type . '_types', true);
/**
* Get the overlay types
*
* @param string $feature_type Feature type
* @param boolean $use_key Build associative array using $use_key as key
* @param boolean $as_options Build as options array ready for <select>
* @return array Array of overlay types
*/
public static function get_overlay_types(String $feature_type = 'marker', String $use_key = '', Bool $as_options = false) {
$object_types = Waymark_Config::get_item($feature_type . 's', $feature_type . '_types', true);

//Use keys
if ($use_key) {
Expand All @@ -625,6 +633,23 @@ public static function get_overlay_types($type = 'marker', $use_key = false, $as
return $object_types;
}

/**
* Get the overlay type data
*
* @param string $feature_type Feature type
* @param string $type_key Type key
* @return array Array of overlay types
*/
public static function get_type_data(String $feature_type = 'marker', String $type_key = '') {
$marker_types = self::get_overlay_types($feature_type, $feature_type . '_title');

if (array_key_exists($type_key, $marker_types)) {
return $marker_types[$type_key];
} else {
return false;
}
}

public static function array_string_to_array($string) {
$string = str_replace(array('[', ']', '"', '"'), array('', '', '', ''), $string);

Expand Down Expand Up @@ -1134,8 +1159,17 @@ public static function get_marker_background(String $colour = '') {
return $colour;
}

public static function build_overlay_content(Array $feature = []) {
$content = '<div class="waymark-overlay-content">';
public static function build_overlay_content(Array $feature = [], String $feature_type = 'marker', Array $type_data = []) {
$content = '<div class="waymark-overlay-content waymark-overlay-' . $feature_type . '">' . "\n";

// If we don't have type data
if (empty($type_data)) {
// Get Type Data
$type_data = Waymark_Helper::get_type_data($feature_type, $feature['properties']['type_key']);

Waymark_Helper::debug($type_data);

}

//Expected Waymark properties
// i.e. array('radius', 'type', 'title', 'description', 'image_thumbnail_url', 'image_medium_url', 'image_large_url')
Expand All @@ -1159,22 +1193,18 @@ public static function build_overlay_content(Array $feature = []) {
$content .= '<strong>' . $feature['properties']['title'] . '</strong>';
//No description
} else {
$content .= '<strong>&nbsp;</strong>';
$content .= '<strong>' . $type_data['type_title'] . '</strong>';
}

break;

//Type
case 'type':
if (Waymark_Config::get_item('map_options.show_type_labels') != '1') {
break;
}
// if (Waymark_Config::get_item('map_options.show_type_labels') != '1') {
// break;
// }

//Get type
$type = Waymark_Helper::get_type($type['type_key'], $feature['properties']['type']);
if ($type) {
$content .= Waymark_Helper::type_to_text($type['type_key'], $type, 'small');
}
$content .= Waymark_Helper::type_to_text($feature_type, $type_data, 'small');

break;

Expand Down Expand Up @@ -1227,27 +1257,26 @@ public static function build_overlay_content(Array $feature = []) {
}

//Represent Type as text
public static function type_to_text(String $type_key = '', Array $type = [], String $ele = 'span') {
$preview_class = 'waymark-type-text waymark-' . $type_key . '-type';
public static function type_to_text(String $feature_type = '', Array $type_data = [], String $ele = 'span') {
$preview_class = 'waymark-type-text waymark-' . $feature_type . '-type';
$preview_style = '';

switch ($type_key) {
switch ($feature_type) {
case 'marker':
$preview_style .= 'color:' . $type['icon_colour'] . ';';
$preview_style .= 'background:' . self::get_marker_background($type['marker_colour']);
$preview_style .= 'color:' . $type_data['icon_colour'] . ';';
$preview_style .= 'background:' . self::get_marker_background($type_data['marker_colour']);

break;
case 'line':
$preview_style .= 'color:' . $type['line_colour'] . ';box-shadow:inset 0 0 0 1px ' . $type['line_colour'];
$preview_style .= 'color:' . $type_data['line_colour'] . ';box-shadow:inset 0 0 0 1px ' . $type_data['line_colour'];

break;
case 'shape':
$preview_style .= 'background:' . $type['shape_colour'];
$preview_style .= 'background:' . $type_data['shape_colour'];

break;
}

return '<' . $ele . ' class="' . $preview_class . '" style="' . $preview_style . '">' . $type[$type_key . '_title'] . '</' . $ele . '>';
return '<' . $ele . ' class="' . $preview_class . '" style="' . $preview_style . '">' . $type_data[$feature_type . '_title'] . '</' . $ele . '>';
}

}

0 comments on commit b97f558

Please sign in to comment.