Skip to main content
Version: 8.1

Perspective - Map Scripting

This page details the various scripting, component, and extension functions available for Perspective's Map component.

Component Events

The Perspective Event Types Reference page describes all the possible component event types for Perspective components. Not all component events support each Perspective component. The Component Events and Actions page shows how to configure events and actions on a Perspective component. Component scripting is handled separately and can be accessed from the Component menubar or by right clicking on the component.

onMarkerClick

Interaction event. Fired when the marker is clicked. Returns the unique name of the marker.

Object PathTypeDescription
event.nameStringThe name of the marker.

onMapClick

Interaction event. Fired when the map is clicked. Returns the lat and lng of the mouse click as it translates on the map.

Object PathTypeDescription
event.latNumericThe latitude of where on the map the user clicked.
event.lngNumericThe longitude of where on the map the user clicked.

onMapMouseMove

Interaction event. Fires as the mouse moves over the map. Returns lat and lng of mouse as it translates on the map.

Object PathTypeDescription
event.latNumericThe latitude of where the mouse moved.
event.lngNumericThe longitude of where the mouse moved.

onVectorClick

Interaction event. Fired when a vector is clicked. Returns the name of the vector, the type of the vector, and the coordinates of the vector.

Object PathTypeDescription
event.nameAnyThe given name of the vector. Returns an empty string if a name is not defined.
event.typeStringThe type of the vector clicked. Possible values are:

- polygon
- circle
- polyline
- rectangle
event.latNumericThe latitude of the clicked vector.
event.lngNumericThe longitude of the clicked vector.

onZoomStart

Map state event. Fired when the map zoom is about to change (e.g. before zoom animation). Returns the zoom level.

Object PathTypeDescription
event.zoomNumericWhat the zoom level on the map was before zooming.

onZoom

Map state event. Fired repeatedly during any change in zoom level, included zoom and fly animations. Returns the zoom level.

Object PathTypeDescription
event.zoomNumericWhat the zoom level was changed to.

onZoomEnd

Map state event. Fired when the map has changed, after any animations. Returns the zoom level.

Object PathTypeDescription
event.zoomNumericWhat the zoom level on the map was after zooming.

onMoveStart

Map state event. Fired when the view of the map starts changing (e.g., user starts dragging the map). Returns the map center as lat and lng.

Object PathTypeDescription
event.latNumericThe latitude of the center of the map before moving.
event.lngNumericThe longitude value for the center of the map before moving.

onMove

Map state event. Fires repeatedly during any movement on the map, include pan and fly animations. Returns the map center as lat and lng.

Object PathTypeDescription
event.latNumericThe latitude value for the center of the map during moving.
event.lngNumericThe longitude value for the center of the map during moving.

onMoveEnd

Map state event. Fired when the center of the map stops changing (e.g. user stopped dragging the map). Returns the new map center as lat and lng.

Object PathTypeDescription
event.latNumericThe latitude value for the center of the map after moving.
event.lngNumericThe longitude value for the center of the map after moving.

onResize

Map state event. Fires when the map size has changed. Returns the map size as oldSize and newSize.

Object PathTypeDescription
event.oldSizePyJsonObjectAdapterReturns the starting size of the map before the resize. Values are returned in an object that's functionally similar to a Python dictionary. The object contains two values: height and width.
event.newSizePyJsonObjectAdapterReturns the starting size of the map after the resize. Values are returned in an object that's functionally similar to a Python dictionary. The object contains two values: height and width.

Component Functions

.getCenter()

  • Description

    • Returns the geographical center of the man in latitude and longitude.
  • Parameters

    • Nothing
  • Return

    • LatLng - Returns the geographical center of the map view as{ lat: number, lng: number } .

.getZoom()

  • Description

    • Returns the current zoom level of the map view as a number.
  • Parameters

    • Nothing
  • Return

    • Returns the current zoom level of the map view as a number.

.getBounds()

  • Description

    • Returns the geographical bound of the map as a dictionary.
  • Parameters

    • Nothing
  • Return

    • Dictonary A dictionary containing the following keys:
      north: number
      northEast: LatLng
      LatLngeast: number
      southEast: LatLng
      south: number
      southWest: LatLng
      west: number
      northWest: LatLng

.getBoundsAsBBoxString()

  • Description

    • Returns a string with bounding box coordinates in a 'South West longitude, South West latitude , North East longitude, North East latitude' format.
  • Parameters

    • Nothing
  • Return

    • Returns the bounding box of the map as a string.

.zoomIn([delta, options])

  • Description

    • Increases the zoom of the map by delta.
  • Parameters

    • Numeric delta - The numerical value to increase the zoom by. If omitted, uses the value of props.zoom.delta. [optional]
    • Dictionary options - A dictionary of parameters to use during the zoom, typically containing a single key, animate. See Perspective - Map ZoomOptions. [optional]
  • Return

    • Nothing

.zoomOut([delta, options])

  • Description

    • Decreases the zoom of the map by delta.
  • Parameters

    • Numeric delta - The numerical value to increase the zoom by. If omitted, uses the value of pro ps.zoom.delta. [optional]
    • Dictionary options - A dictionary of parameters to use during the zoom, typically containing a single key, animate. See Perspective - Map ZoomOptions. [optional]
  • Return

    • Nothing

.setZoomAround(point, zoom, [options])

  • Description

    • Zooms the map while keeping a specified geographical point on the map stationary (e.g. used internally for scroll zoom and double-click zoom)
  • Parameters

    • Dictionary point - The geographic point that the map will zoom around. See Perspective - Map#LatLng. [required]
    • Numeric zoom - The numerical value to increase the zoom by. If omitted, uses the value of props.zoom.delta. [optional]
    • Dictionary options - A dictionary of parameters to use during the zoom, typically containing a single key, animate. See Perspective - Map ZoomOptions. [optional]
  • Return

    • Nothing

.fitBounds(latLngBounds, [options])

  • Description
    • Sets a map view that contains the given geographical bounds with the maximum zoom level possible
  • Parameters
    • Dictionary latLngBounds - A dictionary consisting of two LatLng objects. The LatLng objects combined represent the geographical bounds the map view should be set to. [required]
    • Dictionary options - A dictionary of parameters used to manipulate the FitBound settings. See Perspective - Map FitBounds. [optional]
  • Return
    • Nothing

.fitWorld([options])

  • Description

    • Sets a map view that mostly contains the whole world with the maximum zoom level possible.
  • Parameters

    • Dictionary options - A dictionary of parameters used to manipulate the FitBound settings. See See Perspective - Map FitBounds. [optional]
  • Return

    • Nothing

.panTo(latLng, [options])

  • Description

    • Pans the map to a given center.
  • Parameters

    • Dictionary latLng - The geographic point to pan to. [required]
    • Dictionary options - A dictionary of parameters used to modify the panning behavior. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.panBy(point, [options])

  • Description

    • Pans the map by a given number of pixels (animated).
  • Parameters

    • Dictionary point - The geographic point to pan to. The dictionary should contain an 'x' and 'y' key, both with numeric values. [required]
    • Dictionary options - A dictionary of parameters used to modify the panning behavior. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.flyTo(latLng, [zoom, options])

  • Description

    • Sets the view of the map (geographical center and zoom) performing a smooth pan-zoom animation.
  • Parameters

    • Dictionary latLng - A Python Dictionary representing the coordinates to fly to. [required]
    • Numeric zoom - Sets the zoom level to transition to during the flight. If omitted, uses the value on props.zoom.delta. [optional]
    • Dictionary options - A dictionary of panning options to use. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.flyToBounds(latLngBounds, [options])

  • Description

    • Sets the view of the map with a smooth animation like flyTo, but takes a bounds parameter like fitBounds.
  • Parameters

    • Dictionary latLngBounds - A dictionary consisting of two LatLng objects. The LatLng objects combined represent the geographical bounds the map view should be set to. [required]
    • Dictionary options - A dictionary of panning options to use. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.panInsideBounds(latLngBounds, [options])

  • Description

    • Pans the map to the closest view that would lie inside the given bounds (if it's not already), controlling the animation using the options specific, if any.
  • Parameters

    • Dictionary latLngBounds - A dictionary consisting of two LatLng objects. The LatLng objects combined represent the geographical bounds the map view should be set to. [required]
    • Dictionary options - A dictionary of panning options to use. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.panInside(latLng, [options])

  • Description

    • Pans the map the minimum amount to make the latLng visible.
  • Parameters

    • Dictionary latLng - A Python dictionary representing the coordinates to pan to. [required]
    • Dictionary options - A dictionary of panning options to use. See Perspective - Map PanOptions. [optional]
  • Return

    • Nothing

.getSize()

  • Description

    • Returns height and width of the Map component.
  • Parameters

    • Nothing
  • Return

    • JSON Object - Returns a Python dictionary. Contains two items: height and width.

Scripting Example

def doMapStuff(self):
map = self.getSibling("Map")
coordinateBounds = {'corner1': {'lat': 39.086798, 'lng': -120.069014}, 'corner2': { 'lat': 38.815319, 'lng': -119.787519 }}
latLngTahoe = {'lat': 39.086798, 'lng': -120.069014 }
latLngInductive = {'lat': 38.652511, 'lng': -121.189438 }
zoomPanOptions = { 'animate': True, 'duration': 3, 'easeLinearity': 0.25, 'noMoveStart': False }
fitBoundsOptions = { 'padding': { 'x': 100, 'y': 100 }, 'animate': True, 'duration': 3 }
panPixels = { 'x': 200, 'y': 200 }


print map.getCenter()
# Returns the geographical bounds visible in the current map view as latLngBounds

map.flyTo(latLng = latLngTahoe, options = zoomPanOptions)
# Sets the view of the map with a smooth animation like flyTo, but takes a bounds parameter like fitBounds

Extension Functions

This component does not have extension functions associated with it.