Skip to content

Commit

Permalink
feat(map): map browser binding directive
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget authored and mbarbeau committed May 4, 2017
1 parent 9069486 commit 61d9d26
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/demo-app/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
igoOverlay
igoMapContext
igoLayerContext
igoMapBrowserBinding
[map]="map">
<igo-zoom [map]="map" color="primary"></igo-zoom>
</igo-map-browser>
Expand Down
1 change: 1 addition & 0 deletions src/lib/map/map-browser/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './map-browser.component';
export * from './map-browser-binding.directive';
31 changes: 31 additions & 0 deletions src/lib/map/map-browser/map-browser-binding.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Directive, Self, OnInit, OnDestroy } from '@angular/core';

import { MapService } from '../shared';
import { MapBrowserComponent } from './map-browser.component';


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

private component: MapBrowserComponent;

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

ngOnInit() {
if (this.mapService.getMap() !== undefined) {
throw new Error('No more than one map be binded to the map service.');
}

this.mapService.setMap(this.component.map);
}

ngOnDestroy() {
this.mapService.setMap(undefined);
}

}
14 changes: 14 additions & 0 deletions src/lib/map/map-browser/map-browser-binding.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TestBed } from '@angular/core/testing';

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

it('should create an instance', () => {
expect(true).toBeTruthy();
});
});
5 changes: 1 addition & 4 deletions src/lib/map/map-browser/map-browser.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { IgoMap, MapService } from '../shared';
import { IgoMap } from '../shared';
import { MapBrowserComponent } from './map-browser.component';


Expand All @@ -13,9 +13,6 @@ describe('MapBrowserComponent', () => {
imports: [],
declarations: [
MapBrowserComponent
],
providers: [
MapService
]
})
.compileComponents();
Expand Down
5 changes: 2 additions & 3 deletions src/lib/map/map-browser/map-browser.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input, AfterViewInit } from '@angular/core';

import { IgoMap, MapViewOptions, MapService } from '../shared';
import { IgoMap, MapViewOptions } from '../shared';

@Component({
selector: 'igo-map-browser',
Expand All @@ -26,10 +26,9 @@ export class MapBrowserComponent implements AfterViewInit {

public id: string = 'igo-map-target';

constructor(private mapService: MapService) {}
constructor() {}

ngAfterViewInit(): any {
this.map.olMap.setTarget(this.id);
this.mapService.setMap(this.map);
}
}
4 changes: 3 additions & 1 deletion src/lib/map/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { IgoSharedModule } from '../shared';

import { MapService } from './shared';
import { MapBrowserComponent } from './map-browser';
import { MapBrowserComponent, MapBrowserBindingDirective } from './map-browser';
import { ZoomComponent } from './zoom';


Expand All @@ -13,10 +13,12 @@ import { ZoomComponent } from './zoom';
],
exports: [
MapBrowserComponent,
MapBrowserBindingDirective,
ZoomComponent
],
declarations: [
MapBrowserComponent,
MapBrowserBindingDirective,
ZoomComponent
]
})
Expand Down

0 comments on commit 61d9d26

Please sign in to comment.