1 | function editLocation(){ |
---|
2 | if (GBrowserIsCompatible()) { |
---|
3 | |
---|
4 | var mapping = {'Map':G_NORMAL_MAP, 'Satellite':G_SATELLITE_MAP,'Hybrid':G_HYBRID_MAP}, |
---|
5 | map_t='', |
---|
6 | lat = document.getElementById('latitude'), |
---|
7 | lng = document.getElementById('longitude'), |
---|
8 | lat_el = document.getElementById('maplatitude'), |
---|
9 | lng_el = document.getElementById('maplongitude'), |
---|
10 | map_lat = lat_el.value, |
---|
11 | map_lng = lng_el.value, |
---|
12 | zoom_el = document.getElementById('mapzoom'), |
---|
13 | map_zoom = zoom_el.value, |
---|
14 | map_type = document.getElementsByName('maptype'), |
---|
15 | lat_val = lat.value!=''?lat.value:0, |
---|
16 | lng_val = lng.value!=''?lng.value:0, |
---|
17 | map = new GMap2(document.getElementById('geomap')); |
---|
18 | |
---|
19 | function validator(a,b){ |
---|
20 | if (isNaN(a) || isNaN(b) || a=='' || b=='') return false; |
---|
21 | if (-90<=a && a<=90 && -180<=b && b<=180) return true; |
---|
22 | return false; |
---|
23 | }; |
---|
24 | |
---|
25 | function selectlistener(){ |
---|
26 | var z = zoom_el.value!=''?zoom_el.value:6; |
---|
27 | map.setZoom(parseInt(z)); |
---|
28 | }; |
---|
29 | function fieldlistener(){ |
---|
30 | if (validator(lat_el.value, lng_el.value)) |
---|
31 | map.setCenter(new GLatLng(parseFloat(lat_el.value), parseFloat(lng_el.value))); |
---|
32 | }; |
---|
33 | function boxlistener(){ |
---|
34 | var el = window.event?window.event.srcElement:this; |
---|
35 | map.setMapType(mapping[el.value]); |
---|
36 | }; |
---|
37 | function addMarker(lat, lng){ |
---|
38 | var point = new GLatLng(lat, lng); |
---|
39 | var marker = new GMarker(point) |
---|
40 | map.addOverlay(marker); |
---|
41 | }; |
---|
42 | function mapmarkerlistener(marker, point){ |
---|
43 | if (!marker){ |
---|
44 | map.clearOverlays(); |
---|
45 | addMarker(point.y, point.x); |
---|
46 | lat.value = point.y; |
---|
47 | lng.value = point.x; |
---|
48 | } |
---|
49 | }; |
---|
50 | function maptypelistener(){document.getElementById(map.getCurrentMapType().getName()).click();}; |
---|
51 | function mapzoomlistener(oldzoom, newzoom){zoom_el.selectedIndex = newzoom+1;}; |
---|
52 | function mapcenterlistener(){ |
---|
53 | lat_el.value = map.getCenter().lat(); |
---|
54 | lng_el.value = map.getCenter().lng(); |
---|
55 | }; |
---|
56 | |
---|
57 | map.addControl(new GLargeMapControl()); |
---|
58 | map.addControl(new GMapTypeControl()); |
---|
59 | map.addControl(new GOverviewMapControl()); |
---|
60 | |
---|
61 | for (var i=0; i<map_type.length; i++) { |
---|
62 | if (map_type[i].checked) map_t = map_type[i].value; |
---|
63 | registerEventListener(map_type[i], 'click', boxlistener, false); |
---|
64 | }; |
---|
65 | |
---|
66 | var map_x = map_lat!=''?map_lat:lat_val, map_t, |
---|
67 | map_y = map_lng!=''?map_lng:lng_val, |
---|
68 | map_z = map_zoom!=''?map_zoom:6, |
---|
69 | map_t = map_t=='Map'?G_NORMAL_MAP:map_t=='Satellite'?G_SATELLITE_MAP:G_HYBRID_MAP; |
---|
70 | |
---|
71 | map.setCenter(new GLatLng(parseFloat(map_x), parseFloat(map_y)), parseInt(map_z), map_t); |
---|
72 | |
---|
73 | GEvent.addListener(map, 'maptypechanged', maptypelistener); |
---|
74 | GEvent.addListener(map, 'zoomend', mapzoomlistener); |
---|
75 | GEvent.addListener(map, 'moveend', mapcenterlistener); |
---|
76 | GEvent.addListener(map, 'click', mapmarkerlistener); |
---|
77 | addMarker(parseFloat(lat_val), parseFloat(lng_val)); |
---|
78 | |
---|
79 | registerEventListener(zoom_el, 'change', selectlistener, false); |
---|
80 | registerEventListener(lat_el, 'change', fieldlistener, false); |
---|
81 | registerEventListener(lng_el, 'change', fieldlistener, false); |
---|
82 | |
---|
83 | } |
---|
84 | else window.alert("Google maps aren't compatible with current Browser."); |
---|
85 | }; |
---|
86 | |
---|
87 | registerPloneFunction(editLocation); |
---|
88 | registerEventListener(window, 'unload', GUnload); |
---|