├── .gitignore ├── demo ├── img-1.png ├── img-2.png ├── img-3.png ├── img-4.png ├── img-5.png ├── img-6.png ├── img-7.png ├── img-8.png ├── survey.html ├── step.html ├── codelab.html └── embed.html ├── google-sans.html ├── font-source-code-pro.html ├── google-codelab-elements.html ├── .drone.yml ├── README.md ├── shared-style.html ├── index.html ├── bower.json ├── CONTRIBUTING.md ├── layout-style.html ├── syntax-style.html ├── test ├── embed.html ├── step.html ├── survey.html ├── ga.html └── codelab.html ├── analytics-behavior.html ├── google-codelab-step.html ├── google-codelab-survey.html ├── codelab-style.html ├── LICENSE ├── google-codelab.html └── step-style.html /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | node_modules 3 | -------------------------------------------------------------------------------- /demo/img-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-1.png -------------------------------------------------------------------------------- /demo/img-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-2.png -------------------------------------------------------------------------------- /demo/img-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-3.png -------------------------------------------------------------------------------- /demo/img-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-4.png -------------------------------------------------------------------------------- /demo/img-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-5.png -------------------------------------------------------------------------------- /demo/img-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-6.png -------------------------------------------------------------------------------- /demo/img-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-7.png -------------------------------------------------------------------------------- /demo/img-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidagarwal04/codelab-components/master/demo/img-8.png -------------------------------------------------------------------------------- /google-sans.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /font-source-code-pro.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /google-codelab-elements.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | clone: 2 | depth: 1 3 | build: 4 | image: crhym3/ci-image:node6-go16 5 | environment: 6 | - CHROME=https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 7 | commands: 8 | # use custom version of wct-local 9 | # until https://github.com/Polymer/wct-local/pull/17 is merged 10 | - npm i web-component-tester crhym3/wct-local#args --only=prod --no-optional 11 | - bower install --allow-root 12 | - curl -sSLo chrome.deb $CHROME && dpkg -i chrome.deb 13 | - > 14 | xvfb-run -a ./node_modules/.bin/wct 15 | --skip-plugin sauce 16 | --plugin local 17 | --verbose 18 | -l chrome 19 | --skip-selenium-install 20 | --selenium-arg=-Djava.security.egd=file:///dev/urandom 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Codelab Components 2 | 3 | A set of Polymer elements, core of the Google Codelabs platform. 4 | 5 | ## Dev setup 6 | 7 | `bower install` is the obvious first thing to do. 8 | 9 | To play with the demos, an easy thing would be to use 10 | [polyserve](https://github.com/PolymerLabs/polyserve): 11 | `npm install -g polyserve`. 12 | 13 | Fire up the server with `polyserve` command and point your browser to: 14 | 15 | http://localhost:8080/components/codelab-components/ 16 | 17 | Use [web-component-tester](https://github.com/Polymer/web-component-tester) to run tests. 18 | Can be installed with `npm install -g web-component-tester`, or just fire up `polyserve` 19 | and navigate to `/components/codelab_components/test/`. 20 | -------------------------------------------------------------------------------- /shared-style.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 28 | 29 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codelab-components", 3 | "version": "3.0.0", 4 | "private": true, 5 | "main": "google-codelab-elements.html", 6 | "license": "Apache2", 7 | "dependencies": { 8 | "app-layout": "PolymerElements/app-layout#^0.10.0", 9 | "iron-a11y-keys-behavior": "PolymerElements/iron-a11y-keys-behavior#^1.0.5", 10 | "iron-flex-layout": "PolymerElements/iron-flex-layout#^1.0.3", 11 | "iron-icons": "PolymerElements/iron-icons#^1.0.3", 12 | "iron-localstorage": "PolymerElements/iron-localstorage#^1.0.4", 13 | "neon-animation": "PolymerElements/neon-animation#^1.2.2", 14 | "paper-button": "PolymerElements/paper-button#^1.0.3", 15 | "paper-dialog": "PolymerElements/paper-dialog#^1.0.1", 16 | "paper-fab": "PolymerElements/paper-fab#^1.0.3", 17 | "paper-icon-button": "PolymerElements/paper-icon-button#^1.0.3", 18 | "paper-item": "PolymerElements/paper-item#^1.0.2", 19 | "paper-menu": "PolymerElements/paper-menu#^1.1.0", 20 | "paper-radio-button": "PolymerElements/paper-radio-button#^1.0.6", 21 | "paper-radio-group": "PolymerElements/paper-radio-group#^1.0.4", 22 | "paper-styles": "PolymerElements/paper-styles#^1.0.11", 23 | "google-prettify": "google/code-prettify" 24 | }, 25 | "devDependencies": { 26 | "iron-test-helpers": "PolymerElements/iron-test-helpers#^1.0.2", 27 | "test-fixture": "PolymerElements/test-fixture#^1.0.0", 28 | "web-component-tester": "*", 29 | "iron-component-page": "PolymerElements/iron-component-page#^1.0.8" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at the end). 2 | 3 | ### Before you contribute 4 | Before we can use your code, you must sign the 5 | [Google Individual Contributor License Agreement] 6 | (https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the 8 | copyright to your changes, even after your contribution becomes part of our 9 | codebase, so we need your permission to use and distribute your code. We also 10 | need to be sure of various other things—for instance that you'll tell us if you 11 | know that your code infringes on other people's patents. You don't have to sign 12 | the CLA until after you've submitted your code for review and a member has 13 | approved it, but you must do it before we can put your code into our codebase. 14 | Before you start working on a larger contribution, you should get in touch with 15 | us first through the issue tracker with your idea so that we can help out and 16 | possibly guide you. Coordinating up front makes it much easier to avoid 17 | frustration later on. 18 | 19 | ### Code reviews 20 | All submissions, including submissions by project members, require review. We 21 | use Github pull requests for this purpose. 22 | 23 | ### The small print 24 | Contributions made by corporations are covered by a different agreement than 25 | the one above, the 26 | [Software Grant and Corporate Contributor License Agreement] 27 | (https://cla.developers.google.com/about/google-corporate). 28 | -------------------------------------------------------------------------------- /layout-style.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 61 | 62 | -------------------------------------------------------------------------------- /syntax-style.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 66 | 67 | -------------------------------------------------------------------------------- /test/embed.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | embed tests 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 48 | 49 | 50 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /test/step.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | step tests 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 41 | 42 | 43 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /demo/survey.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | survey demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |

An example of <google-codelab-survey>

32 | 33 | 64 | 65 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /analytics-behavior.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 93 | -------------------------------------------------------------------------------- /test/survey.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | survey tests 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 52 | 53 | 54 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /test/ga.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | survey tests 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /google-codelab-step.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 53 | 54 | 66 | 157 | 158 | -------------------------------------------------------------------------------- /google-codelab-survey.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 49 | 50 | 84 | 189 | 190 | -------------------------------------------------------------------------------- /codelab-style.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 302 | 303 | -------------------------------------------------------------------------------- /demo/step.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | step demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 37 |

An example of <google-codelab-step>

38 | 39 | 170 | 171 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015 Google Inc 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /demo/codelab.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | codelab demo 23 | 24 | 31 | 33 | 34 | 35 | 36 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 |

In this codelab, You'll create a fully working Google Maps app using elements in Polymer's Google Web Components collection. The app will be responsive, include driving directions, and transit a mode. Along the way, you'll also learn about Polymer's data-binding features and iron element set.

53 |

What you'll learn

54 |
    55 |
  • How to start a new Polymer-based project using Chrome Dev Editor
  • 56 |
  • How to use elements in Polymer's iron, paper, and Google Web Component sets.
  • 57 |
  • How to use Polymer's data binding features to reduce boilerplate code.
  • 58 |
59 |

What you'll need

60 |
    61 |
  • Basic understanding of HTML, CSS, and web development.
  • 62 |
  • Install Chrome Dev Editor or use your own editor of choice.
  • 63 |
64 |

How would rate your experience with Polymer?

65 | NoviceIntermediateAdvanced
66 | 67 |
68 | 69 | 70 | 71 |

Create a new project

72 | 73 | 75 | 76 |

A paper-button wrapped into anchor element:

77 |

Example with an icon

78 |

Example without an icon

79 | 80 |

The first time you run Chrome Dev Editor it will ask you to setup your workspace environment.

Fire up Chrome Dev Editor and start a new project:

    81 |
  1. Click to start a new project.
  2. 82 |
  3. Enter "PolymerMapsCodelab" as the Project name.
  4. 83 |
  5. In the Project type dropdown, select "JavaScript web app (using Polymer paper elements)".
  6. 84 |
  7. Click the Create button.
  8. 85 |

Chrome Dev Editor creates a basic scaffold for your Polymer app. In the background, it also uses Bower to download and install a list of dependencies (including the Polymer core library) into the bower_components/ folder. Fetching the components make take some time if your internet connection is slow. You'll learn more about using Bower in the next step.

86 |

bower.json

87 | 88 |
PolymerMapsCodelab/
 89 |   bower_components/ <!-- installed dependencies from Bower -->
 90 |   bower.json  <!-- Bower metadata files used for managing deps -->
 91 |   index.html  <!-- your app -->
 92 |   main.js
 93 |   styles.css
94 | 95 |

Preview the app

96 |

At any point, select the index.html file and hit the  button in the top toolbar to run the app. Chrome Dev Editor fires up a web server and navigates to the index.html page. This is great way to preview changes as you make them.

97 |

Next up

98 |

At this point the app doesn't do much. Let's add a map!

99 | 100 |
101 | 102 | 103 | 104 |

The Google Web Components provide the <google-map> element for declaratively rendering a Google Map. To use it, you first need to install it using Bower.

105 | 107 | 108 |

Install the element

109 |

Normally, you'd run bower install GoogleWebComponents/google-map --save on the command line to install <google-map> and save it as a dependency. However, Chrome Dev Editor does not have a command line for running Bower commands. Instead, you need to manually edit bower.json to include google-map, then run Chrome Dev Editor's Bower Update feature. Bower Update checks the dependencies in bower.json and installs any missing ones.

  1. Edit bower.json and add google-map to the dependencies object:
110 |
"dependencies": {
111 |   "iron-elements": "PolymerElements/iron-elements#^1.0.0",
112 |   "paper-elements": "PolymerElements/paper-elements#^1.0.1",
113 |   "google-map": "GoogleWebComponents/google-map#^1.0.3"
114 | }
115 |
    116 |
  1. Right-click the bower.json filename in the editor.
  2. 117 |
  3. Select Bower Update from the context menu.
  4. 118 |

The download may take few seconds. You can verify that <google-map> (and any dependencies) were installed by checking that bower_components/google-map/ was created and populated.

119 |

Use the element

120 |

To employ <google-map>, you need to:

    121 |
  1. Use an HTML Import to load it in index.html.
  2. 122 |
  3. Declare an instance of the element on the page.
  4. 123 |

In index.html, remove all other HTML imports in the <head> and replace them with a single import that loads google-map.html:

124 |

index.html

125 | 126 |
<head>
127 |   ....
128 |   <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
129 |   <link rel="import" href="bower_components/google-map/google-map.html">
130 | </head>
131 | 132 | 133 |

Next, replace the contents of <body> with an instance of <google-map>:

134 |

index.html

135 | 136 |
<body unresolved>
137 |   <google-map latitude="37.779" longitude="-122.3892" zoom="13"></google-map>
138 | </body>
139 |

As you can see, using <google-map> is completely declarative! The map is centered using the latitude and longitude attributes and its zoom level is set by the zoom attribute.

140 |

Style the map

141 |

If you run the app right now, nothing will display. In order for the map to properly display itself, you need to set its container (in this case, <body>) to have a fixed height.

Open styles.css and replace its contents with default styling:

142 |

styles.css

143 | 144 |
body, html {
145 |   font-family: 'Roboto', Arial, sans-serif;
146 |   height: 100%;
147 |   margin: 0;
148 | }
149 | 150 |

Add a marker

151 |

<google-map> supports adding map markers to the map by declaring <google-map-marker> elements as children. The marker locations are also set using latitude and longitude attributes.

Back in index.html, add a draggable <google-map-marker> to the map:

152 |

index.html

153 | 154 |
<google-map latitude="37.779" longitude="-122.3892" zoom="13" disable-default-ui>
155 |   <google-map-marker latitude="37.779" longitude="-122.3892"
156 |       title="Go Giants!" draggable="true"></google-map-marker>
157 | </google-map>
158 |

Notice that we've also disabled the map's controls by setting disableDefaultUi to true. Since it's a boolean property, its presence as an HTML attribute makes it truthy.

159 |

Run the app

160 |

If you haven't already done so, hit the  button. At this point, you should see a map that takes up the entire viewport and has a single marker pin.

161 |

Frequently Asked Questions

162 | 167 | 168 |
169 | 170 |
171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /test/codelab.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | survey tests 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 47 | 48 | 49 | 298 | 299 | 300 | -------------------------------------------------------------------------------- /demo/embed.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Embeddable codelab demo 23 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 54 | 55 | 56 | 57 |
58 | 59 |

Codelabs > Build Google Maps Using Web Components & No Code!

60 | 61 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis dolor vel arcu blandit tristique. Proin vestibulum nec felis non fringilla. Pellentesque vulputate dui ut risus bibendum, sed egestas arcu ullamcorper. Quisque eget eros pellentesque, aliquet tortor placerat, vehicula lectus. Fusce sit amet mattis turpis, et tempus orci. Vestibulum mauris velit, vulputate a risus quis, imperdiet hendrerit ante. Nunc sollicitudin risus tortor, ac venenatis sem volutpat malesuada. Mauris neque metus, ornare eget porta id, tincidunt vitae magna. In scelerisque quam auctor maximus pellentesque. Sed laoreet ex mi, vel lacinia urna consectetur id. Sed est quam, finibus eget orci in, vulputate tempus diam

62 | 63 | 71 | 72 | 73 | 74 |

In this codelab, You'll create a fully working Google Maps app using elements in Polymer's Google Web Components collection. The app will be responsive, include driving directions, and transit a mode. Along the way, you'll also learn about Polymer's data-binding features and iron element set.

75 |

What you'll learn

76 |
    77 |
  • How to start a new Polymer-based project using Chrome Dev Editor
  • 78 |
  • How to use elements in Polymer's iron, paper, and Google Web Component sets.
  • 79 |
  • How to use Polymer's data binding features to reduce boilerplate code.
  • 80 |
81 |

What you'll need

82 |
    83 |
  • Basic understanding of HTML, CSS, and web development.
  • 84 |
  • Install Chrome Dev Editor or use your own editor of choice.
  • 85 |
86 |

How would rate your experience with Polymer?

87 | NoviceIntermediateAdvanced
88 | 89 |
90 | 91 | 92 | 93 |

Create a new project

94 | 95 | 97 |

The first time you run Chrome Dev Editor it will ask you to setup your workspace environment.

Fire up Chrome Dev Editor and start a new project:

    98 |
  1. Click to start a new project.
  2. 99 |
  3. Enter "PolymerMapsCodelab" as the Project name.
  4. 100 |
  5. In the Project type dropdown, select "JavaScript web app (using Polymer paper elements)".
  6. 101 |
  7. Click the Create button.
  8. 102 |

Chrome Dev Editor creates a basic scaffold for your Polymer app. In the background, it also uses Bower to download and install a list of dependencies (including the Polymer core library) into the bower_components/ folder. Fetching the components make take some time if your internet connection is slow. You'll learn more about using Bower in the next step.

103 |

bower.json

104 | 105 |
PolymerMapsCodelab/
106 |   bower_components/ <!-- installed dependencies from Bower -->
107 |   bower.json  <!-- Bower metadata files used for managing deps -->
108 |   index.html  <!-- your app -->
109 |   main.js
110 |   styles.css
111 | 112 |

Preview the app

113 |

At any point, select the index.html file and hit the  button in the top toolbar to run the app. Chrome Dev Editor fires up a web server and navigates to the index.html page. This is great way to preview changes as you make them.

114 |

Next up

115 |

At this point the app doesn't do much. Let's add a map!

116 | 117 |
118 | 119 | 120 | 121 |

The Google Web Components provide the <google-map> element for declaratively rendering a Google Map. To use it, you first need to install it using Bower.

122 | 124 | 125 |

Install the element

126 |

Normally, you'd run bower install GoogleWebComponents/google-map --save on the command line to install <google-map> and save it as a dependency. However, Chrome Dev Editor does not have a command line for running Bower commands. Instead, you need to manually edit bower.json to include google-map, then run Chrome Dev Editor's Bower Update feature. Bower Update checks the dependencies in bower.json and installs any missing ones.

  1. Edit bower.json and add google-map to the dependencies object:
127 |
"dependencies": {
128 |   "iron-elements": "PolymerElements/iron-elements#^1.0.0",
129 |   "paper-elements": "PolymerElements/paper-elements#^1.0.1",
130 |   "google-map": "GoogleWebComponents/google-map#^1.0.3"
131 | }
132 |
    133 |
  1. Right-click the bower.json filename in the editor.
  2. 134 |
  3. Select Bower Update from the context menu.
  4. 135 |

The download may take few seconds. You can verify that <google-map> (and any dependencies) were installed by checking that bower_components/google-map/ was created and populated.

136 |

Use the element

137 |

To employ <google-map>, you need to:

    138 |
  1. Use an HTML Import to load it in index.html.
  2. 139 |
  3. Declare an instance of the element on the page.
  4. 140 |

In index.html, remove all other HTML imports in the <head> and replace them with a single import that loads google-map.html:

141 |

index.html

142 | 143 |
<head>
144 |   ....
145 |   <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
146 |   <link rel="import" href="bower_components/google-map/google-map.html">
147 | </head>
148 | 149 | 150 |

Next, replace the contents of <body> with an instance of <google-map>:

151 |

index.html

152 | 153 |
<body unresolved>
154 |   <google-map latitude="37.779" longitude="-122.3892" zoom="13"></google-map>
155 | </body>
156 |

As you can see, using <google-map> is completely declarative! The map is centered using the latitude and longitude attributes and its zoom level is set by the zoom attribute.

157 |

Style the map

158 |

If you run the app right now, nothing will display. In order for the map to properly display itself, you need to set its container (in this case, <body>) to have a fixed height.

Open styles.css and replace its contents with default styling:

159 |

styles.css

160 | 161 |
body, html {
162 |   font-family: 'Roboto', Arial, sans-serif;
163 |   height: 100%;
164 |   margin: 0;
165 | }
166 | 167 |

Add a marker

168 |

<google-map> supports adding map markers to the map by declaring <google-map-marker> elements as children. The marker locations are also set using latitude and longitude attributes.

Back in index.html, add a draggable <google-map-marker> to the map:

169 |

index.html

170 | 171 |
<google-map latitude="37.779" longitude="-122.3892" zoom="13" disable-default-ui>
172 |   <google-map-marker latitude="37.779" longitude="-122.3892"
173 |       title="Go Giants!" draggable="true"></google-map-marker>
174 | </google-map>
175 |

Notice that we've also disabled the map's controls by setting disableDefaultUi to true. Since it's a boolean property, its presence as an HTML attribute makes it truthy.

176 |

Run the app

177 |

If you haven't already done so, hit the  button. At this point, you should see a map that takes up the entire viewport and has a single marker pin.

178 |

Frequently Asked Questions

179 | 181 | 182 |
183 | 184 |
185 | 186 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis dolor vel arcu blandit tristique. Proin vestibulum nec felis non fringilla. Pellentesque vulputate dui ut risus bibendum, sed egestas arcu ullamcorper. Quisque eget eros pellentesque, aliquet tortor placerat, vehicula lectus. Fusce sit amet mattis turpis, et tempus orci. Vestibulum mauris velit, vulputate a risus quis, imperdiet hendrerit ante. Nunc sollicitudin risus tortor, ac venenatis sem volutpat malesuada. Mauris neque metus, ornare eget porta id, tincidunt vitae magna. In scelerisque quam auctor maximus pellentesque. Sed laoreet ex mi, vel lacinia urna consectetur id. Sed est quam, finibus eget orci in, vulputate tempus diam

187 | 188 |
189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /google-codelab.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 67 | 68 | 176 | 552 | 553 | -------------------------------------------------------------------------------- /step-style.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 302 | 303 | --------------------------------------------------------------------------------