EON Maps
Real-time location tracking powered by PubNub and MapBox or Google Maps.
Examples
Installing
Hotlink
Bower
bower install eon-map --save
Check out our bower example.
NPM
npm install eon-map --save
Check out our webpack example.
Quickstart
Call eon.map({})
. Check out the table of options below for more information.
Init
Parameter | Value | Default |
---|---|---|
id | The ID of the element where the map will be rendered. | undefined |
channels | An array of PubNub channels to subscribe to. Either channels or channelGroups must be supplied. |
false |
channelGroups | An array of PubNub channel groups to subscribe to. Either channels or channelGroups must be supplied. |
false |
transform | Method for changing the payload format of your stream. | function(m){} |
history | Use PubNub history call to retrieve last message. This will display points at their last known location. Requires PubNub storage to be enabled. | false |
pubnub | An instance of the PUBNUB javascript global. This is required when using your own keys. See the subscribeKey example. |
false |
connect | A function to call when PubNub makes a connection. See PubNub subscribe | function(){} |
marker | A custom Mapbox marker object. Use this to change the marker icon, tooltip, etc. | L.marker |
rotate | Add bearing to markers in options.angle . This won't have any effect unless you're using a rotated marker type. |
false |
provider | Google or Mapbox | mapbox |
mbToken | Mapbox API Token (Mapbox Only). | undefined |
mbId | Mapbox Map ID (MapBox Only). | undefined |
options | An options object supplied to the MapBox Maps constructor (MapBox Only). | {} |
googleKey | Google Maps API Key (Google Maps Only) | undefined |
googleMutant | Configure Google Maps Styles and Options as documented in Google Mutant Plugin | { type: 'roadmap'} |
Lat/Long Values
eon.map
expects an array of objects to be published on the same channel it's subscribed to. More on publishing in the next section.
For example, below you can find a list of all the Torchy's Tacos in Austin, TX.
var torchys = latlng: 30370375 -97756138 latlng: 30323118 -97739144 latlng: 30302816 -97699490 latlng: 30293479 -97742405 latlng: 30250337 -97754593 latlng: 30236689 -97762730 ;
Publishing Messages
The function below is called connect
and fires when the pubnub_mapbox
library is ready.
This function uses the included PubNub library to pubnub.publish() packets to the pubnub.subscribe() call waiting inside the Mapbox framework.
Notice how the subscribeKey
and channel
/channels
matches.
{ var point = latlng: 37370375 -97756138 ; var pn = publishKey: 'YOUR_PUB_KEY' // replace with your own pub-key subscribeKey: 'YOUR_SUB_KEY' // replace with your own sub-key ; ; }; var map = eon;
You probably want to publish data from the back-end instead. Check out our docs for more info:
http://www.pubnub.com/documentation/
Following a Point
You can tell the map to follow a point to it's new location whenever data is received by supplying a message
callback.
var pn = publishKey: 'YOUR_PUB_KEY' // replace with your own pub-key subscribeKey: 'YOUR_SUB_KEY' // replace with your own sub-key; var map = eon;
Marker Customization
You can supply a custom Mapbox marker object with custom tooltips by extening the L.marker
object provided by mapbox. Learn more about custom markers here.
Configure using your own PubNub API Keys
Using your own API Key with Eon Maps
You can set the pubnub
init parameter when using Eon Maps. This allows you to configure PubNub client connections with extra security options such a auth_key
and your cipher_key
. You should also set secure: true
and ssl: true
as well.
Kitchen Sink
Check out the bus.html
and flight.html
for full featured examples.
Customizing with Mapbox
The MapBox map object is returned by eon.mapbox
and can be customized using the Mapbox API. Also see the Mapbox examples page.
Also note that you can customize your map using Mapbox map editor. You can change the map background style, add static markers, etc. Visit Mapbox for your own API key.
Distributed Systems
The EON library compiles all messages at designated intervals. This means you can publish from multiple sources into one map. For example, you can map the individual locations of 3 phones by supplying the same channel to your PubNub publish requests. The flight example works like this; not every flight is updated on every subscribe call.