Skip to content

Commit

Permalink
set routing toggle.
Browse files Browse the repository at this point in the history
bike,4x4 routing is now hidden.
added ctrl+z for undo.
changed default enable behaviour of drawings.
added last position to local storage.
added todos.
  • Loading branch information
HarelM committed Jul 22, 2015
1 parent 6df4380 commit e38a7cd
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 22 deletions.
9 changes: 5 additions & 4 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module IsraelHiking {
// HM TODO: route length.
// HM TODO: better middle marker support.
// HM TODO: snapping.
// HM TODO: confirm on delete.
// HM TODO: height graph?
// HM TODO: url to route (address/?url=)
// HM TODO: support twl? - will be solved hopefull with iis backend.
// HM TODO: add waiting animation when routing works (Not sure I'll bother doing it in the end)


export var app = angular.module("IsraelHiking", ["ngFileUpload", "mgcrea.ngStrap", "LocalStorageModule"]);

Expand All @@ -21,9 +22,9 @@
[Common.Constants.q, Common.Constants.compile, Common.Constants.rootScope, Common.Constants.mapService, Common.Constants.routerFactory, Common.Constants.hashService,
($q: angular.IQService, $compile: angular.ICompileService, $rootScope: angular.IRootScopeService, mapService: Services.MapService, routeFactory: Services.Routers.RouterFactory, hashService: Services.HashService) =>
new Services.Drawing.DrawingFactory($q, $compile, $rootScope, mapService, routeFactory, hashService)]);
app.service(Common.Constants.hashService, [Common.Constants.location, Common.Constants.rootScope,
($location: angular.ILocationService, $rootScope: angular.IRootScopeService) =>
new Services.HashService($location, $rootScope)]);
app.service(Common.Constants.hashService, [Common.Constants.location, Common.Constants.rootScope, Common.Constants.localStorageService,
($location: angular.ILocationService, $rootScope: angular.IRootScopeService, localStorageService: angular.local.storage.ILocalStorageService) =>
new Services.HashService($location, $rootScope, localStorageService)]);
app.service(Common.Constants.controlCreatorService, [Common.Constants.rootScope, Common.Constants.compile, ($rootScope: angular.IScope, $compile: angular.ICompileService) => new Services.ControlCreatorService($rootScope, $compile)]);
app.service(Common.Constants.layersService, [Common.Constants.mapService, Common.Constants.localStorageService, Common.Constants.drawingFactory, Common.Constants.hashService,
(mapService: Services.MapService, localStorageService: angular.local.storage.ILocalStorageService, drawingFactory: Services.Drawing.DrawingFactory, hashService: Services.HashService) =>
Expand Down
21 changes: 15 additions & 6 deletions controllers/DrawingController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IsraelHiking.Controllers {
export interface IDrawingScope extends angular.IScope {
toggleDrawing(e: Event): void;
setRouting(routingType: string, e: Event): void;
toggleRouting(routingType: string, e: Event): void;
undo(e: Event): void;
isDrawingEnabled(): boolean;
getRoutingType(): string;
Expand Down Expand Up @@ -36,8 +36,12 @@
this.suppressEvents(e);
};

$scope.setRouting = (routingType: string, e: Event) => {
this.selectedDrawing.changeRoutingType(routingType);
$scope.toggleRouting = (routingType: string, e: Event) => {
if (this.selectedDrawing.getRoutingType() == routingType) {
this.selectedDrawing.changeRoutingType(Common.routingType.none);
} else {
this.selectedDrawing.changeRoutingType(routingType);
}
this.suppressEvents(e);
};

Expand All @@ -63,11 +67,16 @@
}

document.onkeydown = (e: KeyboardEvent) => {
if (e.keyCode != 27) {
if (e.keyCode == 90 && e.ctrlKey) { // ctrl+Z
this.selectedDrawing.undo();
}
else if (e.keyCode == 27) { // escape
this.selectedDrawing.enable(false);
this.setDragMapCursor();
}
else {
return;
}
this.selectedDrawing.enable(false);
this.setDragMapCursor();
if (!$scope.$$phase) {
$scope.$apply();
}
Expand Down
13 changes: 10 additions & 3 deletions services/HashService.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
module IsraelHiking.Services {
export class HashService {
private static ZOOM_KEY = "Zoom";
private static LATLNG_KEY = "LatLng";
private static ARRAY_DELIMITER = ":";
private static DATA_DELIMITER = ",";
private static PERSICION = 4;

private $location: angular.ILocationService;
private $rootScope: angular.IScope;
private localStorageService: angular.local.storage.ILocalStorageService;
private dataContainer: Common.DataContainer;
public latlng: L.LatLng;
public zoom: number;

constructor($location: angular.ILocationService,
$rootScope: angular.IScope) {
$rootScope: angular.IScope,
localStorageService: angular.local.storage.ILocalStorageService) {
this.$location = $location;
this.$rootScope = $rootScope;
this.latlng = new L.LatLng(31.773, 35.12);
this.zoom = 13;
this.localStorageService = localStorageService;
this.latlng = this.localStorageService.get<L.LatLng>(HashService.LATLNG_KEY) || new L.LatLng(31.773, 35.12);
this.zoom = this.localStorageService.get<number>(HashService.ZOOM_KEY) || 13;
this.dataContainer = <Common.DataContainer> { markers: [], routes: [] };
this.addDataFromUrl();
}
Expand All @@ -40,6 +45,8 @@
this.latlng.lat = latlng.lat;
this.latlng.lng = latlng.lng;
this.zoom = zoom;
this.localStorageService.set(HashService.LATLNG_KEY, this.latlng);
this.localStorageService.set(HashService.ZOOM_KEY, this.zoom);
this.updateUrl();
}

Expand Down
2 changes: 2 additions & 0 deletions services/drawing/DrawingMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@

public activate = () => {
this.active = true;
this.enabled = true;
var data = this.getData();
this.internalClear();
this.setData(data);
}

public deactivate = () => {
this.active = false;
this.enabled = false;
var data = this.getData();
this.internalClear();
for (var markerIndex = 0; markerIndex < data.length; markerIndex++) {
Expand Down
1 change: 0 additions & 1 deletion services/drawing/DrawingRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@

public activate = () => {
this.active = true;
this.enabled = true;
for (var segmementIndex = 0; segmementIndex < this.routeSegments.length; segmementIndex++) {
var segment = this.routeSegments[segmementIndex];
segment.routePoint = this.createMarker(segment.routePointLatlng);
Expand Down
10 changes: 8 additions & 2 deletions services/routers/BaseRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
var deferred = this.$q.defer();
var noneRouter = new NoneRouter(this.$q);
this.$http.get(route + params).success((geojson: GeoJSON.FeatureCollection, status) => {
var data = this.geojsonParser.toDataContainer(geojson);
if (data.routes.length == 0 || data.routes[0].segments.length < 2) {
var failed = false;
try {
var data = this.geojsonParser.toDataContainer(geojson);
} catch (err) {
failed = true;
}
if (failed || data.routes.length == 0 || data.routes[0].segments.length < 2 ) {
console.error("Failed routing from " + latlngStart + " to " + latlngEnd);
noneRouter.getRoute(latlngStart, latlngEnd).then((noneRouterData) => {
deferred.resolve(noneRouterData);
});
Expand Down
2 changes: 1 addition & 1 deletion services/routers/FourByFourRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IsraelHiking.Services.Routers {
export class FourByFourRouter extends BaseRouter {
protected getProfile(): string {
return "trekking";
return "moped";
}
}
}
2 changes: 1 addition & 1 deletion services/routers/HikeRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IsraelHiking.Services.Routers {
export class HikeRouter extends BaseRouter {
protected getProfile(): string {
return "trekking";
return "shortest";
}
}
}
10 changes: 6 additions & 4 deletions views/drawing.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div class="leaflet-bar">
<a class="cursor-pointer" ng-click="toggleDrawing($event)" ng-class="{'leaflet-active' : isDrawingEnabled()}" title="Toggle drawing mode"><i class="fa fa-pencil fa-lg"></i></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="setRouting('none', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'none'}" title="No routing"><i class="fa fa-level-up fa-lg"></i></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="setRouting('hike', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'hike'}" title="Hike routing"><img src="content/images/hike.svg" /></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="setRouting('bike', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'bike'}" title="Bike routing"><img src="content/images/bike.svg" /></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="setRouting('fourByFour', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'fourByFour'}" title="4x4 routing"><img src="content/images/four-by-four.svg" /></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="toggleRouting('hike', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'hike'}" title="Hike routing"><i class="fa fa-level-up fa-lg"></i></a>
<!--
<a class="cursor-pointer" ng-show="showRouting()" ng-click="toggleRouting('hike', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'hike'}" title="Hike routing"><img src="content/images/hike.svg" /></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="toggleRouting('bike', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'bike'}" title="Bike routing"><img src="content/images/bike.svg" /></a>
<a class="cursor-pointer" ng-show="showRouting()" ng-click="toggleRouting('fourByFour', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'fourByFour'}" title="4x4 routing"><img src="content/images/four-by-four.svg" /></a>
-->
<a class="cursor-pointer" ng-click="undo($event)" ng-class="{'leaflet-disabled' : isUndoDisbaled()}" title="Undo"><i class="fa fa-undo fa-lg"></i></a>
</div>

0 comments on commit e38a7cd

Please sign in to comment.