protection if location list is empty

+ create script and style dir
This commit is contained in:
lenovo
2022-11-02 10:59:38 +01:00
parent bd5d1715a0
commit 8ed8fc2044
5 changed files with 55 additions and 14 deletions

View File

@@ -39,10 +39,10 @@ function mp_enqueue_scripts() {
// https://developers.google.com/maps/documentation/javascript/marker-clustering
$marker_clusterer = "https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js";
wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', '');
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
wp_enqueue_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true);
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
wp_enqueue_style( 'mp_style', plugins_url('styles/mp_style.css', __FILE__), '', '', '');
wp_enqueue_script('mp_marker_clusterer', $marker_clusterer, '', '', true);
wp_enqueue_script('mp_init_map', plugins_url('scripts/mp_init_map.js', __FILE__), ['mp_marker_clusterer'],'', true);
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
mp_add_to_scripts();
}

View File

@@ -34,8 +34,12 @@ function mp_retrieve_address(&$posts_list) {
foreach ($posts_list as $post_value) {
$content = $post_value->post_content;
$address = mp_extract_address($content);
$lat_lng = mp_convert_coordinates($address);
array_push($locs, $lat_lng);
if (strlen($address) > 0)
{
$lat_lng = mp_convert_coordinates($address);
if ($lat_lng !== null)
array_push($locs, $lat_lng);
}
};
return $locs;
}

View File

@@ -1,7 +0,0 @@
#ljdp_map {
height: 500px;
width: 100%;
}
#temoin {
color: blue;
}

View File

@@ -11,14 +11,31 @@ function mp_init_map() {
let map_center = {lat:46.227638, lng:2.213749};
if (locations.length > 0)
map_center = locations[0];
let map = new google.maps.Map(
document.getElementById("ljdp_map"),
{
zoom: 5,
// mpa options : https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
// maps controls :
disableDefaultUI: true,
zoomControl: true,
scaleControl: true,
// other controls :
zoom: 5,
//gestureHandling: "cooperative",
//gestureHandling: "greedy",
gestureHandling: "none",
//gestureHandling: "auto",
//disableDoubleClickZoom: "false",
//draggable: "true",
center: map_center,
}
);
//map.addListener("zoom_changed", () => {
// // do nothing ?
//});
let marker, icon, label;
icon = {
url: icon_url,

View File

@@ -0,0 +1,27 @@
#ljdp_map {
height: 500px;
width: 100%;
}
#temoin {
color: blue;
}
/*
* styling zoom buttons on map
*/
/* hide the rectangular box container */
div.gmnoprint div {
visibility: hidden;
}
/* shape buttons in circles */
button.gm-control-active {
visibility: visible;
border-radius: 50% !important;
background-color: rgb(255, 255, 255) !important;
}
/* gap between the buttons */
button.gm-control-active ~ div {
height: 10px !important;
}