examples/bootstrap/LocationPicker.js
[roojs1] / examples / bootstrap / LocationPicker.js
1
2
3 Roo.example = Roo.example || {};
4
5 Roo.example.locationpicker = new Roo.XComponent({
6     part     :  ["layout","viewpanel"],
7     order    : '001-viewpanel',
8     region   : '',
9     parent   : '#bootstrap',
10     name     : "unnamed module",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         
16         this.parent = {
17             el : new Roo.bootstrap.Body()
18         }
19         this.parent.el.layout = false;
20         this.parent.el.render(document.body);
21         
22         var _this = this;
23         var MODULE = this;
24         
25         return {
26             xtype: 'Body',
27             xns: Roo.bootstrap,
28             items :
29             [
30                 {
31                     xtype : 'Container',
32                     xns : Roo.bootstrap,
33                     items : [
34                         {
35                             xtype : 'Column',
36                             xns: Roo.bootstrap,
37                             md : 6,
38                             cls : 'col-md-offset-3',
39                             style : 'margin-top: 50px',
40                             items : [
41                                 {
42                                     xtype : 'Input',
43                                     xns: Roo.bootstrap,
44                                     fieldLabel : 'Location',
45                                     listeners : {
46                                         render : function (_self) {
47                                             _this.location = _self;
48                                         }
49                                     }
50                                 }
51                             ]
52                         }
53                     ]
54                 },
55                 {
56                     xtype : 'Container',
57                     xns : Roo.bootstrap,
58                     items : [
59                         {
60                             xtype : 'LocationPicker',
61                             xns: Roo.bootstrap,
62                             style : 'width:500px; height: 400px; border: 1px solid #000;margin:50px auto;',
63                             latitude : 46.15242437752303,
64                             longitude : 2.7470703125,
65                             listeners : {
66                                 render : function (_self) {
67                                     _this.picker = _self;
68                                     
69                                     this.gMapContext.autocomplete = new google.maps.places.Autocomplete(_this.location.inputEl().dom);
70                                     
71                                     google.maps.event.addListener(this.gMapContext.autocomplete, "place_changed", function() {
72                                         var place = _this.picker.gMapContext.autocomplete.getPlace();
73                                         if (!place.geometry) {
74                                             Roo.log('location not found');
75                                             return;
76                                         }
77                                         _this.picker.setPosition(place.geometry.location);
78                                     });
79                                 },
80                                 positionchanged : function (_self, location) {
81                                     if(_this.latitude){
82                                         _this.latitude.setValue(location.lat());
83                                     }
84                                     
85                                     if(_this.longitude){
86                                         _this.longitude.setValue(location.lng());
87                                     }
88                                 }
89                             }
90                         }
91                     ]
92                 },
93                 {
94                     xtype : 'Container',
95                     xns : Roo.bootstrap,
96                     items : [
97                         {
98                             xtype : 'Column',
99                             xns: Roo.bootstrap,
100                             md : 6,
101                             items : [
102                                 {
103                                     xtype : 'Input',
104                                     xns: Roo.bootstrap,
105                                     fieldLabel : 'Latitude',
106                                     labelAlign : 'top',
107                                     listeners : {
108                                         render : function (_self) {
109                                             _this.latitude = _self;
110                                         }
111                                     }
112                                 }
113                             ]
114                         },
115                         {
116                             xtype : 'Column',
117                             xns: Roo.bootstrap,
118                             md : 6,
119                             items : [
120                                 {
121                                     xtype : 'Input',
122                                     xns: Roo.bootstrap,
123                                     fieldLabel : 'Longitude',
124                                     labelAlign : 'top',
125                                     listeners : {
126                                         render : function (_self) {
127                                             _this.longitude = _self;
128                                         }
129                                     }
130                                 }
131                             ]
132                         }
133                     ]
134                 }
135             ]
136         }
137     }
138 });