Home Reference Source
public class | source

GoogleMapModel

Controls communication and handling of the Google Maps JavaScript API

Example:

const googleMap = new GoogleMapModel(
  'your-google-api-key',
  document.getElementById('some-map'),
  { center: { lat: 10.4657, lng: -66.8796 }, zoom: 12 }
);

Static Member Summary

Static Public Members
public static get

The callback name attached to the Google's script library

public static get

The callback name triggered when the Google's script library is called

Constructor Summary

Public Constructor
public

constructor(apiKey: String, $el: Element, options: google~MapOptions)

Initialises the map using Google Maps JavaScript API

Member Summary

Public Members
public

The element where the map will be rendered

public

Google's API key

public

The map instance from Google Maps JavaScript API

public

Google Maps options

Method Summary

Public Methods
public

addListener(name: String, callback: Function)

Adds map listener

public

Initialises the Google Maps JavaScript library and safely calls renderMap

public

Renders the map in the chosen $el

Static Public Members

public static get INIT_CALLBACK: String: string source

The callback name attached to the Google's script library

Return:

String

public static get READY_CALLBACK: String: string source

The callback name triggered when the Google's script library is called

Return:

String

Public Constructors

public constructor(apiKey: String, $el: Element, options: google~MapOptions) source

Initialises the map using Google Maps JavaScript API

Params:

NameTypeAttributeDescription
apiKey String

Google provides this in their console

$el Element

The element where the map will be rendered

options google~MapOptions

Google Maps options

Public Members

public $el: Element source

The element where the map will be rendered

public apiKey: String source

Google's API key

public map: google~Map source

The map instance from Google Maps JavaScript API

public options: google~MapOptions source

Google Maps options

Public Methods

public addListener(name: String, callback: Function) source

Adds map listener

Params:

NameTypeAttributeDescription
name String

The event name

callback Function

The event callback function

See:

public initGoogleMap(): Promise<google~Map> source

Initialises the Google Maps JavaScript library and safely calls renderMap

There are three ways this can go down:

  1. It's the first map added to the page and the script library has not been included yet
  2. The library was included and INIT_CALLBACK already triggered
  3. The library was included but it has not initialised yet

Return:

Promise<google~Map>

public renderMap(): google~Map source

Renders the map in the chosen $el

Return:

google~Map