Skip to content

MedUnes/map-trix

 
 

Repository files navigation

Map Trix : Google Maps Interface

npm

Description

This module provides an easy to use interface that allows to load and use Google Maps API.

Install

Available via npm as the package Map Trix.

npm install map-trix

Documentation and Usage

Load the lib and create an instance

import { createMapTrix } from 'map-trix'

// Google Maps lib options
const options = { language: 'en', version: 'weekly', /* TODO : to be completed */ }

/**
 * Load the lib and create an instance
 * @param {string} API_KEY : Your Google API Key
 * @param {object} options : { center: { lat: 0, lng: 0 }, zoom: 5 ... }
 * @param {object} config : { enableBounds: false }
 * @returns : MapTrix instance
 */ 
const mapTrix = await createMapTrix(API_KEY, options)

mapTrix.init('#YourMapElSelector')

Add marker

// Add marker without infoWindow
const point1 = {
    latitude: 48.85840, 
    longitude: 2.29448
}
mapTrix.addMarker(point)

// Add marker with infoWindow
const point2 = {
    latitude: 48.87574, 
    longitude: 2.29517, 
    content: 'infoWindow content'
}
mapTrix.addMarker(point2, true)

// Center map on loaded markers
mapTrix.boundsMarkers()

Create route between two points

/**
 * @param {String|{latitude, longitude}} origin
 * @param {String|{latitude, longitude}} destination
 */
mapTrix.traceDirection(point1, point2).then( successResponse => /* Your code here */ )

Load current location

/**
 * Load current user position
 * @param {enableHighAccuracy = true, timeout = 5000, maximumAge = 0}
 */
mapTrix.getCurrentPosition().then( res => {
    // Your code here...
    // for example
    mapTrix.addMarker({latitude: res.coords.latitude, longitude: res.coords.longitude, content: 'My position'}, true)
})

About

This module provides an easy to use interface that allows to load and use Google Maps API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 96.9%
  • JavaScript 3.1%