|
| 1 | +import 'package:angular/angular.dart'; |
| 2 | +import 'package:angular/application_factory.dart'; |
| 3 | + |
| 4 | +import 'dart:html'; |
| 5 | +import 'dart:js'; |
| 6 | + |
| 7 | +/** |
| 8 | + * A component with a simple template which the Javascript Google Maps API |
| 9 | + * will use to install a map inside the ShadowRoot. |
| 10 | + */ |
| 11 | +@Component( |
| 12 | + selector: 'x-google-map', |
| 13 | + template: '<div style="height: 300px; width: 300px"></div>' |
| 14 | +) |
| 15 | +class XGoogleMaps implements ShadowRootAware { |
| 16 | + var map, infowindow; |
| 17 | + |
| 18 | + onShadowRoot(root) { |
| 19 | + // From https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/samples/google_maps/web/index.dart |
| 20 | + final gmaps = context['google']['maps']; |
| 21 | + var london = new JsObject(gmaps['LatLng'], [51.5, 0.125]); |
| 22 | + var mapOptions = new JsObject.jsify({ |
| 23 | + "center": london, |
| 24 | + "zoom": 8, |
| 25 | + }); |
| 26 | + |
| 27 | + map = new JsObject(gmaps['Map'], [root.querySelector('div'), mapOptions]); |
| 28 | + |
| 29 | + // The <content> tag is the exciting part of this component. Instead |
| 30 | + // of passing a string of HTML to the component, we use Shadow DOM to |
| 31 | + // punch a hole into the Shadow DOM allowing consumers to use parts of |
| 32 | + // their 'light DOM' |
| 33 | + infowindow = new JsObject(gmaps['InfoWindow'], [new JsObject.jsify({ |
| 34 | + "content": "<div style='height: 2em; width: 10em'><content></content></div>", |
| 35 | + "position": london |
| 36 | + })]); |
| 37 | + } |
| 38 | + |
| 39 | + @NgOneWay('info') |
| 40 | + set infoWindow(value) { |
| 41 | + if (value) { |
| 42 | + infowindow.callMethod('open', [map]); |
| 43 | + } else { |
| 44 | + infowindow.callMethod('close'); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +main() { |
| 50 | + var module = new Module() |
| 51 | + ..bind(XGoogleMaps); |
| 52 | + |
| 53 | + var injector = applicationFactory().addModule(module) |
| 54 | + .run(); |
| 55 | + var scope = injector.get(Scope); |
| 56 | +} |
0 commit comments