Skip to content

Commit

Permalink
spaces and dangles
Browse files Browse the repository at this point in the history
  • Loading branch information
amyleew committed Sep 3, 2015
1 parent 709d796 commit 85fe1f8
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 238 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"L": true
},
"rules": {
"indent": [2, 2],
"comma-dangle": [2, "never"],
"space-before-blocks": 2,
"space-after-keywords": 2,
"space-unary-ops": 2,
Expand Down
4 changes: 2 additions & 2 deletions i18n/de.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
name: "Deutsch",
name: "Deutsch",
'Link': 'Link',
'Open in editor': 'Im Editor öffnen',
'Open in JOSM': 'In JSOM öffnen',
'Download as GPX': 'Als GPX herunterladen',
'Short': 'Verkürzt',
'Select language and units': 'Sprache und Einheiten auswählen',
'Print': 'Drucken',
'Print': 'Drucken'
};
2 changes: 1 addition & 1 deletion i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = {
'Download as GPX': 'Download as GPX',
'Short': 'Short',
'Select language and units': 'Select language and units',
'Print': 'Print',
'Print': 'Print'
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "frontend interface for project osrm",
"main": "src/index.js",
"scripts": {
"test": "eslint src/index.js src",
"test": "eslint src/*js i18n/*.js",
"build": "browserify -d src/index.js -s osrm > bundle.js",
"build-print": "browserify -d src/index.print.js -s osrm > bundle.print.js",
"start-index": "budo src/index.js --serve=bundle.js --live -d | bistre",
Expand Down
30 changes: 15 additions & 15 deletions src/geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

var geocoder = function(i, num) {
var container = L.DomUtil.create('div',
function() {
if (i === 0) {
return "osrm-directions-origin";
} else if (i === num-1) {
return "osrm-directions-destination";
}
return "osrm-directions-via";
}()),
label = L.DomUtil.create('label', 'osrm-form-label', container),
input = L.DomUtil.create('input', '', container),
close = L.DomUtil.create('span', 'osrm-directions-icon osrm-close-icon', container),
name = String.fromCharCode(65 + i),
icon = L.DomUtil.create('div', 'leaflet-osrm-geocoder-label', label);
function() {
if (i === 0) {
return "osrm-directions-origin";
} else if (i === num - 1) {
return "osrm-directions-destination";
}
return "osrm-directions-via";
}()),
label = L.DomUtil.create('label', 'osrm-form-label', container),
input = L.DomUtil.create('input', '', container),
close = L.DomUtil.create('span', 'osrm-directions-icon osrm-close-icon', container),
name = String.fromCharCode(65 + i),
icon = L.DomUtil.create('div', 'leaflet-osrm-geocoder-label', label);
icon.innerHTML = name;
return {
container: container,
input: input,
closeButton: close,
closeButton: close
};
};

module.exports = geocoder;
module.exports = geocoder;
90 changes: 45 additions & 45 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';

var Geocoder = require('leaflet-control-geocoder');
Expand All @@ -15,7 +14,7 @@ var parsedOptions = links.parse(window.location.href);
var viewOptions = L.extend(mapView.defaultView, parsedOptions);

// Pass basemap layers
mapLayer = mapLayer.reduce( function (title, layer) {
mapLayer = mapLayer.reduce(function(title, layer) {
title[layer.label] = L.tileLayer(layer.tileLayer, {
id: layer.label
});
Expand All @@ -32,22 +31,22 @@ var map = L.map('map', {

/* Leaflet Controls */
L.control.layers(mapLayer, overlay, {
position: 'bottomleft',
}).addTo(map);
position: 'bottomleft'
}).addTo(map);

L.control.scale().addTo(map);

/* OSRM setup */
var ReversablePlan = L.Routing.Plan.extend({
createGeocoders: function () {
createGeocoders: function() {
var container = L.Routing.Plan.prototype.createGeocoders.call(this);
return container;
}
});

/* Setup markers */

function makeIcon (i, n) {
function makeIcon(i, n) {
var url = 'images/marker-via-icon-2x.png';
var markerList = ['images/marker-start-icon-2x.png', 'images/marker-end-icon-2x.png'];
if (i === 0) {
Expand All @@ -56,7 +55,8 @@ function makeIcon (i, n) {
iconSize: [20, 56],
iconAnchor: [10, 28]
});
} if (i === n - 1) {
}
if (i === n - 1) {
return L.icon({
iconUrl: markerList[1],
iconSize: [20, 56],
Expand All @@ -73,14 +73,14 @@ function makeIcon (i, n) {
var plan = new ReversablePlan([], {
geocoder: Geocoder.nominatim(),
routeWhileDragging: true,
createMarker: function (i, wp, n) {
createMarker: function(i, wp, n) {
var options = {
draggable: this.draggableWaypoints,
icon: makeIcon(i, n)
};
var marker = L.marker(wp.latLng, options);
marker.on('click', function () {
plan.spliceWaypoints(i, 1);
marker.on('click', function() {
plan.spliceWaypoints(i, 1);
});
return marker;
},
Expand All @@ -92,15 +92,16 @@ var plan = new ReversablePlan([], {
reverseWaypoints: true,
dragStyles: options.lrm.dragStyles,
geocodersClassName: options.lrm.geocodersClassName,
geocoderPlaceholder: function (i,n) {
geocoderPlaceholder: function(i, n) {
var startend = ['Start - press enter to drop marker', 'End - press enter to drop marker'];
var via = ['Via point - press enter to drop marker'];
if (i===0) {
return startend[0];
} if (i===(n-1)) {
return startend[1];
if (i === 0) {
return startend[0];
}
if (i === (n - 1)) {
return startend[1];
} else {
return via;
return via;
}
}
});
Expand All @@ -124,9 +125,8 @@ var control = L.Routing.control({
var toolsControl = tools.control(control, L.extend({
position: 'bottomleft',
language: mapView.language
}, options.tools)).addTo(map);
if (viewOptions.waypoints.length < 1) {
}
}, options.tools)).addTo(map);
if (viewOptions.waypoints.length < 1) {}
// set waypoints from hash values
if (viewOptions.waypoints.length > 1) {
control.setWaypoints(viewOptions.waypoints);
Expand All @@ -138,8 +138,8 @@ plan.on('waypointschanged', updateHash);
map.on('zoomend', mapZoom);
map.on('moveend', mapMove);

function mapChange (e) {
var length = control.getWaypoints().filter( function (pnt) {
function mapChange(e) {
var length = control.getWaypoints().filter(function(pnt) {
return pnt.latLng;
});
length = length.length;
Expand All @@ -151,21 +151,21 @@ function mapChange (e) {
}
}

function mapZoom (e) {
function mapZoom(e) {
var linkOptions = toolsControl._getLinkOptions();
var updateZoom = links.format(window.location.href, linkOptions);
history.replaceState( {} , 'Project OSRM Demo', updateZoom);
history.replaceState({}, 'Project OSRM Demo', updateZoom);
}

function mapMove (e) {
function mapMove(e) {
var linkOptions = toolsControl._getLinkOptions();
var updateCenter = links.format(window.location.href, linkOptions);
history.replaceState( {} , 'Project OSRM Demo', updateCenter);
history.replaceState({}, 'Project OSRM Demo', updateCenter);
}

// Update browser url
function updateHash (e) {
var length = control.getWaypoints().filter( function (pnt) {
function updateHash(e) {
var length = control.getWaypoints().filter(function(pnt) {
return pnt.latLng;
}).length;
var linkOptions = toolsControl._getLinkOptions();
Expand All @@ -176,12 +176,12 @@ function updateHash (e) {
var newParms = window.location.hash = hash[1];
var oldURL = window.location;
var newURL = newBaseURL.concat(newParms);
history.replaceState( {} , 'Directions', newURL);
history.replaceState({}, 'Directions', newURL);
}

// Update browser url
function updateSearch (e) {
var length = control.getWaypoints().filter( function (pnt) {
function updateSearch(e) {
var length = control.getWaypoints().filter(function(pnt) {
return pnt.latLng;
}).length;
var linkOptions = toolsControl._getLinkOptions();
Expand All @@ -191,7 +191,7 @@ function updateSearch (e) {
}

// User selected routes
control.on('alternateChosen', function (e) {
control.on('alternateChosen', function(e) {
var directions = document.querySelectorAll('.leaflet-routing-alt');
if (directions[0].style.display != 'none') {
directions[0].style.display = 'none';
Expand All @@ -203,17 +203,17 @@ control.on('alternateChosen', function (e) {
});

L.control.locate({
follow: false,
setView: true,
remainActive: false,
keepCurrentZoomLevel: true,
stopFollowingOnDrag: false,
onLocationError: function (err) {
alert(err.message)
},
onLocationOutsideMapBounds: function (context) {
alert(context.options.strings.outsideMapBoundsMsg);
},
showPopup: false,
locateOptions: {}
}).addTo(map);
follow: false,
setView: true,
remainActive: false,
keepCurrentZoomLevel: true,
stopFollowingOnDrag: false,
onLocationError: function(err) {
alert(err.message)
},
onLocationOutsideMapBounds: function(context) {
alert(context.options.strings.outsideMapBoundsMsg);
},
showPopup: false,
locateOptions: {}
}).addTo(map);
36 changes: 20 additions & 16 deletions src/index.print.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ var parsedOptions = links.parse(window.location.href);
var viewOptions = L.extend(mapView.defaultView, parsedOptions);

var map = L.map('map', {
zoomControl: false,
dragging: false,
scrollWheelZoom: false,
touchZoom: false,
doubleClickZoom: false,
layers: mapView.defaultView.layer,
maxZoom: 18
}
).setView(parsedOptions.center, viewOptions.zoom);
zoomControl: false,
dragging: false,
scrollWheelZoom: false,
touchZoom: false,
doubleClickZoom: false,
layers: mapView.defaultView.layer,
maxZoom: 18
}).setView(parsedOptions.center, viewOptions.zoom);

/* Setup markers */
function makeIcon (i, n) {
function makeIcon(i, n) {
var url = 'images/marker-icon-2x.png';
var markerList = ['images/marker-start-icon-2x.png', 'images/marker-end-icon-2x.png'];
if (i === 0) {
Expand All @@ -30,7 +29,8 @@ function makeIcon (i, n) {
iconSize: [20, 56],
iconAnchor: [10, 28]
});
} if (i === n - 1) {
}
if (i === n - 1) {
return L.icon({
iconUrl: markerList[1],
iconSize: [20, 56],
Expand All @@ -52,22 +52,26 @@ L.tileLayer('https://{s}.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}@2x.png?a
}).addTo(map);

var osrm = L.Routing.osrm();
var itinerary = L.Routing.itinerary({language: viewOptions.language});
var itinerary = L.Routing.itinerary({
language: viewOptions.language
});
var itineraryContainer = itinerary.onAdd(map);
document.getElementById("instructions").appendChild(itineraryContainer);

osrm.route(viewOptions.waypoints, function (error, alts) {
osrm.route(viewOptions.waypoints, function(error, alts) {
var altIdx = viewOptions.alternative ? viewOptions.alternative : 0;
var lineOptions = options.lrm.lineOptions;
var line = L.Routing.line(alts[alts.length - 1], lineOptions);
line.addTo(map);
map.fitBounds(line.getBounds());

viewOptions.waypoints.map(function (currentVal, i, n) {
var options = { icon: makeIcon(currentVal, n.length) };
viewOptions.waypoints.map(function(currentVal, i, n) {
var options = {
icon: makeIcon(currentVal, n.length)
};
var colorMarkers = L.marker(currentVal.latLng, options);
colorMarkers.addTo(map);
});
itinerary.setAlternatives(alts);
itinerary.selectAlternative(altIdx);
});
});
2 changes: 1 addition & 1 deletion src/itinerary_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var ItineraryBuilder = L.Class.extend({
},
createStep: function (text, distance, icon, steps) {
var row = L.DomUtil.create('li', 'osrm-directions-step', steps),
td;
td;
L.DomUtil.create('span', 'osrm-directions-icon osrm-'+icon+'-icon', row);
td = L.DomUtil.create('div', 'osrm-directions-step-maneuver', row);
td.appendChild(document.createTextNode(text));
Expand Down
Loading

0 comments on commit 85fe1f8

Please sign in to comment.