Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tool): some tools and working toolbox #25

Merged
merged 4 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/demo-app/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@
<md-card-title>feature-list.component</md-card-title>
<md-card-content>
<igo-feature-list
igoFeatureListBehavior
igoFeatureListBinding
[focusFirst]="true"
[focusedFeature]="feature$ | async"
(focus)="handleFeatureFocus($event)"
(select)="handleFeatureSelect($event)">
</igo-feature-list>
</md-card-content>

<md-card-title>feature-details.component</md-card-title>
<md-card-content *ngIf="(feature$ | async)">
<md-card-content>
<igo-panel [title]="'Details'">
<igo-feature-details [feature]="feature$ | async"></igo-feature-details>
<igo-feature-details [feature]="featureService.focusedFeature$ | async"></igo-feature-details>

<button
md-icon-button
Expand Down Expand Up @@ -108,17 +107,17 @@
<md-card-content>
<igo-toolbar
igoToolContext
igoToolbarBehavior
igoToolbarBinding
[withIcon]="true"
[withTitle]="true"
[horizontal]="true"
(select)="handleToolSelect($event)">
</igo-toolbar>
</md-card-content>

<!--md-card-title>toolbox.component</md-card-title>
<md-card-title>toolbox.component</md-card-title>
<md-card-content>
<igo-toolbox></igo-toolbox>
</md-card-content-->
<igo-toolbox></igo-toolbox>
</md-card-content>
</md-card>
</md-sidenav-container>
23 changes: 10 additions & 13 deletions src/demo-app/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

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

@Component({
selector: 'igo-demo',
Expand All @@ -13,11 +12,11 @@ import { IgoMap, Tool, QueryFormat,
export class AppComponent implements OnInit {

public searchTerm: string;
public feature$ = new BehaviorSubject<Feature>(undefined);

public map = new IgoMap();

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

Expand Down Expand Up @@ -73,19 +72,19 @@ export class AppComponent implements OnInit {
} as WMSLayerOptions
],
toolbar: [
'featureList',
'layerList',
'searchResults',
'map',
'timeFilter'
],
tools: [
{
name: 'featureList'
name: 'searchResults'
},
{
name: 'layerList'
name: 'map'
},
{
name: 'timeFilter'
name: 'timeAnalysis'
}
]
});
Expand All @@ -96,12 +95,10 @@ export class AppComponent implements OnInit {
}

handleFeatureFocus(feature: Feature) {
this.feature$.next(feature);
this.overlayService.setFeatures([feature], 'move');
}

handleFeatureSelect(feature: Feature) {
this.feature$.next(feature);
this.overlayService.setFeatures([feature], 'zoom');
}

Expand All @@ -110,7 +107,7 @@ export class AppComponent implements OnInit {
}

clearFeature() {
this.feature$.next(undefined);
this.featureService.unfocusFeature();
this.overlayService.clear();
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/demo-app/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { AppModule } from './app/module';
import { environment } from './environments/environment';

if (environment.production) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestBed } from '@angular/core/testing';

describe('FeatureDetailsBindingDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: []
});
});

it('should create an instance', () => {
expect(true).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Directive, Self, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { FeatureService } from '../shared';
import { FeatureDetailsComponent } from './feature-details.component';


@Directive({
selector: '[igoFeatureDetailsBinding]'
})
export class FeatureDetailsBindingDirective implements OnInit, OnDestroy {

private component: FeatureDetailsComponent;
private focusedFeatures$$: Subscription;

constructor(@Self() component: FeatureDetailsComponent,
private featureService: FeatureService) {
this.component = component;
}

ngOnInit() {
this.focusedFeatures$$ = this.featureService.focusedFeature$
.subscribe(feature => this.component.feature = feature);
}

ngOnDestroy() {
this.focusedFeatures$$.unsubscribe();
}

}
6 changes: 4 additions & 2 deletions src/lib/feature/feature-details/feature-details.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
import { Component, Input, ChangeDetectionStrategy,
ChangeDetectorRef } from '@angular/core';

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

Expand All @@ -14,9 +15,10 @@ export class FeatureDetailsComponent {
get feature(): Feature { return this._feature; }
set feature(value: Feature) {
this._feature = value;
this.cdRef.detectChanges();
}
private _feature: Feature;

constructor() { }
constructor(private cdRef: ChangeDetectorRef) { }

}
1 change: 1 addition & 0 deletions src/lib/feature/feature-details/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './feature-details.component';
export * from './feature-details-binding.directive';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';

describe('FeatureListBehaviorDirective', () => {
describe('FeatureListBindingDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { FeatureListComponent } from './feature-list.component';


@Directive({
selector: '[igoFeatureListBehavior]'
selector: '[igoFeatureListBinding]'
})
export class FeatureListBehaviorDirective implements OnInit, OnDestroy {
export class FeatureListBindingDirective implements OnInit, OnDestroy {

private component: FeatureListComponent;
private features$$: Subscription;
private focusedFeatures$$: Subscription;

@HostListener('focus', ['$event']) onFocus(feature: Feature) {
this.featureService.focusFeature(feature);
Expand All @@ -33,10 +34,20 @@ export class FeatureListBehaviorDirective implements OnInit, OnDestroy {

this.features$$ = this.featureService.features$
.subscribe(features => this.component.features = features);

// When there are multiple feature list with this directive,
// selecting moving up and down using the keyboard skips some features.
// We can bypass this issue using a debounce time. Since
// having multiple feature list is unusual, no better fix is provided
// for now.
this.focusedFeatures$$ = this.featureService.focusedFeature$
.debounceTime(100)
.subscribe(feature => this.component.focusedFeature = feature);
}

ngOnDestroy() {
this.features$$.unsubscribe();
this.focusedFeatures$$.unsubscribe();
}

}
2 changes: 1 addition & 1 deletion src/lib/feature/feature-list/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './feature-list.component';
export * from './feature-list-behavior.directive';
export * from './feature-list-binding.directive';
11 changes: 7 additions & 4 deletions src/lib/feature/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { IgoSharedModule } from '../shared';

import { FeatureService, FeatureGroupPipe } from './shared';
import { FeatureDetailsComponent } from './feature-details';
import { FeatureDetailsComponent,
FeatureDetailsBindingDirective } from './feature-details';
import { FeatureListComponent,
FeatureListBehaviorDirective } from './feature-list';
FeatureListBindingDirective } from './feature-list';
import { FeatureItemComponent } from './feature-item';


Expand All @@ -15,15 +16,17 @@ import { FeatureItemComponent } from './feature-item';
],
exports: [
FeatureDetailsComponent,
FeatureDetailsBindingDirective,
FeatureListComponent,
FeatureListBehaviorDirective,
FeatureListBindingDirective,
FeatureItemComponent,
FeatureGroupPipe
],
declarations: [
FeatureDetailsComponent,
FeatureDetailsBindingDirective,
FeatureListComponent,
FeatureListBehaviorDirective,
FeatureListBindingDirective,
FeatureItemComponent,
FeatureGroupPipe
]
Expand Down
9 changes: 7 additions & 2 deletions src/lib/feature/shared/feature.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class FeatureService {
this.focusFeature(feature);
}

selectNextFeature() {
this.selectedFeature$.next(this.features$.value[4]);
unfocusFeature() {
this.focusFeature(undefined);
}

unselectFeature() {
this.selectFeature(undefined);
}

}
9 changes: 6 additions & 3 deletions src/lib/filter/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { IgoSharedModule } from '../shared';
import { FilterableLayerPipe } from './shared';
import { TimeFilterFormComponent } from './time-filter-form';
import { TimeFilterItemComponent } from './time-filter-item';
import { TimeFilterListComponent } from './time-filter-list/';
import { TimeFilterListComponent,
TimeFilterListBindingDirective } from './time-filter-list/';

@NgModule({
imports: [
Expand All @@ -19,13 +20,15 @@ import { TimeFilterListComponent } from './time-filter-list/';
FilterableLayerPipe,
TimeFilterFormComponent,
TimeFilterItemComponent,
TimeFilterListComponent
TimeFilterListComponent,
TimeFilterListBindingDirective
],
declarations: [
FilterableLayerPipe,
TimeFilterFormComponent,
TimeFilterItemComponent,
TimeFilterListComponent
TimeFilterListComponent,
TimeFilterListBindingDirective
]
})
export class IgoFilterModule {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/filter/shared/filterable-layer.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Layer, FilterableLayer } from '../../layer';
export class FilterableLayerPipe implements PipeTransform {

transform(value: Layer[], arg: string): any {
let layers = value;
let layers;

if (arg === 'time') {
layers = value.filter(layer => {
Expand Down
1 change: 1 addition & 0 deletions src/lib/filter/time-filter-list/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './time-filter-list.component';
export * from './time-filter-list-binding.directive';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestBed } from '@angular/core/testing';

describe('TimeFilterListBindingDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: []
});
});

it('should create an instance', () => {
expect(true).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Directive, Self, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

import { MapService } from '../../map';
import { TimeFilterListComponent } from './time-filter-list.component';


@Directive({
selector: '[igoTimeFilterListBinding]'
})
export class TimeFilterListBindingDirective implements OnInit, OnDestroy {

private component: TimeFilterListComponent;
private layers$$: Subscription;


constructor(@Self() component: TimeFilterListComponent,
private mapService: MapService) {
this.component = component;
}

ngOnInit() {
// Override input layers
this.component.layers = [];

this.layers$$ = this.mapService.getMap().layers$
.subscribe(layers => this.component.layers = layers);
}

ngOnDestroy() {
this.layers$$.unsubscribe();
}

}
Loading