You are here

public function IpGeoLocAPI::outputMap in IP Geolocation Views & Maps 8

Outputs an HTML div placeholder into which will be injected a map.

The map is centered on the supplied lat,long coordinates. Handy for use in Views.

Parameters

string|float $latitude: E.g. "-37.87" or -37.87.

string|float $longitude: E.g. "144.98" or 144.98.

string $div_id: Id of the div placeholder, can be anything as long as it's unique.

string $style: CSS style applied to the div, e.g "height:250px; width:300px".

string $balloon_text: Text for hover or click.

File

src/Services/IpGeoLocAPI.php, line 151

Class

IpGeoLocAPI
Class IpGeoAPI to interact with other modules.

Namespace

Drupal\ip_geoloc\Services

Code

public function outputMap($latitude, $longitude, $div_id = 'ip-geoloc-map', $style = '', $balloon_text = '') {
  drupal_add_js(IP_GEOLOC_GOOGLE_MAPS, [
    'type' => 'external',
    'group' => JS_LIBRARY,
  ]);
  drupal_add_js(drupal_get_path('module', 'ip_geoloc') . '/js/ip_geoloc_gmap.js');
  $script_code = "displayGMap({$latitude}, {$longitude}, '{$div_id}', '{$balloon_text}');";
  drupal_add_js($script_code, [
    'type' => 'inline',
    'scope' => 'footer',
  ]);
  $map_placeholder = "<div id='{$div_id}'" . (empty($style) ? '' : " style='{$style}'") . '></div>';
  return $map_placeholder;
}