Function Reference: geodir_draw_map

Summary

Display the google map html.

Global Values

$map_canvas_arr
(array) (required) Array of map canvas data.

Default: None

Parameters

$map_args
(array) (required) {
Array of map arguments to use in map options. @type string $width Map width. @type string $height Map height. @type string $child_collapse Collapse filter div?. @type string $sticky Todo: desc needed. @type bool $enable_map_resize_button Do you want to enable map resize button?. @type bool $enable_cat_filters Do you want to enable category filters?. @type bool $enable_text_search Do you want to enable text search?. @type bool $enable_post_type_filters Do you want to enable post type filters?. @type bool $enable_location_filters Do you want to enable location filters?. @type bool $enable_jason_on_load Do you want to enable json on load?. @type bool $enable_map_direction Do you want to enable map directions?. @type bool $enable_marker_cluster Do you want to enable marker cluster?. @type string $ajax_url Map ajax url. @type string $map_canvas_name Map canvas name. @type string $inputText Text search placeholder. @type string $latitude Map default latitude. @type string $longitude Map default longitude. @type string $zoom Map default zoom. @type string $scrollwheel Map default scroll wheel level. @type bool $streetViewControl Display street view control?. @type string $maptype Map type. @type string $showPreview Show preview?. @type int $maxZoom Map maximum zoom level. @type int $autozoom Map auto zoom level. @type string $bubble_size Map bubble size. @type string $token Map token. @type array $navigationControlOptions {
Options of navigation control. @type string $position Navigation position. @type string $style Navigation style. }
@type string $map_class_name Map class name. @type bool $is_geodir_home_map_widget Is this a home page map? True if the current page is home. }.

Default: None

Return Values

(string|void)
  • Html content for google map.

Change Log

Since: 1.0.0

Actions

‘geodir_map_after_render’ [Line: 511]

Filters

‘geodir_map_options_{$map_canvas_name}’ [Line: 150]

‘geodir_map_post_type_list_{$map_canvas_name}’ [Line: 161]

‘geodir_exclude_post_type_on_map_{$map_canvas_name}’ [Line: 170]

‘geodir_change_map_width’ [Line: 192]

‘geodir_default_map_search_pt’ [Line: 325]

Source File

geodir_draw_map() is located in geodirectory-functions/map-functions/map_template_tags.php [Line: 68]

Source Code

function geodir_draw_map($map_args = array())
{
    global $map_canvas_arr;
    $map_canvas_name = (!empty($map_args) && $map_args['map_canvas_name'] != '') ? $map_args['map_canvas_name'] : 'home_map_canvas';
    $map_class_name = (!empty($map_args) && isset($map_args['map_class_name'])) ? $map_args['map_class_name'] : '';

    $default_location = geodir_get_default_location();

    $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : '';
    $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : '';
    $map_default_zoom = 12;
    // map options default values
    $width = 950;
    $height = 450;
    $child_collapse = '0';
    $sticky = '';
    $enable_cat_filters = false;
    $enable_text_search = false;
    $enable_post_type_filters = false;
    $enable_location_filters = false;
    $enable_jason_on_load = false;
    $enable_map_direction = false;
    $enable_marker_cluster = false;
    $enable_map_resize_button = false;
    $maptype = 'ROADMAP';

    $geodir_map_options = array(
        'width' => $width,
        'height' => $height,
        'child_collapse' => $child_collapse,
        'sticky' => $sticky,
        'enable_map_resize_button' => $enable_map_resize_button,
        'enable_cat_filters' => $enable_cat_filters,
        'enable_text_search' => $enable_text_search,
        'enable_post_type_filters' => $enable_post_type_filters,
        'enable_location_filters' => $enable_location_filters,
        'enable_jason_on_load' => $enable_jason_on_load,
        'enable_map_direction' => $enable_map_direction,
        'enable_marker_cluster' => $enable_marker_cluster,
        'ajax_url' => geodir_get_ajax_url(),
        'map_canvas_name' => $map_canvas_name,
        'inputText' => __('Title or Keyword', 'geodirectory'),
        'latitude' => $map_default_lat,
        'longitude' => $map_default_lng,
        'zoom' => $map_default_zoom,
        'scrollwheel' => true,
        'streetViewControl' => true,
        'fullscreenControl' => false,
        'maptype' => $maptype,
        'showPreview' => '0',
        'maxZoom' => 21,
        'autozoom' => true,
        'bubble_size' => 'small',
        'token' => '68f48005e256696074e1da9bf9f67f06',
        'navigationControlOptions' => array('position' => 'TOP_LEFT', 'style' => 'ZOOM_PAN')
    );



    if (!empty($map_args)) {
        foreach ($map_args as $map_option_key => $map_option_value) {
            $geodir_map_options[$map_option_key] = $map_option_value;
        }
    }

    if (strpos($geodir_map_options['height'], '%') !== false || strpos($geodir_map_options['height'], 'px') !== false || strpos($geodir_map_options['height'], 'vh') !== false) {
    } else {
        $geodir_map_options['height'] = $geodir_map_options['height'] . 'px';
    }

    if (strpos($geodir_map_options['width'], '%') !== false || strpos($geodir_map_options['width'], 'px') !== false) {
    } else {
        $geodir_map_options['width'] = $geodir_map_options['width'] . 'px';
    }

    /**
	 * Filter the options to use in google map.
	 *
	 * @since 1.0.0
	 *
	 * @param array $geodir_map_options {@see geodir_draw_map()} docblock.
	 */
	$geodir_map_options = apply_filters("geodir_map_options_{$map_canvas_name}", $geodir_map_options);

    $map_canvas_arr[$map_canvas_name] = array();

    /**
	 * Filter the post types to display data on map.
	 *
	 * @since 1.0.0
	 *
	 * @param object $object Objects of post types.
	 */
	$post_types = apply_filters("geodir_map_post_type_list_{$map_canvas_name}", geodir_get_posttypes('object'));
    
	/**
	 * Filter the post types to exclude to display data on map.
	 *
	 * @since 1.0.0
	 *
	 * @param array Array of post types to exclude to display data on map.
	 */
	$exclude_post_types = apply_filters("geodir_exclude_post_type_on_map_{$map_canvas_name}", get_option('geodir_exclude_post_type_on_map'));

    if (count((array)$post_types) != count($exclude_post_types) || ($enable_jason_on_load)):
        // Set default map options

        wp_enqueue_script('geodir-map-widget', geodir_plugin_url() . '/geodirectory-functions/map-functions/js/map.min.js',array(),false,true);

        wp_localize_script('geodir-map-widget', $map_canvas_name, $geodir_map_options);

        if ($map_canvas_name == 'detail_page_map_canvas' || $map_canvas_name == 'preview_map_canvas') {
            $map_width = '100%';
        } else {
            $map_width = $geodir_map_options['width'];
        }

        /**
		 * Filter the width of map.
		 *
		 * @since 1.0.0
		 *
		 * @param int $map_width Width of map box, eg: gd_place.
		 */
		$map_width = apply_filters('geodir_change_map_width', $map_width);
        ?>
        
>
Google Map Not Loaded

Sorry, unable to load Google Maps API.', 'geodirectory'); ?>

get('homemap_catlist_ptype'); if ($homemap_catlist_ptype) { $geodir_default_map_search_pt = $homemap_catlist_ptype; } /** * Filter the post type to retrieve data for map * * @since 1.0.0 * * @param string $geodir_default_map_search_pt Post type, eg: gd_place. */ $map_search_pt = apply_filters('geodir_default_map_search_pt', $geodir_default_map_search_pt); ?>
1 ? ' map-cat-ptypes' : ' map-cat-floor'; } ?>
checked="checked" style="max-height:;">
1) { ?>