49959d498c0a815109c6b3b681e76bcf57b94ba4
[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 : 22.276022,
64                             longitude : 114.1751471,
65                             markerTitle : 'Drag Me',
66                             listeners : {
67                                 render : function (_self) {
68                                     _this.picker = _self;
69                                     
70                                     this.gMapContext.autocomplete = new google.maps.places.Autocomplete(_this.location.inputEl().dom);
71                                     
72                                     google.maps.event.addListener(this.gMapContext.autocomplete, "place_changed", function() {
73                                         var place = _this.picker.gMapContext.autocomplete.getPlace();
74                                         if (!place.geometry) {
75                                             Roo.log('location not found');
76                                             return;
77                                         }
78                                         _this.picker.setPosition(place.geometry.location);
79                                     });
80                                     
81                                 },
82                                 positionchanged : function (_self, location) {
83                                     if(_this.latitude){
84                                         _this.latitude.setValue(location.lat());
85                                     }
86                                     
87                                     if(_this.longitude){
88                                         _this.longitude.setValue(location.lng());
89                                     }
90                                 }
91                             }
92                         }
93                     ]
94                 },
95                 {
96                     xtype : 'Container',
97                     xns : Roo.bootstrap,
98                     items : [
99                         {
100                             xtype : 'Column',
101                             xns: Roo.bootstrap,
102                             md : 6,
103                             items : [
104                                 {
105                                     xtype : 'Input',
106                                     xns: Roo.bootstrap,
107                                     fieldLabel : 'Latitude',
108                                     labelAlign : 'top',
109                                     listeners : {
110                                         render : function (_self) {
111                                             _this.latitude = _self;
112                                         }
113                                     }
114                                 }
115                             ]
116                         },
117                         {
118                             xtype : 'Column',
119                             xns: Roo.bootstrap,
120                             md : 6,
121                             items : [
122                                 {
123                                     xtype : 'Input',
124                                     xns: Roo.bootstrap,
125                                     fieldLabel : 'Longitude',
126                                     labelAlign : 'top',
127                                     listeners : {
128                                         render : function (_self) {
129                                             _this.longitude = _self;
130                                         }
131                                     }
132                                 }
133                             ]
134                         }
135                     ]
136                 }
137             ]
138         }
139     }
140 });