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

Export control component, for custom control directives #79

Merged
merged 1 commit into from
Dec 6, 2018

Conversation

raysuelzer
Copy link
Contributor

I want to be able to implement a custom directive for the mapbox-draw plugin. By exposing the ControlComponent directive, I can create a directive in the same pattern that you use for the other control directives.

@raysuelzer
Copy link
Contributor Author

raysuelzer commented Dec 5, 2018

Here is an example of my use case. It is much cleaner to be able to do this. My goal eventually once I get a decent working directive for this control is to put in a PR to make it part of controls. But, in the mean time this will allow me a clean way to work on the directive in my app.

@Directive({
  // tslint:disable-next-line:directive-selector
  selector: '[mglExtensionDraw]'
})
export class DrawControlDirective implements OnInit {
  /* Init inputs */
  @Input() drawOptions?: DrawOptions;

  constructor(
    private mapService: MapService,
    @Host() private controlComponent: ControlComponent
  ) { }

  ngOnInit() {
    this.mapService.mapCreated$.subscribe(() => {
      if (this.controlComponent.control) {
        throw new Error('Another control is already set for this control');
      }
      const options: DrawOptions = this.drawOptions || {};

      this.controlComponent.control = new MapboxDraw(options);
      this.mapService.addControl(this.controlComponent.control, this.controlComponent.position);
    });
  }
}

In the template:

            <mgl-map [style]="'mapbox://styles/mapbox/streets-v9?optimize=true'"
                (load)="mapLoaded($event)"
                [zoom]="[5]" [center]="[-98.50, 39]">
                <mgl-control mglExtensionDraw></mgl-control>
            </mgl-map>

Final result:
image

@Wykks
Copy link
Owner

Wykks commented Dec 6, 2018

Sure, thanks !

Also address this #78 (comment)

@Wykks Wykks merged commit 458c3f7 into Wykks:master Dec 6, 2018
@raysuelzer
Copy link
Contributor Author

Any idea when this will go into a release?

@Wykks
Copy link
Owner

Wykks commented Dec 6, 2018

This week-end probably 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants