Skip to content

Commit

Permalink
feat: emit map instance on load output
Browse files Browse the repository at this point in the history
BREAKING CHANGE: MapComponent is no longer exposed in the package
  • Loading branch information
Wykks committed Nov 14, 2017
1 parent 456013a commit 17e9fe2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/app/demo/examples/center-on-symbol.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { MapComponent } from '../../lib';
import { Component, ViewChild } from '@angular/core';
import { MapMouseEvent } from 'mapbox-gl';
import { Component } from '@angular/core';
import { MapMouseEvent, Map } from 'mapbox-gl';

@Component({
template: `
<mgl-map
[style]="'mapbox://styles/mapbox/light-v9'"
[zoom]="8"
[center]="center"
#map
(load)="map = $event"
>
<mgl-geojson-source
id="symbols-source"
Expand All @@ -35,7 +34,7 @@ import { MapMouseEvent } from 'mapbox-gl';
styleUrls: ['./examples.css']
})
export class CenterOnSymbolComponent {
@ViewChild('map') map: MapComponent;
map: Map;

center = [-90.96, -0.47];

Expand Down Expand Up @@ -69,10 +68,10 @@ export class CenterOnSymbolComponent {
}

changeCursorToPointer() {
this.map.mapInstance.getCanvas().style.cursor = 'pointer';
this.map.getCanvas().style.cursor = 'pointer';
}

changeCursorToDefault() {
this.map.mapInstance.getCanvas().style.cursor = '';
this.map.getCanvas().style.cursor = '';
}
}
10 changes: 5 additions & 5 deletions src/app/demo/examples/language-switch.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, ViewChild } from '@angular/core';
import { MapComponent } from '../../lib';
import { Component } from '@angular/core';
import { Map } from 'mapbox-gl';

@Component({
template: `
<mgl-map
style="mapbox://styles/mapbox/light-v9"
[zoom]="2.9"
[center]="[16.05, 48]"
#map
(load)="map = $event"
>
<mgl-control>
<button
Expand All @@ -32,9 +32,9 @@ import { MapComponent } from '../../lib';
styleUrls: ['./examples.css', './toggle-layers.component.css']
})
export class LanguageSwitchComponent {
@ViewChild('map') map: MapComponent;
map: Map;

changeLangTo(language: string) {
this.map.mapInstance.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}');
this.map.setLayoutProperty('country-label-lg', 'text-field', '{name_' + language + '}');
}
}
1 change: 0 additions & 1 deletion src/app/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './lib.module';

export * from './map/map.types';
export { MapComponent } from './map/map.component';
2 changes: 1 addition & 1 deletion src/app/lib/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class MapService {
this.mapInstance.on('load', () => {
this.mapLoaded.next(undefined);
this.mapLoaded.complete();
this.zone.run(() => events.load.emit());
this.zone.run(() => events.load.emit(this.mapInstance));
});
this.mapInstance.on('resize', () => this.zone.run(() => events.resize.emit()));
this.mapInstance.on('remove', () => this.zone.run(() => events.remove.emit()));
Expand Down
4 changes: 2 additions & 2 deletions src/app/lib/map/map.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Can't use MapEvent interface from @types/mapbox because some event name are changed (eg zoomChange)
import { EventEmitter } from '@angular/core';
import { MapMouseEvent, MapTouchEvent, EventData, MapBoxZoomEvent } from 'mapbox-gl';
import { MapMouseEvent, MapTouchEvent, EventData, MapBoxZoomEvent, Map } from 'mapbox-gl';

export interface MapEvent {
resize: EventEmitter<void>;
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface MapEvent {
boxZoomCancel: EventEmitter<MapBoxZoomEvent>;
webGlContextLost: EventEmitter<void>;
webGlContextRestored: EventEmitter<void>;
load: EventEmitter<any>;
load: EventEmitter<Map>;
render: EventEmitter<void>;
error: EventEmitter<any>; // TODO Check type
data: EventEmitter<EventData>;
Expand Down

0 comments on commit 17e9fe2

Please sign in to comment.