Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* $Id$ */
/**
* Address widget and GMap geocoder routines.
*/
////////////////////////////////////////
// GEOCODING //
////////////////////////////////////////
/**
* Provide a shared geocoder.
* Lazy initialize it so it's not resident until needed.
*/
Drupal.gmap.geocoder = function() {
var theGeocoder;
if (!theGeocoder) {
theGeocoder = new GClientGeocoder();
}
return theGeocoder;
};
Drupal.gmap.addHandler('gmap', function(elem) {
var obj = this;
obj.bind('geocode_pan', function(addr) {
Drupal.gmap.geocoder().getLatLng(addr,function(point) {
if(point) {
obj.vars.latitude = point.lat();
obj.vars.longitude = point.lng();
obj.change("move",-1);
}
else {
// Error condition?
}
});
});
obj.bind('geocode_panzoom', function(addr) {
Drupal.gmap.geocoder().getLocations(addr, function(response) {
if (response && response.Status.code == 200) {
var place = response.Placemark[0];
obj.vars.latitude = place.Point.coordinates[1];
obj.vars.longitude = place.Point.coordinates[0];
// This is, of course, temporary.
switch (place.AddressDetails.Accuracy) {
case 1: // Country level
obj.vars.zoom = 4;
break;
case 2: // Region (state, province, prefecture, etc.) level
obj.vars.zoom = 6;
break;
case 3: // Sub-region (county, municipality, etc.) level
obj.vars.zoom = 8;
break;
case 4: // Town (city, village) level accuracy. (Since 2.59)
case 5: // Post code (zip code) level accuracy. (Since 2.59)
case 6: // Street level accuracy. (Since 2.59)
case 7: // Intersection level accuracy. (Since 2.59)
case 8: // Address level accuracy. (Since 2.59)
obj.vars.zoom = 12;
}
obj.change('move',-1);
}
});
});
obj.bind('preparemarker', function(marker) {
if (marker.address && (!marker.latitude || !marker.longitude)) {
Drupal.gmap.geocoder().getLatLng(marker.address,function(point) {
if (point) {
marker.latitude = point.lat();
marker.longitude = point.lng();
}
});
}
});
});
////////////////////////////////////////
// Address widget //
////////////////////////////////////////
Drupal.gmap.addHandler('address', function(elem) {
var obj = this;
// Respond to focus event.
$(elem).focus(function() {
this.value = '';
});
// Respond to incoming movements.
// Clear the box when the coords change...
var binding = obj.bind("move", function(){
elem.value = 'Enter an address';
});
// Send out outgoing movements.
// This happens ASYNC!!!
$(elem).change(function() {
if (elem.value.length > 0) {
Drupal.gmap.geocoder().getLatLng(elem.value, function(point) {
if (point) {
obj.vars.latitude = point.lat();
obj.vars.longitude = point.lng();
obj.change("move",binding);
}
else {
// Todo: Get translated value using settings.
elem.value = 'Geocoder error: Address not found';
}
});
}
else {
// Was empty. Ignore.
elem.value = 'Enter an address';
}
});
});
////////////////////////////////////////
// Locpick address handler (testing) //
////////////////////////////////////////
Drupal.gmap.addHandler('locpick_address', function(elem) {
var obj = this;
// Respond to focus event.
$(elem).focus(function() {
this.value = '';
});
// Respond to incoming movements.
// Clear the box when the coords change...
var binding = obj.bind("locpickchange", function(){
elem.value = 'Enter an address';
});
// Send out outgoing movements.
// This happens ASYNC!!!
$(elem).change(function() {
if (elem.value.length > 0) {
Drupal.gmap.geocoder().getLatLng(elem.value,function(point) {
if (point) {
obj.locpick_coord = point;
obj.change("locpickchange",binding);
}
else {
// Todo: Get translated value using settings.
elem.value = 'Geocoder error: Address not found';
}
});
}
else {
// Was empty. Ignore.
elem.value = 'Enter an address';
}
});
});