Home

Awesome

Tabris.js Maps Plugin

<a href="https://github.com/eclipsesource/tabris-plugin-maps/blob/master/.github/workflows/main.yml"><img alt="Tabris.js Maps Plugin status" src="https://github.com/eclipsesource/tabris-plugin-maps/workflows/Build%20example%20app/badge.svg"></a>

The tabris-plugin-maps plugin project provides a Tabris.js API to show and interact with a map widget. The plugin currently supports Android (via Google Maps) and iOS (via Map Kit).

Tabris maps on iOS and Android

Compatibility

Compatible with Tabris.js 3.2.0+. For older Tabris version see repository branches.

Example

The following snippet shows how the tabris-plugin-maps plugin can be used in a Tabris.js app:

new esmaps.Map({
  left: 0, right: 0, top: 0, bottom: 0
}).on('ready', function() {
  // show paris with a radius of 2000 meters
  this.moveToPosition([48.8644458, 2.3589976], 2000);
}).appendTo(tabris.ui.contentView);

A more elaborate example can be found in the example folder. It provides a Tabris.js app that demonstrates various features of the tabris-plugin-maps widget.

Integrating the plugin

The Tabris.js website provides detailed information on how to integrate custom widgets in your Tabris.js based app.

Add the plugin to your project

The plugin should be added as an entry in the apps config.xml file:

<plugin name="tabris-plugin-maps" spec="^5.0.0" />

To fetch the latest development version use the GitHub url:

<plugin name="tabris-plugin-maps" spec="https://github.com/eclipsesource/tabris-plugin-maps.git" />

Android

On Android a Google Maps API key has to be provided when adding the plugin to your Tabris.js app. The documentation for the Google Maps API explains how to acquire an API key.

The API key can be configured inside your app's config.xml:

<plugin name="tabris-plugin-maps" spec="^5.0.0">
  <variable name="ANDROID_API_KEY" value="$ANDROID_API_KEY" />
</plugin>

When the environment variable ANDROID_API_KEY is set, Tabris.js CLI will replace the value placeholder $ANDROID_API_KEY in the config.xml during build.

API documentation

The API consists of two objects: The esmaps.Map and the esmaps.Marker that can be created on an Map. Note that the properties and functions of the Map can only be accessed after the ready callback has fired.

Map

Properties

The following properties can be applied on top of the common Tabris.js properties. All properties can be read and written unless noted otherwise.

position : number[]
region : object
camera : object
showMyLocation : boolean, default: false
showMyLocationButton : boolean, default: false
myLocation : number[]
mapType : string, supported values: none, hybrid, normal, satellite, terrain, satelliteflyover, hybridflyover, default: normal

Events

ready
Event Parameters:
tap
Event Parameters:
longpress
Event Parameters:
cameraMoved
Event Parameters:
cameraChanged
Event Parameters:

Functions

moveToPosition(position, radius, [options])

The function moveToPosition() updates the cameras center to a new position and makes sure the given radius is fully contained in the visible region. This function resets the maps tilt.

Example:

map.moveToPosition([48.8644458, 2.3589976], 500, {padding: 16, animate: true});
Parameter

moveToRegion(region, [options])

The function moveToPosition() sets the cameras center to a new position and makes sure the given radius is fully contained in the visible region. This function resets the maps tilt.

Example:

map.moveToRegion({southWest: [48.8644458, 2.3589976], northEast: [48.8821597,2.3856527]},
                 {padding: 16, animate: true});
Parameter

addMarker(marker)

The function addMarker(marker) adds a marker to the map. When a map gets disposed all of its previously added markers are disposed with it.

removeMarker(marker)

The function removeMarker(marker) removes a marker from the map.

getMarkers()

The function getMarkers() returns an array of all currently added markers.

Parameter

Marker

A Marker is used to indicate places and positions on the Map.

Properties

position : number[]
image : Image

Events

tap

Functions

dispose()

Compatibility

Compatible with Tabris.js 2.4 and 2.5.

Development of the widget

While not required by the consumer of the widget, this repository provides Android specific development artifacts. These artifacts allow to more easily consume the native source code when developing the native parts of the widget.

Android

The project provides a gradle based build configuration, which also allows to import the project into Android Studio.

In order to reference the Tabris.js specific APIs, the environment variable TABRIS_ANDROID_PLATFORM has to point to the Tabris.js Android Cordova platform root directory.

export TABRIS_ANDROID_PLATFORM=/home/user/tabris-android

The environment variable is consumed in the gradle projects build.gradle file.

Copyright

Published under the terms of the BSD 3-Clause License.