# Class: Map

## Map

WPGMZA.Map

#### new Map(element [, options])

  Base class for maps. Please do not call this constructor directly. Always use createInstance rather than instantiating this class directly. Using createInstance allows this class to be externally extensible.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `element` | HTMLElement |  | to contain map
  `options` | object | <optional> | Options to apply to this map

### Extends

- WPGMZA.EventDispatcher

### Methods

#### <static> createInstance(element [, options])

  Creates an instance of a map, please always use this function rather than calling the constructor directly.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `element` | HTMLElement |  | to contain map
  `options` | object | <optional> | Options to apply to this map

  ##### Returns:

  An instance of WPGMZA.Map
  Type
    WPGMZA.Map

#### <static> getConstructor()

  Returns the contructor to be used by createInstance, depending on the selected maps engine.

  ##### Returns:

  The appropriate contructor
  Type
    function

#### <static> getGeographicDistance(lat1, lon1, lat2, lon1)

  This gets the distance in kilometers between two latitude / longitude points TODO: Move this to the distance class, or the LatLng class

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `lat1` | number | Latitude from the first coordinate pair
  `lon1` | number | Longitude from the first coordinate pair
  `lat2` | number | Latitude from the second coordinate pair
  `lon1` | number | Longitude from the second coordinate pair

  ##### Returns:

  The distance between the latitude and longitudes, in kilometers
  Type
    number

#### _triggerListeners()

  Handles the logic of triggering listeners
  Inherited From:
    - WPGMZA.EventDispatcher#_triggerListeners

#### addCircle(circle)

  Adds the specified circle to this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `circle` | WPGMZA.Circle | The circle to add

  ##### Fires:

  - event:polygonadded

  ##### Throws:

  Argument must be an instance of WPGMZA.Circle

#### addEventListener(type, callback [, thisObject] [, useCapture])

  Adds an event listener on this object

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `type` | string |  | The event type, or multiple types separated by spaces
  `callback` | function |  | The callback to call when the event fires
  `thisObject` | object | <optional> | The object to use as "this" when firing the callback
  `useCapture` | bool | <optional> | If true, fires the callback on the capture phase, as opposed to bubble phase

  Inherited From:
    - WPGMZA.EventDispatcher#addEventListener

#### addMarker(marker)

  Adds the specified marker to this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `marker` | WPGMZA.Marker | The marker to add

  ##### Fires:

  - event:markeradded
  - WPGMZA.Marker#event:added

  ##### Throws:

  Argument must be an instance of WPGMZA.Marker

#### addPolygon(polygon)

  Adds the specified polygon to this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `polygon` | WPGMZA.Polygon | The polygon to add

  ##### Fires:

  - event:polygonadded

  ##### Throws:

  Argument must be an instance of WPGMZA.Polygon

#### addPolyline(polyline)

  Adds the specified polyline to this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `polyline` | WPGMZA.Polyline | The polyline to add

  ##### Fires:

  - event:polylineadded

  ##### Throws:

  Argument must be an instance of WPGMZA.Polyline

#### deleteCircleByID(id)

  Removes a circle by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the circle to remove

#### deletePolygon(polygon)

  Removes the specified polygon from this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `polygon` | WPGMZA.Polygon | The polygon to remove

  ##### Fires:

  - event:polygonremoved

  ##### Throws:

  - Argument must be an instance of WPGMZA.Polygon
  - Wrong map error

#### deletePolygonByID(id)

  Removes a polygon by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the polygon to remove

#### deletePolyline(polyline)

  Removes the specified polyline from this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `polyline` | WPGMZA.Polyline | The polyline to remove

  ##### Fires:

  - event:polylineremoved

  ##### Throws:

  - Argument must be an instance of WPGMZA.Polyline
  - Wrong map error

#### deletePolylineByID(id)

  Removes a polyline by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the polyline to remove

#### dispatchEvent(event)

  Fires an event on this object

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `event` | string | WPGMZA.Event | Either the event type as a string, or an instance of WPGMZA.Event

  Inherited From:
    - WPGMZA.EventDispatcher#dispatchEvent

#### getCircleByID(id)

  Gets a circle by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the circle to get

  ##### Returns:

  The circle, or null if no circle with the specified ID is found
  Type
    WPGMZA.Circle | null

#### getMarkerByID(id)

  Gets a marker by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the marker to get

  ##### Returns:

  The marker, or null if no marker with the specified ID is found
  Type
    WPGMZA.Marker | null

#### getPolygonByID(id)

  Gets a polygon by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the polygon to get

  ##### Returns:

  The polygon, or null if no polygon with the specified ID is found
  Type
    WPGMZA.Polygon | null

#### getPolylineByID(id)

  Gets a polyline by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the polyline to get

  ##### Returns:

  The polyline, or null if no polyline with the specified ID is found
  Type
    WPGMZA.Polyline | null

#### hasEventListener(type)

  Test for listeners of type on this object

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `type` | string | The event type to test for

  Inherited From:
    - WPGMZA.EventDispatcher#hasEventListener

  ##### Returns:

  True if this object has listeners bound for the specified type
  Type
    bool

#### loadSettings()

  Loads the maps settings and sets some defaults

#### nudge(x, y)

  Nudges the map viewport by the given pixel coordinates

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `x` | number | Number of pixels to nudge along the x axis
  `y` | number | Number of pixels to nudge along the y axis

  ##### Throws:

  Invalid coordinates supplied

#### off()

  Alias for removeEventListener
  Inherited From:
    - WPGMZA.EventDispatcher#off
  See:
    - WPGMZA.EventDispatcher#removeEventListener

#### on()

  Alias for addEventListener
  Inherited From:
    - WPGMZA.EventDispatcher#on
  See:
    - WPGMZA.EventDispatcher#addEventListener

#### onBoundsChanged()

  Called when the map viewport bounds change. Fires the legacy bounds_changed event.

  ##### Fires:

  - event:boundschanged
  - event:bounds_changed

#### onElementResized()

  Called when the engine map div is resized

#### onIdle()

  Called when the map viewport becomes idle (eg movement done, tiles loaded)

  ##### Fires:

  - event:idle

#### onWindowResize()

  Called when the window resizes

#### removeCircle(circle)

  Removes the specified circle from this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `circle` | WPGMZA.Circle | The circle to remove

  ##### Fires:

  - event:circleremoved

  ##### Throws:

  - Argument must be an instance of WPGMZA.Circle
  - Wrong map error

#### removeEventListener(type [, listener] [, thisObject] [, useCapture])

  Removes event listeners from this object

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `type` | string |  | The event type to remove listeners from
  `listener` | function | <optional> | The function to remove. If omitted, all listeners will be removed
  `thisObject` | object | <optional> | Use the parameter to remove listeners bound with the same thisObject
  `useCapture` | bool | <optional> | Remove the capture phase event listener. Otherwise, the bubble phase event listener will be removed.

  Inherited From:
    - WPGMZA.EventDispatcher#removeEventListener

#### removeMarker(marker)

  Removes the specified marker from this map

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `marker` | WPGMZA.Marker | The marker to remove

  ##### Fires:

  - event:markerremoved
  - WPGMZA.Marker#event:removed

  ##### Throws:

  - Argument must be an instance of WPGMZA.Marker
  - Wrong map error

#### removeMarkerByID(id)

  Removes a marker by ID

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `id` | int | The ID of the marker to remove

  ##### Fires:

  - event:markerremoved
  - WPGMZA.Marker#event:removed

#### setCenter(latLng)

  Centers the map on the supplied latitude and longitude

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `latLng` | object | WPGMZA.LatLng | A LatLng literal or an instance of WPGMZA.LatLng

#### setDimensions(width, height)

  Sets the dimensions of the map engine element

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `width` | number | Width as a CSS string
  `height` | number | Height as a CSS string

#### setOptions()

  Sets options in bulk on map

#### trigger()

  Alias for removeEventListener
  Inherited From:
    - WPGMZA.EventDispatcher#trigger
  See:
    - WPGMZA.EventDispatcher#removeEventListener

#### Search results