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

2.0 #440

Open
wants to merge 17 commits into
base: 2.0-preview
Choose a base branch
from
Open

2.0 #440

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
google-map
==========

If you are seeking a smaller, simplified version of `google-map`, we recommend using
[`good-map`](https://www.webcomponents.org/element/keanulee/good-map)


[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://beta.webcomponents.org/element/GoogleWebComponents/google-map)

<!---
Expand All @@ -20,10 +24,10 @@ google-map
```
-->
```html
<google-map fit-to-marker api-key="AIzaSyD3E1D9b-Z7ekrT3tbhl_dy8DCXuIuDDRc">
<google-map fit-to-markers api-key="AIzaSyD3E1D9b-Z7ekrT3tbhl_dy8DCXuIuDDRc">
<google-map-marker latitude="37.78" longitude="-122.4" draggable="true"></google-map-marker>
</google-map>
```

Breaking changes:
* Markers added to `<google-map>` must now specify `slot="markers"` to be added correctly.
* Markers added to `<google-map>` must now specify `slot="markers"` to be added correctly.
11 changes: 4 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"name": "google-map",
"version": "1.2.0",
"version": "2.0.5",
"description": "Google Maps web components",
"homepage": "https://elements.polymer-project.org/elements/google-map",
"main": [
"google-map.html",
"google-map-search.html",
"google-map-marker.html",
"google-map-directions.html"
"google-map-elements.html"
],
"authors": [
"Frankie Fu <ffu@google.com>",
Expand All @@ -29,13 +26,13 @@
],
"dependencies": {
"polymer": "Polymer/polymer#1.9 - 2",
"google-apis": "GoogleWebComponents/google-apis#^2.0.0",
"google-apis": "GoogleWebComponents/google-apis#1 - 2",
"iron-resizable-behavior": "PolymerElements/iron-resizable-behavior#1 - 2",
"iron-selector": "PolymerElements/iron-selector#1 - 2"
},
"devDependencies": {
"web-component-tester": "^6.0.0",
"iron-component-page": "PolymerElements/iron-component-page#^1 - 2"
"iron-component-page": "PolymerElements/iron-component-page#1 - 2"
},
"variants": {
"1.x": {
Expand Down
300 changes: 152 additions & 148 deletions google-map-directions.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,174 +40,178 @@
</google-maps-api>
</template>
<script>
Polymer({
is: 'google-map-directions',

/**
* Fired whenever the directions service returns a result.
*
* @event google-map-response
* @param {{response: Object}} detail
*/

/**
* Polymer properties for the google-map-directions custom element.
*/
properties: {
/**
* A Maps API key. To obtain an API key, see developers.google.com/maps/documentation/javascript/tutorial#api_key.
*/
apiKey: String,
(function() {
'use strict';

/**
* Overrides the origin the Maps API is loaded from. Defaults to `https://maps.googleapis.com`.
*/
mapsUrl: {
type: String
// Initial value set in google-maps-api.
},
Polymer({
is: 'google-map-directions',

/**
* The Google map object.
* Fired whenever the directions service returns a result.
*
* @type google.maps.Map
* @event google-map-response
* @param {{response: Object}} detail
*/
map: {
type: Object,
observer: '_mapChanged'
},

/**
* Start address or latlng to get directions from.
*
* @type string|google.maps.LatLng
* Polymer properties for the google-map-directions custom element.
*/
startAddress: {
type: String,
value: null
properties: {
/**
* A Maps API key. To obtain an API key, see developers.google.com/maps/documentation/javascript/tutorial#api_key.
*/
apiKey: String,

/**
* Overrides the origin the Maps API is loaded from. Defaults to `https://maps.googleapis.com`.
*/
mapsUrl: {
type: String
// Initial value set in google-maps-api.
},

/**
* The Google map object.
*
* @type google.maps.Map
*/
map: {
type: Object,
observer: '_mapChanged'
},

/**
* Start address or latlng to get directions from.
*
* @type string|google.maps.LatLng
*/
startAddress: {
type: String,
value: null
},

/**
* End address or latlng for directions to end.
*
* @type string|google.maps.LatLng
*/
endAddress: {
type: String,
value: null
},

/**
* Travel mode to use. One of 'DRIVING', 'WALKING', 'BICYCLING', 'TRANSIT'.
*/
travelMode: {
type: String,
value: 'DRIVING'
},

/**
* Array of intermediate waypoints. Directions will be calculated
* from the origin to the destination by way of each waypoint in this array.
* The maximum allowed waypoints is 8, plus the origin, and destination.
* Maps API for Business customers are allowed 23 waypoints,
* plus the origin, and destination.
* Waypoints are not supported for transit directions. Optional.
*
* @type Array<google.maps.DirectionsWaypoint>
*/
waypoints: {
type: Array,
value: function() { return []; }
},

/**
* The localized language to load the Maps API with. For more information
* see https://developers.google.com/maps/documentation/javascript/basics#Language
*
* Note: the Maps API defaults to the preffered language setting of the browser.
* Use this parameter to override that behavior.
*/
language: {
type: String,
value: null
},

/**
* Options for the display of results
*/
rendererOptions: {
type: Object,
value: function() { return {}; }
},

/**
* The response from the directions service.
*
*/
response: {
type: Object,
observer: '_responseChanged',
notify: true
}
},

/**
* End address or latlng for directions to end.
*
* @type string|google.maps.LatLng
*/
endAddress: {
type: String,
value: null
},
observers: [
'_route(startAddress, endAddress, travelMode, waypoints.*)'
],

/**
* Travel mode to use. One of 'DRIVING', 'WALKING', 'BICYCLING', 'TRANSIT'.
*/
travelMode: {
type: String,
value: 'DRIVING'
_mapApiLoaded: function() {
this._route();
},

/**
* Array of intermediate waypoints. Directions will be calculated
* from the origin to the destination by way of each waypoint in this array.
* The maximum allowed waypoints is 8, plus the origin, and destination.
* Maps API for Business customers are allowed 23 waypoints,
* plus the origin, and destination.
* Waypoints are not supported for transit directions. Optional.
*
* @type Array<google.maps.DirectionsWaypoint>
*/
waypoints: {
type: Array,
value: function() { return []; }
},

/**
* The localized language to load the Maps API with. For more information
* see https://developers.google.com/maps/documentation/javascript/basics#Language
*
* Note: the Maps API defaults to the preffered language setting of the browser.
* Use this parameter to override that behavior.
*/
language: {
type: String,
value: null
_responseChanged: function() {
if (this.directionsRenderer && this.response) {
this.directionsRenderer.setDirections(this.response);
}
},

/**
* Options for the display of results
*/
rendererOptions: {
type: Object,
value: function() { return {}; }
_mapChanged: function() {
if (this.map && this.map instanceof google.maps.Map) {
if (!this.directionsRenderer) {
this.directionsRenderer = new google.maps.DirectionsRenderer(this.rendererOptions);
}
this.directionsRenderer.setMap(this.map);
this._responseChanged();
} else {
// If there is no more map, remove the directionsRenderer from the map and delete it.
if (this.directionsRenderer) {
this.directionsRenderer.setMap(null);
this.directionsRenderer = null;
}
}
},

/**
* The response from the directions service.
*
*/
response: {
type: Object,
observer: '_responseChanged',
notify: true
}
},

observers: [
'_route(startAddress, endAddress, travelMode, waypoints.*)'
],

_mapApiLoaded: function() {
this._route();
},

_responseChanged: function() {
if (this.directionsRenderer && this.response) {
this.directionsRenderer.setDirections(this.response);
}
},

_mapChanged: function() {
if (this.map && this.map instanceof google.maps.Map) {
if (!this.directionsRenderer) {
this.directionsRenderer = new google.maps.DirectionsRenderer(this.rendererOptions);
_route: function() {
// Abort attempts to _route if the API is not available yet or the
// required attributes are blank.
if (typeof google == 'undefined' || typeof google.maps == 'undefined' ||
!this.startAddress || !this.endAddress) {
return;
}
this.directionsRenderer.setMap(this.map);
this._responseChanged();
} else {
// If there is no more map, remove the directionsRenderer from the map and delete it.
if (this.directionsRenderer) {
this.directionsRenderer.setMap(null);
this.directionsRenderer = null;

// Construct a directionsService if necessary.
// Wait until here where the maps api has loaded and directions are actually needed.
if (!this.directionsService) {
this.directionsService = new google.maps.DirectionsService();
}
}
},

_route: function() {
// Abort attempts to _route if the API is not available yet or the
// required attributes are blank.
if (typeof google == 'undefined' || typeof google.maps == 'undefined' ||
!this.startAddress || !this.endAddress) {
return;
}

// Construct a directionsService if necessary.
// Wait until here where the maps api has loaded and directions are actually needed.
if (!this.directionsService) {
this.directionsService = new google.maps.DirectionsService();
var request = {
origin: this.startAddress,
destination: this.endAddress,
travelMode: this.travelMode,
waypoints: this.waypoints
};
this.directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
this.response = response;
this.fire('google-map-response', {response: response});
}
}.bind(this));
}

var request = {
origin: this.startAddress,
destination: this.endAddress,
travelMode: this.travelMode,
waypoints: this.waypoints
};
this.directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
this.response = response;
this.fire('google-map-response', {response: response});
}
}.bind(this));
}
});
});
})();
</script>
</dom-module>
Loading