Skip to content

Commit cd7a6d5

Browse files
committed
upgrade to support Polymer 2.0
1 parent 87513cd commit cd7a6d5

File tree

4 files changed

+94
-16
lines changed

4 files changed

+94
-16
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
}

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
Google Places Autocomplete attached to a paper-input, providing a convenient material design input for places.
44

5-
[Live Demo](https://mlisook.github.io/paper-input-place/)
5+
This release is a Polymer 2.0 hybrid element so it will work in 1.x or 2.0 Polymer applications.
6+
7+
[Live Demos](https://mlisook.github.io/paper-input-place/)
68

79
Basic use:
810

911
```html
10-
<paper-input-place api-key="your google api key" value="{{tourstop.place}}" hide-error></paper-input-place>
12+
<paper-input-place api-key="your google api key" value="{{tourstop.place}}"
13+
label="Pick a place" hide-error></paper-input-place>
1114
```
1215
The `value` property is an object:
1316

@@ -24,7 +27,7 @@ The `value` property is an object:
2427
Basic use with validation:
2528

2629
```html
27-
<paper-input-place api-key="your google api key" value="{{tourstop.place}}"></paper-input-place>
30+
<paper-input-place label="Pick a place" api-key="your google api key" value="{{tourstop.place}}"></paper-input-place>
2831
```
2932
## Installation
3033

@@ -184,8 +187,12 @@ The floating label for the paper-input.
184187
Indicates to the control that selection of a place is mandatory and that an empty input is not valid.
185188

186189
## Methods - Convenience Functions
190+
While not needed for the main purpose, the user entering a place, you may have existing data you
191+
need to geocode for use in the element. We make these functions available here since the Google
192+
API is already loaded.
193+
187194
### geocode(address)
188-
The `geocode` function takes an address as it's parameter and returns a _promise_ for a result which is a _place object_ as described in the place property above. Note that this does not have any effect on the control's properties (but, of course one could turn around and set the value property with information from the place detail returned).
195+
The `geocode` function takes an address as its parameter and returns a _promise_ for a result which is a _place object_ as described in the place property above. Note that this does not have any effect on the control's properties (but, of course one could turn around and set the value property with information from the place detail returned).
189196
```js
190197
this.$$('paper-input-place').geocode(address).then(
191198
function(result) {

bower.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "paper-input-place",
33
"description": "Google Places Autocomplete attached to paper-input",
44
"main": "paper-input-place.html",
5+
"demo": "demo/index.html",
56
"keywords": [
67
"polymer",
78
"place",
@@ -14,16 +15,18 @@
1415
],
1516
"license": "MIT",
1617
"dependencies": {
17-
"polymer": "Polymer/polymer#^1.9.1",
18-
"google-apis": "GoogleWebComponents/google-apis#^1.1.6",
19-
"paper-input": "PolymerElements/paper-input#^2.0.0"
18+
"polymer": "Polymer/polymer#1.9 - 2",
19+
"paper-input": "PolymerElements/paper-input#^2.0.0",
20+
"iron-jsonp-library": "PolymerElements/iron-jsonp-library#^2.0.0",
21+
"iron-icon": "PolymerElements/iron-icon#^2.0.0",
22+
"iron-iconset-svg": "PolymerElements/iron-iconset-svg#^2.0.0"
2023
},
2124
"devDependencies": {
22-
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
23-
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0",
24-
"web-component-tester": "^4.0.0",
25+
"iron-component-page": "PolymerElements/iron-component-page#^2.0.0",
26+
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^2.0.0",
27+
"web-component-tester": "^6.0.0",
2528
"highlightjs": "^9.5.0",
26-
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
29+
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
2730
},
28-
"version": "1.2.0"
31+
"version": "1.9.0"
2932
}

paper-input-place.html

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
<link rel="import" href="../polymer/polymer.html">
22
<link rel="import" href="../paper-input/paper-input.html" />
3-
<link rel="import" href="../google-apis/google-maps-api.html" />
3+
<link rel="import" href="../iron-jsonp-library/iron-jsonp-library.html">
44
<link rel="import" href="../iron-icon/iron-icon.html" />
55
<link rel="import" href="paper-input-place-icons.html" />
66

77
<!--
88
`paper-input-place`
9-
Google Places Autocomplete attached to paper-input
9+
10+
Google Places Autocomplete attached to paper-input.
11+
12+
This release is a Polymer 2.0 hybrid element so it will work in 1.x or 2.0 Polymer applications.
13+
14+
Basic use:
15+
16+
```html
17+
<paper-input-place api-key="your google api key" value="{{tourstop.place}}"
18+
label="Pick a place" hide-error></paper-input-place>
19+
```
20+
The `value` property is an object:
21+
22+
```js
23+
{
24+
"search": "Guggenheim Museum, 5th Avenue, New York, NY, United States",
25+
"place_id": "ChIJmZ5emqJYwokRuDz79o0coAQ",
26+
"latLng": {
27+
"lat": 40.7829796,
28+
"lng": -73.95897059999999
29+
}
30+
}
31+
```
32+
Basic use with validation:
33+
34+
```html
35+
<paper-input-place label="Pick a place" api-key="your google api key" value="{{tourstop.place}}"></paper-input-place>
36+
```
37+
38+
1039
1140
@demo demo/index.html
1241
13-
@version 1.1.0
42+
@version 1.9.0
1443
-->
1544

1645
<dom-module id="paper-input-place">
@@ -21,7 +50,22 @@
2150
}
2251
</style>
2352
<template is="dom-if" if="[[apiKey]]" restamp="true">
24-
<google-maps-api api-key="[[apiKey]]" on-api-load="_mapsApiLoaded"></google-maps-api>
53+
<!--
54+
NOTE: the GoogleWebComponents collection has not been updated
55+
to support Polymer 2.0 as of 5/31/2017. There is no estimated
56+
date at this time.
57+
58+
For that reason this control is using iron-jsonp-library to load
59+
the google maps api instead of <google-maps-api>. The url string
60+
is the same as what would have been issued by the <google-maps-api> so
61+
even if that control is used elsewhere in your 1.x app, the api will
62+
not be loaded twice.
63+
-->
64+
<iron-jsonp-library
65+
library-url="[[_gmapApiUrl]]"
66+
notify-event="map-api-load"
67+
library-loaded="{{_ijplLoaded}}"
68+
on-map-api-load="_mapsApiLoaded"></iron-jsonp-library>
2569
</template>
2670
<paper-input id="locationsearch" label="[[label]]" value="{{_value}}" invalid="[[invalid]]" disabled$="[[disabled]]" error-message="Invalid - please select a place">
2771
<iron-icon icon="papinpplc:clear" suffix on-tap="_clearLocation"></iron-icon>
@@ -171,6 +215,22 @@
171215
notify: true,
172216
value: "",
173217
observer: '_svalChanged'
218+
},
219+
/**
220+
* @private
221+
* The url for the google maps api
222+
*/
223+
_gmapApiUrl: {
224+
type: String,
225+
notify: true,
226+
computed: '_computeUrl(apiKey)'
227+
},
228+
/**
229+
* @private
230+
* jsonp loaded bool
231+
*/
232+
_ijplLoaded: {
233+
type: Boolean
174234
}
175235

176236
},
@@ -182,6 +242,11 @@
182242
}
183243
},
184244

245+
_computeUrl: function(akey) {
246+
return "https://maps.googleapis.com/maps/api/js?callback=%%callback%%&v=3.exp&libraries=drawing,geometry,places,visualization&key="
247+
+ akey;
248+
},
249+
185250
_mapsApiLoaded: function() {
186251
if (!this._geocoder && !this._places && this.$.locationsearch && this.$.locationsearch.$.nativeInput) {
187252
this._geocoder = new google.maps.Geocoder();

0 commit comments

Comments
 (0)