public static function GetMapInfo($p_htmlDir = '', $p_websiteUrl = '', $p_mapProvider = '')
{
global $Campsite;
$cnf_html_dir = $Campsite['HTML_DIR'];
$cnf_website_url = $Campsite['WEBSITE_URL'];
$preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
if ('' != $p_htmlDir) {
$cnf_html_dir = $p_htmlDir;
}
if ('' != $p_websiteUrl) {
$cnf_website_url = $p_websiteUrl;
}
$map_width = $preferencesService->MapViewWidthDefault;
if (!$map_width) {
$map_width = 600;
}
$map_height = $preferencesService->MapViewHeightDefault;
if (!$map_height) {
$map_height = 400;
}
$map_view_long = $preferencesService->MapCenterLongitudeDefault;
$map_view_lat = $preferencesService->MapCenterLatitudeDefault;
$map_view_resol = $preferencesService->MapDisplayResolutionDefault;
if (!$map_view_long) {
$map_view_long = '14.424133';
}
if (!$map_view_lat) {
$map_view_lat = '50.089926';
}
if (!$map_view_resol) {
$map_view_resol = '4';
}
$use_single_provider = false;
// whether we already know which single map provider has to be used
if ('' != $p_mapProvider) {
$use_single_provider = true;
}
$map_prov_default = '';
if ($use_single_provider) {
$map_prov_default = $p_mapProvider;
} else {
$map_prov_default = $preferencesService->MapProviderDefault;
if (!$map_prov_default) {
$map_prov_default = '';
} else {
$map_prov_default = strtolower($map_prov_default);
}
}
// we only have support for googlev3 and osm/mapquest for now
$map_prov_names_arr = array('googlev3', 'osm', 'mapquest');
if ($use_single_provider) {
$map_prov_names_arr = array($p_mapProvider);
}
$map_prov_includes = array();
$map_prov_includes_async = array();
$map_prov_info_arr = array();
$map_prov_gv3_async = false;
$map_prov_gv3_async_method = '';
$known_providers = array('googlev3' => false, 'osm' => false);
$sys_pref_names = array('googlev3' => 'GoogleV3', 'osm' => 'OSM', 'mapquest' => 'MapQuest');
$usage_providers_count = 0;
$map_prov_first = '';
$map_prov_default_found = false;
foreach ($map_prov_names_arr as $one_prov_name) {
if ('' == $one_prov_name) {
continue;
}
if (!$use_single_provider) {
$one_prov_usage = $preferencesService->MapProviderAvailable . ucfirst($sys_pref_names[$one_prov_name]);
if (!$one_prov_usage) {
continue;
}
if (in_array(strtolower($one_prov_usage), array('0', 'false', 'no'))) {
continue;
}
}
$one_prov_include = '';
$one_prov_include_async = '';
if ('googlev3' == $one_prov_name) {
$one_prov_include = 'https://maps.google.com/maps/api/js?v=3.9&sensor=false';
$one_prov_include_async = 'https://maps.google.com/maps/api/js?v=3.9&sensor=false&callback=initialize_gv3async';
$map_prov_gv3_async_method = 'initialize_gv3async';
$map_prov_gv3_async = true;
}
// up to now, we know how to deal with just a few map providers
$one_prov_label = strtolower($one_prov_name);
if (!in_array($one_prov_label, $map_prov_names_arr)) {
continue;
}
$known_providers[$one_prov_label] = true;
if ($one_prov_include && '' != $one_prov_include) {
$map_prov_includes[] = $one_prov_include;
}
if ($one_prov_include_async && '' != $one_prov_include_async) {
$map_prov_includes_async[] = $one_prov_include_async;
}
if ('' == $map_prov_first) {
$map_prov_first = $one_prov_label;
}
if ($one_prov_label == $map_prov_default) {
$map_prov_default_found = true;
}
$usage_providers_count += 1;
}
if (!$map_prov_default_found) {
$map_prov_default = $map_prov_first;
}
// if nothing set to usage, use the all ones, with the default configuration
if (0 == $usage_providers_count) {
foreach ($known_providers as $one_prov => $one_state) {
$known_providers[$one_prov] = true;
}
$map_prov_default = 'googlev3';
$map_prov_includes[] = 'https://maps.google.com/maps/api/js?v=3.9&sensor=false';
$map_prov_includes_async[] = 'https://maps.google.com/maps/api/js?v=3.9&sensor=false&callback=initialize_gv3async';
$map_prov_gv3_async_method = 'initialize_gv3async';
$map_prov_gv3_async = true;
}
$providers_usage_arr = array();
foreach ($known_providers as $provider => $usage) {
if ($usage) {
$providers_usage_arr[] = $provider;
}
}
$res_map_info = array();
$res_map_info['default'] = $map_prov_default;
$res_map_info['longitude'] = $map_view_long;
$res_map_info['latitude'] = $map_view_lat;
$res_map_info['resolution'] = $map_view_resol;
$res_map_info['providers'] = $providers_usage_arr;
$res_map_info['width'] = $map_width;
$res_map_info['height'] = $map_height;
return array('json_obj' => $res_map_info, 'incl_obj' => $map_prov_includes, 'incl_obj_async' => $map_prov_includes_async, 'incl_gv3' => $map_prov_gv3_async, 'incl_gv3_init' => $map_prov_gv3_async_method);
}