resolved uncaught js error

This commit is contained in:
lenovo
2022-10-31 00:20:37 +01:00
parent c35adaa732
commit fe6810f159
5 changed files with 44 additions and 19 deletions

View File

@@ -13,14 +13,25 @@ require_once(dirname(__FILE__) . '/mp_url_api.php');
add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts' );
function wpa_enqueue_scripts() {
wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', false);
wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', '');
wp_enqueue_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true);
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
// wp_register_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true);
// wp_register_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
}
//function wpa_defer_scripts($tag, $handle) {
// if ('mp_google_api' === $handle)
// return str_replace(' src="', ' async defer src="', $tag);
// if ('mp_googe_api' === $handle)
// return str_replace(' src="', ' defer src="', $tag);
// return $tag;
//}
//add_filter('script_loader_tag', 'wpa_defer_scripts', 10, 2);
add_shortcode('lejourduprof_map', 'mp_add_div');
function mp_add_div() {
$mp_api_script = '<div id="map">map here</div>';
$mp_api_script = '<div id="ljdp_map">map here</div>';
return $mp_api_script;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -1,11 +1,28 @@
function mp_init_map() {
var location = {lat: 38.8833, lng: -77.0167};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 12,
center: location
});
var marker = new google.maps.Marker({
position: location,
map: map
});
var locations = [
{lat: 38.8833, lng: -77.0167},
{lat: 39.8833, lng: -76.0167},
];
var map = new google.maps.Map(
document.getElementById("ljdp_map"),
{
zoom: 5,
disableDefaultUI: true,
center: locations[0],
}
);
var marker, icon;
// icon = "/wp-content/plugins/map_prof/marker.png";
icon = {
//url: document.location.href + "marker.png",
url: "/wp-content/plugins/map_prof/marker.png",
scaledSize: new google.maps.Size(35, 50)
};
for (loc of locations) {
marker = new google.maps.Marker({
position: loc,
map: map,
icon: icon,
});
};
}

View File

@@ -1,4 +1,4 @@
#map {
#ljdp_map {
height: 500px;
width: 100%;
}

View File

@@ -1,10 +1,10 @@
<?php
function mp_url_api() {
$mp_url = array(
'src' => 'https://maps.googleapis.com/maps/api/js',
'sensor' => 'false',
'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE',
'callback' => 'mp_init_map',
'src' => 'https://maps.googleapis.com/maps/api/js',
'sensor' => 'false',
'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE',
'callback' => 'mp_init_map',
);
$mp_src = "";
foreach ($mp_url as $url_key => $url_value) {
@@ -17,9 +17,6 @@ function mp_url_api() {
$mp_src .= "&" . $url_key . "=" . $url_value;
};
//$mp_api_script = '<script async defer ';
//$mp_api_script .= 'src="' . $mp_src . '"></script>';
//return $mp_api_script;
return $mp_src;
}
?>