-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support google maps drawing library (#1749)
Add Drawing library to support DrawingManager
- Loading branch information
Showing
17 changed files
with
470 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
+++ | ||
date = "2017-08-31T13:51:15-05:00" | ||
draft = false | ||
title = "google.maps.drawing.DrawingManager in AGM" | ||
+++ | ||
|
||
Angular Google Maps provides a package that allows users to draw new shapes on the map, integrating google.maps.drawing.DrawingManager | ||
|
||
## Install the needed packages | ||
First make sure that you install the following NPM packages: | ||
|
||
```bash | ||
npm install @agm/core @agm/drawing | ||
``` | ||
|
||
## Loading the modules | ||
|
||
Update your root component (e.g. src/app/app.module.ts) and import the following modules: | ||
|
||
```typescript | ||
import { AgmCoreModule } from '@agm/core'; | ||
import { AgmDrawingModule } from '@agm/drawing'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
AgmCoreModule.forRoot({ | ||
apiKey: ['YOUR_API_KEY_HERE'] | ||
}), | ||
AgmDrawingModule | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
``` | ||
|
||
## Using the directive | ||
|
||
When you import the `AgmDrawingManager`, you can use the `agm-drawing-manager` directive in your | ||
template. Agm-drawing-manager takes form of an html elements outside the `agm-map` component, where | ||
it is configured with properties. It is connected to the map via `agmDrawingManager` trigger | ||
directive, similar to MatAutocomplete from angular/components library. | ||
|
||
```html | ||
<agm-map style="height: 300px" [latitude]="51.673858" [longitude]="7.815982" [agmDrawingManager]="drawing"> | ||
</agm-map> | ||
<agm-drawing-manager #drawing="agmDrawingManager" (circleComplete)="circleAdded($event)" [drawingMode]="'circle'" [circleOptions]="{fillColor:'red', radius: 150}"></agm-drawing-manager> | ||
``` | ||
|
||
### Customizing drawn figures | ||
|
||
If you want to control how the figures the user draws will look like, specifically colors, | ||
line thickness, opacity, et cetera, you can provide CircleOptions or PolylineOptions | ||
to the drawing manager, similar how you would do in vanilla javascript with Google Maps javascript. | ||
|
||
### Ignored properties | ||
|
||
These \*Options interfaces are originally made for the developer displaying the shapes, so they have | ||
properties useless to us such as `map` and `center`. These properties are ignored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Map Drawing for AGM | ||
|
||
----- | ||
|
||
this package adds drawing support to [AGM][agm]. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install @agm/drawing | ||
# or | ||
yarn add @agm/drawing | ||
``` | ||
|
||
## Usage | ||
|
||
1. Import the module | ||
|
||
```typescript | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { AppComponent } from './app.component | ||
// add these imports | ||
import { AgmCoreModule } from '@agm/core'; | ||
import { AgmDrawingModule } from '@agm/drawing | ||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
AgmCoreModule.forRoot({ | ||
apiKey: ['YOUR_API_KEY_HERE'] | ||
}), | ||
AgmDrawingModule | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
``` | ||
2. use it in your template | ||
|
||
```html | ||
<agm-map style="height: 300px" [latitude]="51.673858" [longitude]="7.815982" [agmDrawingManager]="drawing"> | ||
</agm-map> | ||
<agm-drawing-manager #drawing="agmDrawingManager" [drawingMode]="'circle'" [circleOptions]="{fillColor:'red', radius: 150}"></agm-drawing-manager> | ||
``` | ||
|
||
|
||
[drawing-manager]: https://developers.google.com/maps/documentation/javascript/reference/#drawing | ||
[agm]: https://angular-maps.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AgmMap } from '@agm/core'; | ||
import { AfterViewInit, Directive, Host, Input, OnDestroy } from '@angular/core'; | ||
import { first } from 'rxjs/operators'; | ||
import { AgmDrawingManager } from './drawing-manager'; | ||
|
||
@Directive({ | ||
selector: 'agm-map[agmDrawingManager]', | ||
exportAs: 'matDrawingManagerTrigger', | ||
}) | ||
export class AgmDrawingManagerTrigger implements AfterViewInit, OnDestroy{ | ||
|
||
/** The drawing manager to be attached to this trigger. */ | ||
// tslint:disable-next-line: no-input-rename | ||
@Input('agmDrawingManager') drawingManager: AgmDrawingManager; | ||
|
||
constructor(@Host() private _agmMap: AgmMap) { | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this._agmMap.mapReady.pipe(first()).subscribe(map => this.drawingManager.setMap(map)); | ||
} | ||
|
||
ngOnDestroy() { | ||
this._agmMap.mapReady.pipe(first()).subscribe(() => this.drawingManager.setMap(null)); | ||
} | ||
} |
Oops, something went wrong.