You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(google-maps): Improve documentation for Google Maps. (#20492)
* docs(google-maps): Improve documentation for Google Maps.
Add new Google Maps components to documentation, including MapPolygon,
MapPolyline, MapRectangle, MapCircle, MapGroundOverlay, MapKmlLayer,
MapTransitLayer, MapTrafficLayer, and MapBicyclingLayer. Add
instructions on how to lazy load the Google Maps JavaScript API for use
with the @angular/google-maps components.
* Apply suggestions from code review
Co-authored-by: Jeremy Elbourn <jelbourn@gmail.com>
Co-authored-by: Jeremy Elbourn <jelbourn@gmail.com>
(cherry picked from commit 541c942)
Copy file name to clipboardExpand all lines: src/google-maps/README.md
+88-78Lines changed: 88 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -14,109 +14,119 @@ To install, run `npm install @angular/google-maps`.
14
14
- Load the [Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API).
15
15
- The Google Maps JavaScript API must be loaded before the `GoogleMap` component.
16
16
17
-
## GoogleMap
18
-
19
-
The `GoogleMap` component wraps the [`google.maps.Map` class](https://developers.google.com/maps/documentation/javascript/reference/map) from the Google Maps JavaScript API. You can configure the map via the component's inputs. The `options` input accepts a full [`google.maps.MapOptions` object](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions), and the component additionally offers convenience inputs for setting the `center` and `zoom` of the map without needing an entire `google.maps.MapOptions` object. The `height` and `width` inputs accept a string to set the size of the Google map. [Events](https://developers.google.com/maps/documentation/javascript/reference/map#Map.bounds_changed) can be bound using the outputs of the `GoogleMap` component, although events have the same name as native mouse events (e.g. `mouseenter`) have been prefixed with "map" as to not collide with the native mouse events. Other members on the `google.maps.Map` object are available on the `GoogleMap` component and can be accessed using the [`ViewChild` decorator](https://angular.io/api/core/ViewChild).
20
-
21
-
See the [example](#example) below or the [source](./google-map/google-map.ts) to read the API.
22
-
23
-
## MapMarker
24
-
25
-
The `MapMarker` component wraps the [`google.maps.Marker` class](https://developers.google.com/maps/documentation/javascript/reference/marker#Marker) from the Google Maps JavaScript API. The `MapMarker` component displays a marker on the map when it is a content child of a `GoogleMap` component. Like `GoogleMap`, this component offers an `options` input as well as convenience inputs for `position`, `title`, `label`, and `clickable`, and supports all `google.maps.Marker` events as outputs.
26
-
27
-
See the [example](#example) below or the [source](./map-marker/map-marker.ts) to read the API.
28
-
29
-
## MapInfoWindow
30
-
31
-
The `MapInfoWindow` component wraps the [`google.maps.InfoWindow` class](https://developers.google.com/maps/documentation/javascript/reference/info-window#InfoWindow) from the Google Maps JavaScript API. The `MapInfoWindow` has a `options` input as well as a convenience `position` input. Content for the `MapInfoWindow` is the inner HTML of the component, and will keep the structure and css styling of any content that is put there when it is displayed as an info window on the map.
32
-
33
-
To display the `MapInfoWindow`, it must be a child of a `GoogleMap` component, and it must have its `open` method called, so a reference to `MapInfoWindow` will need to be loaded using the [`ViewChild` decorator](https://angular.io/api/core/ViewChild). The `open` method accepts an `MapMarker` as an optional input, if you want to anchor the `MapInfoWindow` to a `MapMarker`.
See the [example](#example) below or the [source](./map-info-window/map-info-window.ts) to read the API.
27
+
## Lazy Loading the API
36
28
37
-
## Example
29
+
The API can be loaded when the component is actually used by using the Angular HttpClient jsonp method to make sure that the component doesn't load until after the API has loaded.
The Google Maps components implement all of the options for their respective objects from the Google Maps JavaScript API through an `options` input, but they also have specific inputs for some of the most common options. For example, the Google Maps component could have its options set either in with a google.maps.MapOptions object:
108
+
109
+
```html
110
+
<google-map[options]="options"></google-map>
111
+
```
112
+
113
+
```typescript
114
+
options: google.maps.MapOptions= {
115
+
center: {lat: 40, lng: -20},
116
+
zoom: 4
117
+
};
93
118
```
94
119
120
+
It can also have individual options set for some of the most common options:
Not every option has its own input. See the API for each component to see if the option has a dedicated input or if it should be set in the options input.
The `GoogleMap` component wraps the [`google.maps.Map` class](https://developers.google.com/maps/documentation/javascript/reference/map) from the Google Maps JavaScript API. You can configure the map via the component's inputs. The `options` input accepts a full [`google.maps.MapOptions` object](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions), and the component additionally offers convenience inputs for setting the `center` and `zoom` of the map without needing an entire `google.maps.MapOptions` object. The `height` and `width` inputs accept a string to set the size of the Google map. [Events](https://developers.google.com/maps/documentation/javascript/reference/map#Map.bounds_changed) can be bound using the outputs of the `GoogleMap` component, although events have the same name as native mouse events (e.g. `mouseenter`) have been prefixed with "map" as to not collide with the native mouse events. Other members on the `google.maps.Map` object are available on the `GoogleMap` component and can be accessed using the [`ViewChild` decorator](https://angular.io/api/core/ViewChild).
The `MapBicyclingLayer` component wraps the [`google.maps.BicyclingLayer` class](https://developers.google.com/maps/documentation/javascript/reference/map#BicyclingLayer) from the Google Maps JavaScript API.
The `MapCircle` component wraps the [`google.maps.Circle` class](https://developers.google.com/maps/documentation/javascript/reference/polygon#Circle) from the Google Maps JavaScript API.
The `MapGroundOverlay` component wraps the [`google.maps.BicyclingLayer` class](https://developers.google.com/maps/documentation/javascript/reference/image-overlay#GroundOverlay) from the Google Maps JavaScript API. A url and a bounds are required.
0 commit comments