Skip to content

Commit

Permalink
#653 - remove language from poi address, fix address reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Jun 2, 2018
1 parent 91d94e4 commit 7b87bb7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Component } from "@angular/core";
import { Router } from "@angular/router";
import { MatDialog } from "@angular/material";
import "rxjs/add/operator/take";

import { BaseMapComponent } from "./base-map.component";
import { ResourcesService } from "../services/resources.service";
import { SidebarService } from "../services/sidebar.service";
import { HashService, RouteStrings } from "../services/hash.service";
import { HashService } from "../services/hash.service";
import { DownloadDialogComponent } from "./dialogs/download-dialog.component";

@Component({
Expand All @@ -16,7 +15,6 @@ import { DownloadDialogComponent } from "./dialogs/download-dialog.component";
export class InfoComponent extends BaseMapComponent {

constructor(resources: ResourcesService,
private readonly router: Router,
private readonly hashService: HashService,
private readonly sidebarService: SidebarService,
private readonly dialog: MatDialog) {
Expand All @@ -43,7 +41,7 @@ export class InfoComponent extends BaseMapComponent {
private openDownloadDialog = () => {
let dialog = this.dialog.open(DownloadDialogComponent, { width: "600px" });
dialog.afterClosed().take(1).subscribe(() => {
this.router.navigate([RouteStrings.ROUTE_ROOT]);
this.hashService.resetAddressbar();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component } from "@angular/core";
import { Router } from "@angular/router";
import { MatSelectChange } from "@angular/material";
import * as _ from "lodash";

Expand All @@ -17,7 +16,7 @@ import { IMarkerWithData } from "../../services/layers/routelayers/iroute.layer"
import { RouteLayerFactory } from "../../services/layers/routelayers/route-layer.factory";
import { ISelectableCategory } from "../dialogs/update-point-dialog.component";
import { CategoriesLayerFactory } from "../../services/layers/categories-layers.factory";
import { HashService, IPoiSourceAndId, RouteStrings } from "../../services/hash.service";
import { HashService, IPoiSourceAndId } from "../../services/hash.service";
import * as Common from "../../common/IsraelHiking";

@Component({
Expand All @@ -42,7 +41,6 @@ export class PublicPoiSidebarComponent extends BaseMapComponent {
private poiExtended: IPointOfInterestExtended;

constructor(resources: ResourcesService,
private readonly router: Router,
private readonly mapService: MapService,
private readonly sidebarService: SidebarService,
private readonly poiService: PoiService,
Expand Down Expand Up @@ -311,7 +309,8 @@ export class PublicPoiSidebarComponent extends BaseMapComponent {

public close() {
this.sidebarService.hide();
this.router.navigate([RouteStrings.ROUTE_ROOT]);
this.hashService.setApplicationState("poi", null);
this.hashService.resetAddressbar();
}

public getEditElementOsmAddress(): string {
Expand Down
71 changes: 42 additions & 29 deletions IsraelHiking.Web/sources/application/services/hash.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ export interface IPoiSourceAndId {
}

export class RouteStrings {
public static MAP = "map";
public static SHARE = "share";
public static URL = "url";
public static POI = "poi";
public static DOWNLOAD = "download";
public static SEARCH = "search";
public static ROUTE_ROOT = "/";
public static ROUTE_MAP = `/${RouteStrings.MAP}`;
public static ROUTE_SHARE = `/${RouteStrings.SHARE}`;
public static ROUTE_URL = `/${RouteStrings.URL}`;
public static ROUTE_POI = `/${RouteStrings.POI}`;
public static ROUTE_DOWNLOAD = `/${RouteStrings.DOWNLOAD}`;
public static ROUTE_SEARCH = `/${RouteStrings.SEARCH}`;

public static LAT = "lat";
public static LON = "lon";
public static ZOOM = "zoom";
public static ID = "id";
public static SOURCE = "source";
public static TERM = "term";
public static BASE_LAYER = "baselayer";
public static readonly MAP = "map";
public static readonly SHARE = "share";
public static readonly URL = "url";
public static readonly POI = "poi";
public static readonly DOWNLOAD = "download";
public static readonly SEARCH = "search";
public static readonly ROUTE_ROOT = "/";
public static readonly ROUTE_MAP = `/${RouteStrings.MAP}`;
public static readonly ROUTE_SHARE = `/${RouteStrings.SHARE}`;
public static readonly ROUTE_URL = `/${RouteStrings.URL}`;
public static readonly ROUTE_POI = `/${RouteStrings.POI}`;
public static readonly ROUTE_DOWNLOAD = `/${RouteStrings.DOWNLOAD}`;
public static readonly ROUTE_SEARCH = `/${RouteStrings.SEARCH}`;

public static readonly LAT = "lat";
public static readonly LON = "lon";
public static readonly ZOOM = "zoom";
public static readonly ID = "id";
public static readonly SOURCE = "source";
public static readonly TERM = "term";
public static readonly BASE_LAYER = "baselayer";
}

@Injectable()
Expand Down Expand Up @@ -72,19 +72,32 @@ export class HashService {
this.stateMap = new Map();
this.backwardCompatibilitySupport();
this.mapService.map.on("moveend", () => {
if (this.stateMap.get("share") || this.stateMap.get("url") || this.stateMap.get("poi")) {
if (this.getShareUrlId() || this.getUrl() || this.stateMap.get("poi")) {
return;
}
this.router.navigate([
RouteStrings.ROUTE_MAP,
this.mapService.map.getZoom(),
this.mapService.map.getCenter().lat.toFixed(HashService.PERSICION),
this.mapService.map.getCenter().lng.toFixed(HashService.PERSICION)
],
{ replaceUrl: true });
this.resetAddressbar();
});
}

public resetAddressbar(): void {
if (this.getShareUrlId()) {
this.router.navigate([RouteStrings.ROUTE_SHARE, this.getShareUrlId()], { replaceUrl: true });
return;
}
if (this.getUrl()) {
this.router.navigate([RouteStrings.ROUTE_URL, this.getUrl()],
{ queryParams: { baselayer: this.getBaselayer() }, replaceUrl: true });
return;
}
this.router.navigate([
RouteStrings.ROUTE_MAP,
this.mapService.map.getZoom(),
this.mapService.map.getCenter().lat.toFixed(HashService.PERSICION),
this.mapService.map.getCenter().lng.toFixed(HashService.PERSICION)
],
{ replaceUrl: true });
}

private backwardCompatibilitySupport() {
if (this.window.location.hash.indexOf(HashService.HASH) < 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ export class CategoriesLayer extends BasePoiMarkerLayer {
marker.on("click", () => {
if (this.hashService.getPoiSourceAndId() != null &&
this.hashService.getPoiSourceAndId().id === pointOfInterest.id) {
this.router.navigate([RouteStrings.ROUTE_ROOT]);
this.sidebarService.hide();
this.hashService.setApplicationState("poi", null);
this.hashService.resetAddressbar();
} else {
this.router.navigate([RouteStrings.ROUTE_POI, pointOfInterest.source, pointOfInterest.id],
{ queryParams: { language: this.resources.getCurrentLanguageCodeSimplified() } });
this.router.navigate([RouteStrings.ROUTE_POI, pointOfInterest.source, pointOfInterest.id]);
}
});
return marker;
Expand Down

0 comments on commit 7b87bb7

Please sign in to comment.