1+ import Ember from 'ember' ;
2+ import AbstractMapMixin from 'ember-cli-map/mixins/abstract-map' ;
3+ var gmapView ;
4+
5+ gmapView = Ember . Component . extend ( AbstractMapMixin , {
6+ mapType : 'asGoogleMap' ,
7+ initialize : ( function ( ) {
8+ var map , marker , options ;
9+ options = {
10+ zoom : this . get ( 'zoom' ) ,
11+ center : this . get ( 'center' ) ,
12+ mapTypeId : this . get ( 'mapTypeId' )
13+ } ;
14+ map = new google . maps . Map ( this . $ ( ) . find ( ".map" ) [ 0 ] , options ) ;
15+ marker = this . initMarker ( map ) ;
16+ this . initAutocomplete ( map , marker ) ;
17+ return google . maps . event . addListener ( map , 'zoom_changed' , ( function ( _this ) {
18+ return function ( ) {
19+ return _this . setZoom ( map . getZoom ( ) ) ;
20+ } ;
21+ } ) ( this ) ) ;
22+ } ) . on ( 'didInsertElement' ) ,
23+ center : ( function ( ) {
24+ var coord ;
25+ coord = this . centerCoords ( ) ;
26+ return new google . maps . LatLng ( coord [ 0 ] , coord [ 1 ] ) ;
27+ } ) . property ( ) ,
28+ mapTypeId : ( function ( ) {
29+ return google . maps . MapTypeId . ROADMAP ;
30+ } ) . property ( ) ,
31+ initMarker : function ( map ) {
32+ var marker , options ;
33+ options = {
34+ position : this . get ( 'center' ) ,
35+ map : map ,
36+ draggable : true
37+ } ;
38+ marker = new google . maps . Marker ( options ) ;
39+ google . maps . event . addListener ( marker , 'dragend' , ( function ( _this ) {
40+ return function ( event ) {
41+ var pos ;
42+ map . setCenter ( event . latLng ) ;
43+ pos = marker . getPosition ( ) ;
44+ return _this . setAttrs ( pos . lat ( ) , pos . lng ( ) ) ;
45+ } ;
46+ } ) ( this ) ) ;
47+ return marker ;
48+ } ,
49+ initAutocomplete : function ( map , marker ) {
50+ var autocomplete , autocompleteView , input ;
51+ autocompleteView = this . get ( 'MapAutocomplete' ) ;
52+ input = autocompleteView . $ ( ) [ 0 ] ;
53+ autocomplete = new google . maps . places . Autocomplete ( input , {
54+ types : [ 'geocode' ]
55+ } ) ;
56+ return google . maps . event . addListener ( autocomplete , 'place_changed' , ( function ( _this ) {
57+ return function ( ) {
58+ var place , pos ;
59+ place = autocomplete . getPlace ( ) ;
60+ if ( ! place . geometry ) {
61+ return ;
62+ }
63+ pos = place . geometry . location ;
64+ if ( place . geometry . viewport ) {
65+ map . fitBounds ( place . geometry . viewport ) ;
66+ } else {
67+ map . setCenter ( pos ) ;
68+ map . setZoom ( 17 ) ;
69+ }
70+ marker . setPosition ( pos ) ;
71+ return _this . setAttrs ( pos . lat ( ) , pos . lng ( ) ) ;
72+ } ;
73+ } ) ( this ) ) ;
74+ }
75+ } ) ;
76+
77+ export default gmapView ;
0 commit comments