Skip to content

Commit

Permalink
feat(context): context service (#20)
Browse files Browse the repository at this point in the history
* feat(context): context service
  • Loading branch information
cbourget authored and mbarbeau committed Apr 24, 2017
1 parent 0871eb6 commit a17054c
Show file tree
Hide file tree
Showing 31 changed files with 461 additions and 74 deletions.
2 changes: 1 addition & 1 deletion proxy.conf.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
5 changes: 4 additions & 1 deletion src/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"endDate": "End Date",
"hideLayer": "Hide Layer",
"lowerLayer": "Bring layer backward",
"map": "Map",
"noLegendText": "No legend available for this layer",
"opacity": "Opacity",
"raiseLayer": "Bring layer forward",
"removeLayer": "Remove this layer from the map",
"searchResults": "Search Results",
"showLayer": "Show Layer",
"startDate": "Start Date"
"startDate": "Start Date",
"timeAnalysis": "Time Analysis"
}
}
5 changes: 4 additions & 1 deletion src/assets/locale/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"endDate": "Date de fin",
"hideLayer": "Masquer la couche",
"lowerLayer": "Descendre la couche",
"map": "Carte",
"noLegendText": "Aucune légende disponible pour cette couche",
"opacity": "Opacité",
"raiseLayer": "Monter la couche",
"removeLayer": "Retirer la couche de la carte",
"searchResults": "Résultats de recherche",
"showLayer": "Afficher la couche",
"startDate": "Date de début"
"startDate": "Date de début",
"timeAnalysis": "Analyse Temporelle"
}
}
4 changes: 3 additions & 1 deletion src/demo-app/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<igo-map-browser
igoQuery
igoOverlay
igoMapContext
igoLayerContext
[map]="map"
[view]="mapView">
<igo-zoom [map]="map" color="primary"></igo-zoom>
Expand Down Expand Up @@ -64,7 +66,7 @@
<md-card-title>toolbar.component</md-card-title>
<md-card-content>
<igo-toolbar-base
[tools]="tools"
igoToolContext
[withIcon]="true"
[withTitle]="true"
[horizontal]="true"
Expand Down
121 changes: 68 additions & 53 deletions src/demo-app/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

import { IgoMap, LayerService, Tool,
OverlayService, QueryFormat,
import { IgoMap, Tool, QueryFormat,
OverlayService, ContextService,
Feature, FeatureService,
WMSLayerOptions, LanguageService } from '../../lib';

Expand All @@ -17,65 +17,80 @@ export class AppComponent implements OnInit {
public feature$ = new BehaviorSubject<Feature>(undefined);

public map = new IgoMap();
public mapView = {
projection: 'EPSG:3857',
center: [-72, 52],
zoom: 6
};

public tools = [
{name: 'tool1', title: 'Tool 1', icon: 'map', tooltip: 'tooltip1'},
{name: 'tool2', title: 'Tool 2', icon: 'bookmark', tooltip: 'tooltip2'}
];

constructor(public featureService: FeatureService,
public layerService: LayerService,
constructor(public contextService: ContextService,
public featureService: FeatureService,
public overlayService: OverlayService,
public language: LanguageService) {}

ngOnInit() {
this.map.removeLayers();

this.layerService.createAsyncLayer({
type: 'osm',
title: 'OSM'
}).subscribe(layer => this.map.addLayer(layer));
const projection = 'EPSG:3857';

this.layerService.createAsyncLayer({
title: 'MSP DESSERTE MUN 911',
type: 'wms',
source: {
url: '/cgi-wms/igo_gouvouvert.fcgi',
params: {
layers: 'MSP_DESSERTE_MUN_911',
version: '1.3.0'
},
projection: 'EPSG:3857'
this.contextService.setContext({
uri: 'qc911',
title: 'Qc-911',
map: {
view: {
projection: projection,
center: [-72, 52],
zoom: 6
}
},
queryFormat: QueryFormat.GML2,
queryTitle: 'Municipalite'
} as WMSLayerOptions).subscribe(layer => this.map.addLayer(layer));

this.layerService.createAsyncLayer({
title: 'Embâcle',
type: 'wms',
source: {
url: 'http://geoegl.msp.gouv.qc.ca/cgi-wms/igo_gouvouvert.fcgi',
params: {
layers: 'vg_observation_v_inondation_embacle_wmst',
version: '1.3.0'
layers: [
{
type: 'osm',
title: 'OSM'
},
projection: 'EPSG:3857'
},
queryFormat: QueryFormat.GML2,
queryTitle: 'Municipalite',
timeFilter: {
min: '2017-01-01',
max: '2018-01-01',
type: 'date',
range: true
}
} as WMSLayerOptions).subscribe(layer => this.map.addLayer(layer));
{
title: 'MSP DESSERTE MUN 911',
type: 'wms',
source: {
url: '/cgi-wms/igo_gouvouvert.fcgi',
params: {
layers: 'MSP_DESSERTE_MUN_911',
version: '1.3.0'
},
projection: projection
},
queryFormat: QueryFormat.GML2,
queryTitle: 'Municipalite'
} as WMSLayerOptions,
{
title: 'Embâcle',
type: 'wms',
source: {
url: 'http://geoegl.msp.gouv.qc.ca/cgi-wms/igo_gouvouvert.fcgi',
params: {
layers: 'vg_observation_v_inondation_embacle_wmst',
version: '1.3.0'
},
projection: projection
},
timeFilter: {
min: '2017-01-01',
max: '2018-01-01',
type: 'date',
range: true
}
} as WMSLayerOptions
],
toolbar: [
'featureList',
'layerList',
'timeFilter'
],
tools: [
{
name: 'featureList'
},
{
name: 'layerList'
},
{
name: 'timeFilter'
}
]
});
}

handleSearch(term: string) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './module';
35 changes: 35 additions & 0 deletions src/lib/context/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NgModule, ModuleWithProviders } from '@angular/core';

import { IgoSharedModule } from '../shared';

import { ContextService, MapContextDirective,
LayerContextDirective, ToolContextDirective } from './shared';


@NgModule({
imports: [
IgoSharedModule
],
exports: [
MapContextDirective,
LayerContextDirective,
ToolContextDirective
],
declarations: [
MapContextDirective,
LayerContextDirective,
ToolContextDirective
]
})
export class IgoContextModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: IgoContextModule,
providers: [
ContextService
]
};
}
}

export * from './shared';
23 changes: 23 additions & 0 deletions src/lib/context/shared/context.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MapViewOptions } from '../../map';
import { LayerOptions } from '../../layer';
import { Tool } from '../../tool/shared/tool.interface';


export interface Context {
title: string;
uri: string;
scope?: 'public' | 'protected' | 'private';
description?: string;
icon?: string;
}

export interface DetailedContext extends Context {
map?: MapContext;
layers?: LayerOptions[];
tools?: Tool[];
toolbar?: string[];
}

export interface MapContext {
view: MapViewOptions;
}
26 changes: 26 additions & 0 deletions src/lib/context/shared/context.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpModule } from '@angular/http';

import { RequestService, MessageService } from '../../core';

import { ContextService } from './context.service';


describe('ContextService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpModule
],
providers: [
ContextService,
MessageService,
RequestService
]
});
});

it('should ...', inject([ContextService], (service: ContextService) => {
expect(service).toBeTruthy();
}));
});
36 changes: 36 additions & 0 deletions src/lib/context/shared/context.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
// import { Observable } from 'rxjs/Observable';

import { RequestService } from '../../core';

import { DetailedContext } from './context.interface';


@Injectable()
export class ContextService {

public context$ = new BehaviorSubject<DetailedContext>(undefined);

constructor(private http: Http,
private requestService: RequestService) { }

// getContexts(): Observable<Context[]> {
// return this.requestService.register(
// this.http.get(`contexts/_contexts.json`)
// ).map(res => res.json());
// }

loadContext(url: string) {
this.requestService.register(
this.http.get(url), 'Context')
.map(res => res.json())
.subscribe(context => this.setContext(context));
}

setContext(context: DetailedContext) {
this.context$.next(context);
}

}
4 changes: 4 additions & 0 deletions src/lib/context/shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './context.service';
export * from './layer-context.directive';
export * from './map-context.directive';
export * from './tool-context.directive';
25 changes: 25 additions & 0 deletions src/lib/context/shared/layer-context.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { TestBed } from '@angular/core/testing';

// import { LayerService } from '../../layer';
// import { RequestService } from '../../core';

// import { ContextService } from './context.service';
// import { LayerContextDirective } from './layer-context.directive';


describe('LayerContextDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: [
// RequestService,
// ContextService,
// LayerService
]
});
});

it('should create an instance', () => {
expect(true).toBeTruthy();
});
});
Loading

0 comments on commit a17054c

Please sign in to comment.