Skip to content

Commit c2523ca

Browse files
tomtomauVheissu
authored andcommitted
feat(polygons): added polygons & drawing manager (#74)
* feat(drawing): add drawing mode in for overlays * fix(zoom): fix map bounds zoom issues
1 parent b19c0e4 commit c2523ca

18 files changed

+1665
-45
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
_BACKUP/
33
dist/test/
4+
.DS_Store
5+
.idea

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,30 @@ var myMarkers = [
215215
* `custom` (optional) - store arbitrary data (e.g. an `id` field) in this object, retrieve it from the `googlemap:marker:click` event payload
216216
* `infoWindow` (optional) - object - If set, the `googlemap:marker:click` evetn will not be called, instead an infowindow containing the given content will show up - see [docs](https://developers.google.com/maps/documentation/javascript/infowindows)
217217

218+
### Drawing Mode
219+
220+
Allows usage of Google Maps' Drawing API to add Markers, Polylines, Polygons, Rectangles and Circles to the map instance. To allow this, simply set the defaults as below:
221+
222+
``` html
223+
<google-map draw-enable.bind="true" draw-mode="polygon"></google-map>
224+
```
225+
226+
The `draw-mode` can take the same values as defined [here](https://developers.google.com/maps/documentation/javascript/reference#OverlayType)
227+
228+
#### Drawing Events
229+
230+
One of the drawing events has been exposed to the element as a `CustomEvent` and a callback can be set as below:
231+
232+
``` html
233+
<google-map map-overlay-complete.delegate="callback($event)"></google-map>
234+
```
235+
236+
The event object is the same as given [here](https://developers.google.com/maps/documentation/javascript/reference#OverlayCompleteEvent) with the addition of the `encoded` variable. This is the encoded polyline (you can play around with it [here](https://developers.google.com/maps/documentation/utilities/polylineutility)).
237+
238+
In addition to the `map-overlay-complete` event, an event is also propagated through Aurelia's Event Aggregator:
239+
240+
* `googlemap:draw:overlaycomplete` - Emitted when an overlay drawing has been completed
241+
218242
## Supported Properties
219243

220244
* latitude: A latitude value for the map
@@ -233,6 +257,7 @@ var myMarkers = [
233257
## Supported Events
234258

235259
- map-click: Delegate a handler with `map-click.delegate="callback($event)"`
260+
- map-overlay-complete: Delegate a handler with `map-overlay-complete.delegate="callback($event)"`
236261

237262
## Todo
238263
This element still is missing some features, but they are in development.

dist/amd/google-maps.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export declare class GoogleMaps {
2626
private eventAggregator;
2727
private googleMapsApi;
2828
private _geocoder;
29+
private _currentInfoWindow;
2930
longitude: number;
3031
latitude: number;
3132
zoom: number;
@@ -35,12 +36,21 @@ export declare class GoogleMaps {
3536
mapType: string;
3637
options: {};
3738
mapLoaded: any;
39+
drawEnabled: boolean;
40+
drawMode: string;
41+
drawOverlayCompleteEvent: any;
42+
polygons: any;
43+
drawingControl: true;
44+
drawingControlOptions: {};
3845
map: any;
3946
_renderedMarkers: any[];
4047
_markersSubscription: any;
4148
_scriptPromise: Promise<any> | any;
4249
_mapPromise: Promise<any> | any;
4350
_mapResolve: Promise<any> | any;
51+
drawingManager: any;
52+
_renderedPolygons: any;
53+
_polygonsSubscription: any;
4454
constructor(element: Element, taskQueue: TaskQueue, config: Configure, bindingEngine: BindingEngine, eventAggregator: EventAggregator, googleMapsApi: GoogleMapsAPI);
4555
clearMarkers(): void;
4656
attached(): void;
@@ -62,4 +72,14 @@ export declare class GoogleMaps {
6272
getMapTypeId(): any;
6373
error(): void;
6474
resize(): void;
75+
initDrawingManager(options?: any): any;
76+
destroyDrawingManager(): void;
77+
getOverlayType(type?: any): any;
78+
drawEnabledChanged(newval: any, oldval: any): void;
79+
drawModeChanged(newval?: any): void;
80+
encodePath(path?: any): any;
81+
decodePath(polyline: string): any;
82+
renderPolygon(polygonObject?: any): void;
83+
polygonsChanged(newValue: any): void;
84+
polygonCollectionChange(splices: any): void;
6585
}

0 commit comments

Comments
 (0)