Google Maps integration & placeholder
-
The wizard says “We see you have enabled Google Maps as a service, but we can’t find an integration. You can integrate manually if needed.” and I am having trouble with maps in two places.
Google maps is being blocked until marketing consent is granted, which is expected. One of the maps is not showing a placeholder, just a big empty space. I tried to manually add the placeholder in generatepress-maps.php using the class of my map container, locations-map-canvas:
<?php
defined( 'ABSPATH' ) or die( "you do not have access to this page!" );
add_filter( 'cmplz_known_script_tags', 'cmplz_custom_googlemaps_script' );
/**
* Block the script, and an inline script with string 'initMap'.
* initMap can also be something else. That's the problem with custom maps :)
*
* @param $tags
*
* @return array
*/
function cmplz_custom_googlemaps_script( $tags ) {
$tags[] = array(
'name' => 'google-maps',
'category' => 'marketing',
'placeholder' => 'google-maps',
'urls' => array(
'show_google_map_acf.js',
'MapOptions',
'maps.googleapis.com/maps/api/js',
),
'enable_placeholder' => '1',
'placeholder_class' => 'locations-map-canvas',
'enable_dependency' => '1',
'dependency' => [
//'wait-for-this-script' => 'script-that-should-wait'
'maps.googleapis.com/maps/api/' => 'show_google_map_acf.js',
'mapOptions' => 'maps.googleapis.com/maps/api/js',
],
);
return $tags;
}
/**
* Trigger the DomContentLoaded event
* This is not always needed, but in a plugin initializes on document load or ready, the map won't show on consent because this event already ran.
* This will re-trigger that.
*
*/
function cmplz_custom_maps_initDomContentLoaded() {
ob_start();
?>
<script>
document.addEventListener("cmplz_run_after_all_scripts", cmplz_fire_domContentLoadedEvent);
function cmplz_fire_domContentLoadedEvent() {
dispatchEvent(new Event('load'));
}
</script>
<?php
$script = ob_get_clean();
$script = str_replace(array('<script>', '</script>'), '', $script);
wp_add_inline_script( 'cmplz-cookiebanner', $script );
}
add_action( 'wp_enqueue_scripts', 'cmplz_custom_maps_initDomContentLoaded',PHP_INT_MAX );The console does not show any classes or placeholders showing in that area when consent is not granted.
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.