added global max zoom
- better map center - default filter same bounds as init map
This commit is contained in:
@@ -14,6 +14,7 @@ function mp_add_to_scripts($to_add) {
|
||||
global $mp_icon_size_factor;
|
||||
global $mp_coordinates_default;
|
||||
global $mp_icon_stroke_width;
|
||||
global $mp_max_zoom;
|
||||
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_size, 'icon_size'), 'before');
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($mp_icon_color, 'icon_color'), 'before');
|
||||
@@ -21,6 +22,7 @@ function mp_add_to_scripts($to_add) {
|
||||
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_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');
|
||||
|
||||
foreach ($to_add as $key => $var) {
|
||||
wp_add_inline_script('mp_init_map', mp_php_to_js($var, $key), 'before');
|
||||
|
||||
@@ -22,7 +22,7 @@ function mp_create_div(&$filters) {
|
||||
';
|
||||
foreach ($filter as $value) {
|
||||
$mp_map_div .= '
|
||||
<p onclick="filter_show_only_selection('.json_encode($value->indexes).', true)">'.$value->_name.'</p>
|
||||
<p onclick="filter_show_only_selection('.json_encode($value->indexes).', false)">'.$value->_name.'</p>
|
||||
';
|
||||
}
|
||||
$mp_map_div .= '
|
||||
|
||||
@@ -45,10 +45,6 @@ function mp_fill_name($fields, $name, &$menu, $index) {
|
||||
}
|
||||
// add location index, if not there already
|
||||
if (! in_array($index, $menu_item->indexes) ) {
|
||||
mp_console_log("add index:");
|
||||
mp_console_log($index);
|
||||
mp_console_log("to menu_item:");
|
||||
mp_console_log($menu_item);
|
||||
array_push($menu_item->indexes, $index);
|
||||
}
|
||||
}
|
||||
@@ -64,10 +60,6 @@ function mp_fill_name($fields, $name, &$menu, $index) {
|
||||
array_push($menu_item->$key_field, $value);
|
||||
}
|
||||
// add list of location index
|
||||
mp_console_log("add index:");
|
||||
mp_console_log($index);
|
||||
mp_console_log("to menu_item:");
|
||||
mp_console_log($menu_item);
|
||||
$menu_item->indexes = [$index];
|
||||
|
||||
// and add this item to list of menu
|
||||
@@ -85,9 +77,6 @@ function mp_get_filters(&$events) {
|
||||
"mode" => ($event->irl)? "En présentiel" : "En ligne",
|
||||
);
|
||||
$index = $event->index;
|
||||
mp_console_log(" ");
|
||||
mp_console_log("EVENT:");
|
||||
mp_console_log($event);
|
||||
foreach ($fields as $key => $value) {
|
||||
if (! isset($filters->$key))
|
||||
$filters->$key = [];
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
// bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625
|
||||
|
||||
/**
|
||||
* if show_only is true:
|
||||
* erase all other markers from the map,
|
||||
* else, they stay visible
|
||||
* if zoom_in is true:
|
||||
* zoom to new selection,
|
||||
* even if already visible in current view
|
||||
*/
|
||||
function filter_show_only_selection(indexes, show_only = true) {
|
||||
function filter_show_only_selection(indexes, zoom_in = false) {
|
||||
|
||||
console.log("indexes:");
|
||||
console.log(indexes);
|
||||
@@ -17,8 +17,7 @@ function filter_show_only_selection(indexes, show_only = true) {
|
||||
if (indexes_count === 0)
|
||||
return;
|
||||
|
||||
if (show_only)
|
||||
g_marker_cluster.clearMarkers(true);
|
||||
g_marker_cluster.clearMarkers(true);
|
||||
|
||||
let marker = g_markers[0];
|
||||
let position = marker.getPosition();
|
||||
@@ -37,23 +36,23 @@ function filter_show_only_selection(indexes, show_only = true) {
|
||||
outside_bounds = true;
|
||||
bounds.extend(position);
|
||||
|
||||
if (show_only)
|
||||
g_marker_cluster.addMarker(marker, true);
|
||||
g_marker_cluster.addMarker(marker, true);
|
||||
}
|
||||
if ( show_only == false || (show_only && outside_bounds) ) {
|
||||
if (zoom_in || outside_bounds) {
|
||||
if (indexes_count === 1) {
|
||||
g_map.setCenter(position);
|
||||
g_map.setZoom(5);
|
||||
g_map.setZoom(max_zoom);
|
||||
}
|
||||
else if (indexes_count > 1)
|
||||
g_map.fitBounds(bounds);
|
||||
}
|
||||
if (show_only)
|
||||
g_marker_cluster.render();
|
||||
g_marker_cluster.render();
|
||||
|
||||
}
|
||||
|
||||
function filter_show_all() {
|
||||
g_marker_cluster.addMarkers(g_markers);
|
||||
g_map.fitBounds(g_init_bounds);
|
||||
//g_map.fitBounds(g_init_bounds);
|
||||
g_map.setCenter(coordinates_default);
|
||||
g_map.setZoom(2);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ function mp_init_map() {
|
||||
* - let icon_color_back = ""
|
||||
* - let icon_size = [x, y]
|
||||
* - let cluster_size_factor = Number
|
||||
* - let max_zoom = x
|
||||
*/
|
||||
|
||||
console.log("locations:");
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
/**
|
||||
* global variables :
|
||||
*
|
||||
* DO NOT MODIFY !
|
||||
* modify mp_optionnals.php or mp_required.php instead
|
||||
*/
|
||||
|
||||
$mp_icon_base_url = '/wp-content/plugins/map_prof/images/';
|
||||
$mp_icon_url = $mp_icon_base_url . $mp_icon_file;
|
||||
$mp_icon_cluster_url = $mp_icon_base_url . $mp_icon_cluster_file;
|
||||
|
||||
|
||||
/* ICON SIZE
|
||||
*/
|
||||
$mp_icon_size = [40, 40];
|
||||
if (isset($mp_settings_icon_size)) {
|
||||
if (is_array($mp_settings_icon_size)) {
|
||||
@@ -19,18 +22,30 @@ if (isset($mp_settings_icon_size)) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ICON COLOR
|
||||
*/
|
||||
$mp_icon_color = "#ba197a";
|
||||
if (isset($mp_settings_icon_color))
|
||||
$mp_icon_color = $mp_settings_icon_color;
|
||||
|
||||
|
||||
/* ICON FACTOR SIZE
|
||||
*/
|
||||
$mp_icon_size_factor = 2.5;
|
||||
if (isset($mp_settings_icon_size_factor))
|
||||
$mp_icon_size_factor = $mp_settings_icon_size_factor;
|
||||
|
||||
|
||||
/* DEFAULT COORDINATES
|
||||
*/
|
||||
$mp_coordinates_default = (object)["lat" => 46.227638, "lng" => 2.213749]; // france
|
||||
if (isset($mp_settings_coordinates_default))
|
||||
$mp_coordinates_default = $mp_settings_coordinates_default;
|
||||
|
||||
|
||||
/* ICON COLOR
|
||||
*/
|
||||
$mp_icon_color = "#ba197a";
|
||||
$mp_icon_color_back = "#ffffff99";
|
||||
if (isset($mp_settings_icon_color))
|
||||
@@ -38,8 +53,19 @@ if (isset($mp_settings_icon_color))
|
||||
if (isset($mp_settings_icon_color_back))
|
||||
$mp_icon_color_back = $mp_settings_icon_color_back;
|
||||
|
||||
|
||||
/* ICON STROKE WIDTH
|
||||
*/
|
||||
$mp_icon_stroke_width = 6;
|
||||
if (isset($mp_settings_icon_stroke_width))
|
||||
$mp_icon_stroke_width = $mp_settings_icon_stroke_width;
|
||||
|
||||
|
||||
/* MAX ZOOM
|
||||
*/
|
||||
$mp_max_zoom = 5;
|
||||
if (isset($mp_settings_max_zoom))
|
||||
$mp_max_zoom = $mp_settings_max_zoom;
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
/* ************************************
|
||||
dimensions de l'icone des marqueurs
|
||||
_
|
||||
valeur par defaut [40, 40]
|
||||
************************************ */
|
||||
//$mp_settings_icon_size = [50, 50];
|
||||
@@ -19,6 +20,7 @@
|
||||
|
||||
/* ************************************
|
||||
facteur de taille des clusters
|
||||
_
|
||||
valeur par defaut "2.5"
|
||||
************************************ */
|
||||
//$mp_settings_icon_size_factor = 4;
|
||||
@@ -29,9 +31,10 @@
|
||||
coordonnees par defaut
|
||||
(pour centrer la carte globale,
|
||||
et en cas de mauvaises adresses)
|
||||
_
|
||||
valeur par defaut "france"
|
||||
************************************ */
|
||||
//$mp_settings_coordinates_default = {lat:35.746512, lng:-39.462891}; // oceant atlantique nord
|
||||
$mp_settings_coordinates_default = (object)["lat" => 30.0, "lng" => -1.0]; // carte mieux centree
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +42,7 @@
|
||||
couleurs d'icones
|
||||
- couleur de contour
|
||||
- couleur de remplissage
|
||||
_
|
||||
valeurs par defaut "#ba197a"
|
||||
"#ffffff99"
|
||||
************************************ */
|
||||
@@ -59,9 +63,22 @@
|
||||
|
||||
/* ************************************
|
||||
epaisseur de trait des icones
|
||||
_
|
||||
valeurs par defaut "6"
|
||||
************************************ */
|
||||
$mp_settings_icon_stroke_width = 8;
|
||||
|
||||
|
||||
|
||||
|
||||
/* ************************************
|
||||
zoom automatique maximum sur les
|
||||
marqueurs
|
||||
_
|
||||
valeurs par defaut "5"
|
||||
************************************ */
|
||||
$mp_settings_max_zoom = 4;
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user