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                                 },
81                                 positionchanged : function (_self, location) {
82                                     if(_this.latitude){
83                                         _this.latitude.setValue(location.lat());
84                                     }
85                                     
86                                     if(_this.longitude){
87                                         _this.longitude.setValue(location.lng());
88                                     }
89                                 }
90                             }
91                         }
92                     ]
93                 },
94                 {
95                     xtype : 'Container',
96                     xns : Roo.bootstrap,
97                     items : [
98                         {
99                             xtype : 'Column',
100                             xns: Roo.bootstrap,
101                             md : 6,
102                             items : [
103                                 {
104                                     xtype : 'Input',
105                                     xns: Roo.bootstrap,
106                                     fieldLabel : 'Latitude',
107                                     labelAlign : 'top',
108                                     listeners : {
109                                         render : function (_self) {
110                                             _this.latitude = _self;
111                                         }
112                                     }
113                                 }
114                             ]
115                         },
116                         {
117                             xtype : 'Column',
118                             xns: Roo.bootstrap,
119                             md : 6,
120                             items : [
121                                 {
122                                     xtype : 'Input',
123                                     xns: Roo.bootstrap,
124                                     fieldLabel : 'Longitude',
125                                     labelAlign : 'top',
126                                     listeners : {
127                                         render : function (_self) {
128                                             _this.longitude = _self;
129                                         }
130                                     }
131                                 }
132                             ]
133                         }
134                     ]
135                 }
136             ]
137         }
138     }
139 });