Skip to content

Commit

Permalink
Clear button for routes and markers #26 - added.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jul 28, 2015
1 parent ec3668b commit 23051b1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions controllers/DrawingController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module IsraelHiking.Controllers {
export interface IDrawingScope extends angular.IScope {
clear(e: Event): void;
toggleDrawing(e: Event): void;
toggleRouting(routingType: string, e: Event): void;
undo(e: Event): void;
Expand All @@ -24,6 +25,11 @@
this.selectedDrawing = this.layersService.getSelectedDrawing();
});

$scope.clear = (e: Event) => {
this.selectedDrawing.clear();
this.suppressEvents(e);
}

$scope.toggleDrawing = (e: Event) => {
if (this.selectedDrawing.isEnabled()) {
this.selectedDrawing.enable(false);
Expand Down
5 changes: 4 additions & 1 deletion services/drawing/BaseDrawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
activate: () => void;
deactivate: () => void;
undo: () => void;
isEnabled: () => boolean;
enable(enable: boolean): void;
isEnabled: () => boolean;
clear() => void;
getRoutingType: () => string;
setRoutingType: (routingType: string) => void;
isUndoDisbaled: () => boolean;
Expand Down Expand Up @@ -43,6 +44,8 @@
}
// should be override in derived
public enable = (enable: boolean): void => { }
// should be override in derived
public clear = () => { }

// should be override in derived
public getRoutingType = (): string => {
Expand Down
5 changes: 5 additions & 0 deletions services/drawing/DrawingMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
this.setData(data);
}

public clear = () => {
this.internalClear();
this.updateDataLayer();
}

public deactivate = () => {
this.active = false;
this.enabled = false;
Expand Down
11 changes: 8 additions & 3 deletions services/drawing/DrawingRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
return this.enabled && this.active;
}

public clear = () => {
this.internalClear();
this.updateDataLayer();
}

public getRoutingType = (): string => {
return this.currentRoutingType;
}
Expand All @@ -97,7 +102,7 @@

public reroute = (): angular.IPromise<void> => {
var data = this.getData();
this.internalclear();
this.internalClear();
var promises = [];
for (var pointIndex = 0; pointIndex < data.segments.length; pointIndex++) {
var segmentData = data.segments[pointIndex];
Expand Down Expand Up @@ -357,7 +362,7 @@
}

public setData = (data: Common.RouteData) => {
this.internalclear();
this.internalClear();
data.name = this.name;
for (var pointIndex = 0; pointIndex < data.segments.length; pointIndex++) {
var segment = data.segments[pointIndex];
Expand All @@ -367,7 +372,7 @@
this.hashService.updateRoute(this.getData());
}

private internalclear = () => {
private internalClear = () => {
for (var segmentIndex = this.routeSegments.length - 1; segmentIndex >= 0; segmentIndex--) {
this.removeSegmentByIndex(segmentIndex);
}
Expand Down
1 change: 1 addition & 0 deletions views/drawing.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="leaflet-bar">
<a class="cursor-pointer" ng-click="clear($event)" title="Clear"><i class="fa fa-remove fa-lg"></i></a>
<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="toggleRouting('h', $event)" ng-class="{'leaflet-active' : getRoutingType() == 'h'}" title="Hike routing"><i class="fa fa-level-up fa-lg"></i></a>
<!--
Expand Down

0 comments on commit 23051b1

Please sign in to comment.