diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php index e0dd0cb..8d425ee 100644 --- a/srcs/plugins/map_prof/map_prof_hooks.php +++ b/srcs/plugins/map_prof/map_prof_hooks.php @@ -32,9 +32,38 @@ require_once(dirname(__FILE__) . '/mp_address_errors.php'); require_once(dirname(__FILE__) . '/mp_create_div.php'); +// // temp test +// +// add_action( 'wp', 'my_front_end_function'); +// function my_front_end_function() { +// if ( is_admin() ) +// return; +// if ( get_post_type() != "post" ) +// return; +// if ( get_post_status() != "publish" ) +// return; +// +// $location = get_field(location); +// mp_console_log("location:"); +// mp_console_log($location); +// +// $coordinates = $location->coordinates; +// mp_console_log("coordinates:"); +// mp_console_log($coordinates); +// } +function is_event_post() { + if ( is_admin() ) + return false; + if ( get_post_type() != "post" ) + return 0; + if ( get_post_status() != "publish" ) + return 0; + return true; +} + /** @@ -89,6 +118,18 @@ function mp_ljdp_map() { "locations" => $locations, "filters" => $filters, ); + + // if post event instead of map page, change ccoordinate and zoom + global $mp_zoom; + if (is_event_post()) { + $mp_zoom = $mp_zoom_set[1]; + + $location = get_field(location); + $coordinates = $location->coordinates; + + $mp_coordinates_default = $coordinates; + } + mp_add_to_scripts($to_add); diff --git a/srcs/plugins/map_prof/mp_add_to_scripts.php b/srcs/plugins/map_prof/mp_add_to_scripts.php index e8d216e..c8a991d 100644 --- a/srcs/plugins/map_prof/mp_add_to_scripts.php +++ b/srcs/plugins/map_prof/mp_add_to_scripts.php @@ -12,6 +12,7 @@ function mp_add_to_scripts($to_add) { global $mp_icon_color; global $mp_icon_color_back; global $mp_icon_size_factor; + global $mp_zoom; global $mp_coordinates_default; global $mp_icon_stroke_width; global $mp_max_zoom; @@ -20,6 +21,7 @@ function mp_add_to_scripts($to_add) { wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color, 'icon_color'), 'before'); wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color_back, 'icon_color_back'), 'before'); wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size_factor, 'icon_size_factor'), 'before'); + wp_add_inline_script('mp_init_map', mp_php_to_js($mp_zoom, 'map_zoom'), 'before'); wp_add_inline_script('mp_init_map', mp_php_to_js($mp_coordinates_default, 'coordinates_default'), 'before'); wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_stroke_width, 'icon_stroke_width'), 'before'); wp_add_inline_script('mp_init_map', mp_php_to_js($mp_max_zoom, 'max_zoom'), 'before'); diff --git a/srcs/plugins/map_prof/mp_get_coordinates.php b/srcs/plugins/map_prof/mp_get_coordinates.php index 164f22c..21a94e8 100644 --- a/srcs/plugins/map_prof/mp_get_coordinates.php +++ b/srcs/plugins/map_prof/mp_get_coordinates.php @@ -66,4 +66,5 @@ function mp_get_coordinates($id) { return $location; } + ?> diff --git a/srcs/plugins/map_prof/scripts/mp_create_map.js b/srcs/plugins/map_prof/scripts/mp_create_map.js index 4031461..844ff7a 100644 --- a/srcs/plugins/map_prof/scripts/mp_create_map.js +++ b/srcs/plugins/map_prof/scripts/mp_create_map.js @@ -8,7 +8,7 @@ function create_map(map_div) { disableDefaultUI: true, zoomControl: true, scaleControl: true, - zoom: 2, + zoom: map_zoom, gestureHandling: "cooperative", //gestureHandling: "greedy", //gestureHandling: "none", diff --git a/srcs/plugins/map_prof/scripts/mp_init_map.js b/srcs/plugins/map_prof/scripts/mp_init_map.js index 5e0d84c..954f475 100644 --- a/srcs/plugins/map_prof/scripts/mp_init_map.js +++ b/srcs/plugins/map_prof/scripts/mp_init_map.js @@ -41,6 +41,7 @@ function mp_init_map() { * - let icon_color_back = "" * - let icon_size = [x, y] * - let cluster_size_factor = Number + * - let map_zoom = x * - let max_zoom = x */ diff --git a/srcs/plugins/map_prof/settings/mp_globals.php b/srcs/plugins/map_prof/settings/mp_globals.php index eeb8ade..d64fb4e 100644 --- a/srcs/plugins/map_prof/settings/mp_globals.php +++ b/srcs/plugins/map_prof/settings/mp_globals.php @@ -37,6 +37,15 @@ if (isset($mp_settings_icon_size_factor)) $mp_icon_size_factor = $mp_settings_icon_size_factor; +/* DEFAULT ZOOM +*/ +$mp_zoom_set = [2, 5]; +if (isset($mp_settings_zoom_set)) +$mp_zoom_set = $mp_settings_zoom_set; +// also create the variable, and set to map page by default +$mp_zoom = $mp_zoom_set[0]; + + /* DEFAULT COORDINATES */ $mp_coordinates_default = (object)["lat" => 46.227638, "lng" => 2.213749]; // france diff --git a/srcs/plugins/map_prof/settings/mp_optionnals.php b/srcs/plugins/map_prof/settings/mp_optionnals.php index 21d2fba..0722820 100644 --- a/srcs/plugins/map_prof/settings/mp_optionnals.php +++ b/srcs/plugins/map_prof/settings/mp_optionnals.php @@ -9,15 +9,6 @@ -/* ************************************ - dimensions de l'icone des marqueurs - _ - valeur par defaut [40, 40] - ************************************ */ -//$mp_settings_icon_size = [50, 50]; - - - /* ************************************ facteur de taille des clusters _ @@ -27,6 +18,17 @@ +/* ************************************ + zoom initial + - pour les pages + - pour les posts + _ + valeur par defaut [2, 5] + ************************************ */ +//$mp_settings_zoom_set = [1, 6]; + + + /* ************************************ coordonnees par defaut (pour centrer la carte globale,