Perspective - Map Scripting
This page details the component-specific events and functions available for Perspective's Map component. Right-click on the component or select Components from the Designer menubar to access the Configure Events and Configure Scripts popups.
Component Events​
The Perspective Event Types Reference page describes all the possible component event types for Perspective components.
onMarkerClick​
Interaction event. Fired when the marker is clicked. Returns the unique name of the marker.
| Object Path | Type | Description |
|---|---|---|
| event.name | String | The 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 Path | Type | Description |
|---|---|---|
| event.lat | Numeric | The latitude of where on the map the user clicked. |
| event.lng | Numeric | The 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 the mouse as it translates on the map.
| Object Path | Type | Description |
|---|---|---|
| event.lat | Numeric | The latitude of where the mouse moved. |
| event.lng | Numeric | The 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 Path | Type | Description |
|---|---|---|
| event.name | Any | The given name of the vector. Returns an empty string if a name is not defined. |
| event.type | String | The type of the vector clicked. Possible values are:- polygon - circle - polyline - rectangle |
| event.lat | Numeric | The latitude of the clicked vector. |
| event.lng | Numeric | The 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 Path | Type | Description |
|---|---|---|
| event.zoom | Numeric | What the zoom level on the map was before zooming. |
onZoom​
Map state event. Fired repeatedly during any change in zoom level, including zoom and fly animations. Returns the zoom level.
| Object Path | Type | Description |
|---|---|---|
| event.zoom | Numeric | What the zoom level was changed to. |
onZoomEnd​
Map state event. Fired when the map has changed, after any animations. Returns the zoom level.
| Object Path | Type | Description |
|---|---|---|
| event.zoom | Numeric | What 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 Path | Type | Description |
|---|---|---|
| event.lat | Numeric | The latitude of the center of the map before moving. |
| event.lng | Numeric | The longitude value for the center of the map before moving. |
onMove​
Map state event. Fires repeatedly during any movement on the map, including pan and fly animations. Returns the map center as lat and lng.
| Object Path | Type | Description |
|---|---|---|
| event.lat | Numeric | The latitude value for the center of the map during moving. |
| event.lng | Numeric | The 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 Path | Type | Description |
|---|---|---|
| event.lat | Numeric | The latitude value for the center of the map after moving. |
| event.lng | Numeric | The 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 Path | Type | Description |
|---|---|---|
| event.oldSize | PyJsonObjectAdapter | Returns 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.newSize | PyJsonObjectAdapter | Returns 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 map in latitude and longitude.
-
Parameters
- Nothing
-
Return
- LatLng - Returns the geographical center of the map view as
{"lat": number, "lng": number}.
- LatLng - Returns the geographical center of the map view as
.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 bounds of the map as a dictionary.
-
Parameters
- Nothing
-
Return
- Dictionary: A dictionary containing the following keys:
north: number
northEast: LatLng
east: number
southEast: LatLng
south: number
southWest: LatLng
west: number
northWest: LatLng
- Dictionary: A dictionary containing the following keys:
.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 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
.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 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 of 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.