Geo_Preferences::GetMapInfo PHP Method

GetMapInfo() public static method

Gets info on map view
public static GetMapInfo ( string $p_htmlDir = '', string $p_websiteUrl = '', $p_mapProvider = '' ) : array
$p_htmlDir string
$p_websiteUrl string
return array
    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);
    }

Usage Example

Example #1
0
    /**
     * Gives the header part for the map front end search by map-based rectangle selection
     * the optional p_bboxDivs array of divs for automatical setting of the box corners coordinates.
     * The bounding-box corners are available by js calls too (see e.g. locations/search.php).
     *
     * @param int $p_mapWidth
     * @param int $p_mapHeight
     * @param mixed $p_bboxDivs
     *
     * @return string
     */
    public static function GetMapSearchHeader($p_mapWidth = 0, $p_mapHeight = 0, $p_bboxDivs = null)
    {
        global $Campsite;
        $tag_string = '';
        $map_suffix = '_search';
        $cnf_html_dir = $Campsite['HTML_DIR'];
        $cnf_website_url = $Campsite['WEBSITE_URL'];
        $map_provider = Geo_Preferences::GetMapProviderDefault();
        $geo_map_info = Geo_Preferences::GetMapInfo($cnf_html_dir, $cnf_website_url, $map_provider);
        if (0 < $p_mapWidth) {
            $geo_map_info['width'] = $p_mapWidth;
        }
        if (0 < $p_mapHeight) {
            $geo_map_info['height'] = $p_mapHeight;
        }
        $geo_map_incl = Geo_Preferences::PrepareMapIncludes($geo_map_info['incl_obj']);
        $geo_map_json = '';
        $geo_map_json .= json_encode($geo_map_info['json_obj']);
        $geo_icons_info = Geo_Preferences::GetSearchInfo($cnf_html_dir, $cnf_website_url);
        $geo_icons_json = '';
        $geo_icons_json .= json_encode($geo_icons_info['json_obj']);
        $geocodingdir = $Campsite['WEBSITE_URL'] . '/js/geocoding/';
        $tag_string .= $geo_map_incl;
        $tag_string .= "\n";
        $tag_string .= '

    <script type="text/javascript" src="' . $Campsite['WEBSITE_URL'] . '/js/geocoding/map_popups.js"></script>
    <script type="text/javascript" src="' . $Campsite['WEBSITE_URL'] . '/js/geocoding/openlayers/OpenLayers.js"></script>
    <script type="text/javascript" src="' . $Campsite['WEBSITE_URL'] . '/js/geocoding/openlayers/OLlocals.js"></script>
    <script type="text/javascript" src="' . $Campsite['WEBSITE_URL'] . '/js/geocoding/map_search.js"></script>

<script type="text/javascript">

    geo_object' . $map_suffix . ' = new geo_locations();

var useSystemParameters = function()
{
';
        $tag_string .= "\n";
        $tag_string .= "geo_object{$map_suffix}.set_map_info({$geo_map_json});";
        $tag_string .= "\n";
        $tag_string .= "geo_object{$map_suffix}.set_icons_info({$geo_icons_json});";
        $tag_string .= "\n";
        if ($p_bboxDivs) {
            $bbox_divs_json = '';
            $bbox_divs_json .= json_encode($p_bboxDivs);
            $tag_string .= "geo_object{$map_suffix}.set_bbox_divs({$bbox_divs_json});";
            $tag_string .= "\n";
        }
        $tag_string .= '
};
var on_load_proc = function()
{

    var map_obj = document.getElementById ? document.getElementById("geo_map_mapcanvas' . $map_suffix . '") : null;
    if (map_obj)
    {
        map_obj.style.width = "' . $geo_map_info['width'] . 'px";
        map_obj.style.height = "' . $geo_map_info['height'] . 'px";

        geo_main_selecting_locations(geo_object' . $map_suffix . ', "' . $geocodingdir . '", "geo_map_mapcanvas' . $map_suffix . '", "map_sidedescs", "", "", true);

    }
};
    $(document).ready(function()
    {
        on_load_proc();
    });
</script>
';
        return $tag_string;
    }
All Usage Examples Of Geo_Preferences::GetMapInfo