-
-
Save ToeJamson/4cc8bb21b7e6606240ab to your computer and use it in GitHub Desktop.
Receiving and Displaying Vehicle Data with Automatic and MapBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var coffee = require('coffee-script'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = -> | |
L.mapbox.accessToken = '<your-mapbox-api-key>' | |
map = L.mapbox.map('map', '<your-map-code>') | |
map.setView [lat, lng], 5 | |
marker = L.marker [lat, lng], | |
icon: L.mapbox.marker.icon('marker-color': '#f86767') | |
marker.addTo map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if navigator.geolocation | |
navigator.geolocation.getCurrentPosition (position) -> | |
if locationMarker? | |
# return if there is a locationMarker bug | |
return | |
# sets default position to your position | |
lat = position.coords['latitude'] | |
lng = position.coords['longitude'] | |
pubs() | |
main() | |
(error) -> | |
console.log 'Error: ', error, | |
enableHighAccuracy: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/app.css', function(req, res) { | |
res.header('Content-Type', 'text/css'); | |
file = fs.readFileSync(__dirname + '/client/styles/css/app.css', 'ascii'); | |
res.send(file); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/:script.js', function(req, res) { | |
res.header('Content-Type', 'application/x-javascript'); | |
cs = fs.readFileSync(__dirname + '/client/js/' + | |
req.params.script + '.coffee', 'ascii'); | |
js = coffee.compile(cs); | |
res.send(js); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title= title | |
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js") | |
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js") | |
... | |
body | |
block content | |
script(src="/map_box_example.js") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout_template | |
block content | |
.container | |
h1 Application online | |
a.btn.btn-primary(href="/login"). | |
Login |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout_template | |
block content | |
.container | |
h1 MapBox Example | |
div#map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body, #map { | |
height: 700px; | |
margin: 0px; | |
padding: 0px | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lat = null | |
lng = null | |
map = undefined | |
marker = undefined | |
notificationType = undefined | |
vehicle = undefined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pubs = -> | |
pubnub = PUBNUB.init( | |
publish_key: 'publish_key_here' | |
subscribe_key: 'subscribe_key_here') | |
pubnub.subscribe | |
channel: 'automaticChannel' | |
message: (message, channel) -> | |
console.log message | |
lat = message.location.lat | |
lng = message.location.lon | |
notificationType = message.type | |
vehicle = message.vehicle.display_name | |
map.setView [lat,lng] | |
marker.setLatLng L.latLng(lat, lng) | |
marker.bindPopup("<p>#{notificationType}</p>" + | |
"<p>Vehicle: #{vehicle}</p>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment