Home

Awesome

Mapbox Framer Module

license PRs Welcome Maintenance

Simplest way to integrate Mapbox maps on your prototypes; you can define size, zoom, center point and even it lets you to use the full API. Obviously you need an active internet connection to load the maps.

mapbox gif

Installation

<a href='https://open.framermodules.com/Mapbox%20JS'> <img alt='Install with Framer Modules' src='https://www.framermodules.com/assets/badge@2x.png' width='160' height='40' /> </a>

Manual

  1. Copy the MapboxJS.coffee file to the ‘modules’ folder inside your Framer project
  2. Add this line on the top
{MapboxJS, CustomMarker, Marker, animateMarker} = require 'MapboxJS'

How to use

Init the map with your accessToken, generate it on Mapbox website, it's free. Without this, the map won't work.

myMap = new MapboxJS
  accessToken: 'insertHereYourAccessToken'

Customization

* Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.

Methods

Interact with Mapbox API

Read Mapbox GL JS documentation to learn how to use the API.

Some extra elements require to load other Mapbox JS files, for example if you want to add a search box (geocoder), this example could help you.

Add a marker with animation

# Latitude and Longitude points
centerPoint = [-3.70346, 40.41676]
startPoint = [-3.70773, 40.42135]
endPoint = [-3.702478, 40.41705]

# Create the map
myMap = new mapboxJS
  accessToken: 'insertHereYourAccessToken'
  style: 'yourCustomStyleURL'
  center: centerPoint

# Create a maker using the Layer's attributes and put it into the map
simpleMarker = new Marker
  map: myMap.mapbox
  lngLat: endPoint
  size: 20
  borderRadius: 40
  backgroundColor: "#FF0000"

scaleUp = new Animation simpleMarker,
  size: 30
  options: time: 1, curve: Bezier.ease
scaleUp.start()
scaleDown = scaleUp.reverse()

scaleUp.onAnimationEnd -> scaleDown.start()
scaleDown.onAnimationEnd -> scaleUp.start()

Add a marker from the Design tab

customMarker = new CustomMarker
  map: myMap.mapbox
  lngLat: startPoint
  element: targetName # Target must be a frame

Paint route between two points

route = new PaintRoute
  id: 'route-1' # Must be a unique name
  map: myMap.mapbox
  start: startPoint
  end: endPoint
  layout: { 'line-cap': 'round' }
  paint: { 'line-width': 2, 'line-color': '#FF0000', "line-dasharray": [1, 2, 0]}

Read more about now to use the layout and paint properties.

Animate marker through a route

animateMarker(customMarker, endPoint, 0.01)

Animate map to certain point

myMap.flyTo(endPoint)

Create 3D map


# use build3D method on mapobject load, mind that  bearing, hash and pitch should be set at mapbox initialization
myMap = new MapboxJS
  accessToken: mapboxToken	
  style: styles.light
  zoom: 12
  center: originPoint
  pitch: 45,
  bearing: -17.6,
  hash: true
myMap.mapbox.on 'load', ->
  myMap.build3d()

Sample project

Framer prototype

mapbox gif 2

Contact & Credits

You can find us on Twitter @NocheVolta, @mamezito

Inspirated on this project made by John Sherwin.

This project is not realted to the Mapbox company.