Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
morehawes committed Sep 9, 2024
1 parent 2c0fc3c commit aeb46f5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
53 changes: 39 additions & 14 deletions inc/Front/Waymark_Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ function handle_shortcode($shortcode_data, $content = null) {

// === Initially Show / Hide ===

$debug_output = '';

foreach (['hide_marker', 'show_marker', 'hide_line', 'show_line', 'hide_shape', 'show_shape'] as $show_hide_type) {
// If option exists
if (array_key_exists($show_hide_type, $shortcode_data)) {
Expand All @@ -382,6 +384,11 @@ function handle_shortcode($shortcode_data, $content = null) {
$out .= ' var this_key = waymark_viewer.make_key(waymark_config.map_options.' . $overlay_kind . '_types[i]["' . $overlay_kind . '_title"]);' . "\n";

$out .= ' if("' . $overlay_type . '" == "*" || this_key == "' . $overlay_type . '") {' . "\n";

if (Waymark_Helper::is_debug()) {
$debug_output .= ucwords($overlay_kind) . ' ' . ucwords($show_hide_explode[0]) . ' (' . $overlay_type . ') ';
}

$out .= ' waymark_config.map_options.' . $overlay_kind . '_types[i]["' . $overlay_kind . '_display"] = ' . $overlay_display . ';' . "\n";
$out .= ' }' . "\n";
$out .= ' }' . "\n";
Expand All @@ -395,8 +402,14 @@ function handle_shortcode($shortcode_data, $content = null) {

$out .= ' waymark_viewer.init(waymark_config);' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Initialised");' . "\n";
$out .= ' waymark_viewer.debug(waymark_config);' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Initialised");' . "\n";
$out .= ' waymark_viewer.debug(waymark_config);' . "\n";

if ($debug_output) {
$out .= ' waymark_viewer.debug("' . $debug_output . '");' . "\n";
}
}

// =====================================
// ================ MAPS ===============
Expand All @@ -412,8 +425,10 @@ function handle_shortcode($shortcode_data, $content = null) {
if (isset($map_output['map_data'])) {
$out .= ' waymark_viewer.load_json(' . $map_output['map_data'] . ');' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Map Loaded");' . "\n";
$out .= ' waymark_viewer.debug(' . $map_output['map_data'] . ');' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Map Loaded");' . "\n";
$out .= ' waymark_viewer.debug(' . $map_output['map_data'] . ');' . "\n";
}

//Done loading
$out .= ' waymark_viewer.load_done();' . "\n";
Expand All @@ -429,8 +444,10 @@ function handle_shortcode($shortcode_data, $content = null) {

$out .= ' waymark_load_map_data(waymark_viewer, ' . $map_id . ', ' . $reset_view . ');' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Map Loaded via HTTP (' . $i . '/' . sizeof($maps_output) . ')");' . "\n";
$out .= ' waymark_viewer.debug(' . $map_id . ');' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Map Loaded via HTTP (' . $i . '/' . sizeof($maps_output) . ')");' . "\n";
$out .= ' waymark_viewer.debug(' . $map_id . ');' . "\n";
}

//Done loading
if ($i == sizeof($maps_output)) {
Expand Down Expand Up @@ -518,8 +535,10 @@ function handle_shortcode($shortcode_data, $content = null) {
$out .= ' let marker_geojson = ' . json_encode($marker_geojson) . ';' . "\n";
$out .= ' waymark_viewer.load_json(marker_geojson);' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Marker Loaded");' . "\n";
$out .= ' waymark_viewer.debug(marker_geojson);' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' Marker Loaded");' . "\n";
$out .= ' waymark_viewer.debug(marker_geojson);' . "\n";
}
}
}

Expand Down Expand Up @@ -681,8 +700,10 @@ function handle_shortcode($shortcode_data, $content = null) {
// Add Markers
$out .= ' waymark_viewer.load_json(fileAddFeatures);' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' File ' . ucwords($overlay_type) . 's Loaded");' . "\n";
$out .= ' waymark_viewer.debug(fileAddFeatures);' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' File ' . ucwords($overlay_type) . 's Loaded");' . "\n";
$out .= ' waymark_viewer.debug(fileAddFeatures);' . "\n";
}
}

break;
Expand All @@ -692,9 +713,10 @@ function handle_shortcode($shortcode_data, $content = null) {

$out .= ' waymark_viewer.load_json(file_geo_json);' . "\n";

$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' File Loaded");' . "\n";
$out .= ' waymark_viewer.debug(file_geo_json);' . "\n";

if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode #' . $shortcode_hash . ' File Loaded");' . "\n";
$out .= ' waymark_viewer.debug(file_geo_json);' . "\n";
}
}
}
}
Expand All @@ -706,7 +728,10 @@ function handle_shortcode($shortcode_data, $content = null) {

if (array_key_exists('loaded_callback', $shortcode_data)) {
$out .= ' if(typeof ' . $shortcode_data['loaded_callback'] . ' === "function") {' . "\n";
$out .= ' waymark_viewer.debug("Shortcode Callback detected ' . $shortcode_data['loaded_callback'] . '(waymark_instance)");' . "\n";
if (Waymark_Helper::is_debug()) {
$out .= ' waymark_viewer.debug("Shortcode Callback detected ' . $shortcode_data['loaded_callback'] . '(waymark_instance)");' . "\n";
}

$out .= ' ' . $shortcode_data['loaded_callback'] . '(waymark_viewer);' . "\n";
$out .= ' } else {' . "\n";
$out .= ' waymark_viewer.message("Callback function not found!", "error");' . "\n";
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Built on the shoulders of giants, [thank you](https://www.waymark.dev/docs/thank
### 1.4.0 ###

- Added the ability to show/hide all Types initially when using the Shortcode by specifying "*" as the Type key. For example, to initially hide all Marker Types, except "photo" and "alert", use `[Waymark map_id="1234" hide_marker="*" show_marker="photo,alert"]`. Thanks to [Association Franc-Comtoise du Chemin de Compostelle](https://www.af-ccc.fr) for requesting this.
- Improved debugging output.

### 1.3.2 ###

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Built on the shoulders of giants, [thank you](https://www.waymark.dev/docs/thank
= 1.4.0 =

- Added the ability to show/hide all Types initially when using the Shortcode by specifying "*" as the Type key. For example, to initially hide all Marker Types, except "photo" and "alert", use `[Waymark map_id="1234" hide_marker="*" show_marker="photo,alert"]`. Thanks to [Association Franc-Comtoise du Chemin de Compostelle](https://www.af-ccc.fr) for requesting this.
- Improved debugging output.

= 1.3.2 =

Expand Down

0 comments on commit aeb46f5

Please sign in to comment.