Skip to content

Commit

Permalink
fix(controls): Fix control order when using custom controls alongside…
Browse files Browse the repository at this point in the history
… built-in controls (fix #75)
  • Loading branch information
dmytro-gokun authored and Wykks committed Jul 19, 2019
1 parent f7602c2 commit 10612f0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, Host, Input, OnInit } from '@angular/core';
import { AfterContentInit, Directive, Host, Input } from '@angular/core';
import { AttributionControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import { ControlComponent } from './control.component';

@Directive({
selector: '[mglAttribution]'
})
export class AttributionControlDirective implements OnInit {
export class AttributionControlDirective implements AfterContentInit {
/* Init inputs */
@Input() compact?: boolean;
@Input() customAttribution?: string | string[];
Expand All @@ -16,7 +16,7 @@ export class AttributionControlDirective implements OnInit {
@Host() private ControlComponent: ControlComponent
) { }

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, OnInit, Host, Input } from '@angular/core';
import { AfterContentInit, Directive, Host, Input } from '@angular/core';
import { FullscreenControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import { ControlComponent } from './control.component';

@Directive({
selector: '[mglFullscreen]'
})
export class FullscreenControlDirective implements OnInit {
export class FullscreenControlDirective implements AfterContentInit {
/* Init inputs */
@Input() container?: HTMLElement;

Expand All @@ -15,7 +15,7 @@ export class FullscreenControlDirective implements OnInit {
@Host() private ControlComponent: ControlComponent
) { }

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AfterContentInit,
Directive,
EventEmitter,
Host,
Expand All @@ -7,7 +8,6 @@ import {
Input,
NgZone,
OnChanges,
OnInit,
Optional,
Output,
SimpleChanges
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface Result extends GeoJSON.Feature<GeoJSON.Point> {
@Directive({
selector: '[mglGeocoder]'
})
export class GeocoderControlDirective implements OnInit, OnChanges, GeocoderEvent {
export class GeocoderControlDirective implements AfterContentInit, OnChanges, GeocoderEvent {
/* Init inputs */
@Input() country?: string;
@Input() placeholder?: string;
Expand Down Expand Up @@ -81,7 +81,7 @@ export class GeocoderControlDirective implements OnInit, OnChanges, GeocoderEven
@Optional() @Inject(MAPBOX_GEOCODER_API_KEY) private readonly MAPBOX_GEOCODER_API_KEY: string
) { }

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, Host, Input, OnInit } from '@angular/core';
import { AfterContentInit, Directive, Host, Input } from '@angular/core';
import { GeolocateControl, FitBoundsOptions } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import { ControlComponent } from './control.component';

@Directive({
selector: '[mglGeolocate]'
})
export class GeolocateControlDirective implements OnInit {
export class GeolocateControlDirective implements AfterContentInit {
/* Init inputs */
@Input() positionOptions?: PositionOptions;
@Input() fitBoundsOptions?: FitBoundsOptions;
Expand All @@ -18,7 +18,7 @@ export class GeolocateControlDirective implements OnInit {
@Host() private ControlComponent: ControlComponent
) { }

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, Host, Input, OnInit } from '@angular/core';
import { AfterContentInit, Directive, Host, Input } from '@angular/core';
import { NavigationControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import { ControlComponent } from './control.component';

@Directive({
selector: '[mglNavigation]'
})
export class NavigationControlDirective implements OnInit {
export class NavigationControlDirective implements AfterContentInit {
/* Init inputs */
@Input() showCompass?: boolean;
@Input() showZoom?: boolean;
Expand All @@ -16,7 +16,7 @@ export class NavigationControlDirective implements OnInit {
@Host() private ControlComponent: ControlComponent
) { }

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directive, Host, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { AfterContentInit, Directive, Host, Input, OnChanges, SimpleChanges } from '@angular/core';
import { ScaleControl } from 'mapbox-gl';
import { MapService } from '../map/map.service';
import { ControlComponent } from './control.component';

@Directive({
selector: '[mglScale]'
})
export class ScaleControlDirective implements OnInit, OnChanges {
export class ScaleControlDirective implements AfterContentInit, OnChanges {
/* Init inputs */
@Input() maxWidth?: number;

Expand All @@ -24,7 +24,7 @@ export class ScaleControlDirective implements OnInit, OnChanges {
}
}

ngOnInit() {
ngAfterContentInit() {
this.MapService.mapCreated$.subscribe(() => {
if (this.ControlComponent.control) {
throw new Error('Another control is already set for this control');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { Component } from '@angular/core';
Hello
</button>
</mgl-control>
<mgl-control mglAttribution position="top-right"></mgl-control>
<mgl-control mglFullscreen position="top-right"></mgl-control>
<mgl-control mglGeocoder position="top-right"></mgl-control>
<mgl-control mglGeolocate position="top-right"></mgl-control>
<mgl-control mglNavigation position="top-right"></mgl-control>
<mgl-control mglScale position="top-right"></mgl-control>
</mgl-map>
`,
styleUrls: ['./examples.css']
Expand Down

0 comments on commit 10612f0

Please sign in to comment.