00001 <?
00010 abstract class BaseMap extends MyModule
00011 {
00015 function getPagesXml()
00016 {
00017 $xml = parent::getPagesXml();
00018
00019 $xml .= <<<XML
00020 <page name="lookup">
00021 <param name="location" required="true"/>
00022 </page>
00023 <page name="mapjs"/>
00024 XML;
00025 return $xml;
00026 }
00027
00034 function initMainPage()
00035 {
00036 $this->needsJs("http://maps.google.com/maps?file=api&v=2&key=" . Config::get('google_map_api_key'));
00037 $this->needsJs("lib/js/prototype-1.5.0.js");
00038 $this->needsJs("lib/js/gxmarker.js");
00039
00040 $this->needsJs($this->getUrl('.mapjs'));
00041
00042 $this->doCachePage = true;
00043 }
00044
00048 function drawMainPage()
00049 {
00050 $this->drawLookupForm();
00051 echo "<div id=\"mapDebug\"></div>\n";
00052 echo "<div id=\"map\"></div>\n";
00053 }
00054
00058 function drawLookupForm()
00059 {
00060 ?>
00061 <div id="mapLookup">
00062 <form id="mapLookup" onsubmit="mapDoLookup(); return false;">
00063 <b>Jump to location: (street/city/state/zip):</b>
00064 <input type="text" size="40" id="lookupAddress"/>
00065 <input type="button" onclick="mapDoLookup()" value="Jump"/>
00066 </form>
00067 </div>
00068 <?
00069 }
00070
00074 function initLookupPage()
00075 {
00076 $this->setTemplate(new BlankTemplate());
00077 }
00078
00082 function drawLookupPage()
00083 {
00084 $geo = new Geocode();
00085 $rs = $geo->search($this->params('location'));
00086
00087 echo JSON::encode($rs);
00088 }
00089
00094 function initMapJsPage()
00095 {
00096 $this->setTemplate(new BlankTemplate());
00097 header("Content-Type: application/x-javascript");
00098 }
00099
00107 function drawMapJsPage()
00108 {
00109 ?>
00110 function mapDoLookup()
00111 {
00112 var addy = $F('lookupAddress');
00113
00114 if (addy)
00115 {
00116 Form.disable('mapLookup');
00117
00118 var url = '<?=$this->getUrl('.lookup?location=');?>' + addy;
00119
00120 GDownloadUrl(url, function(data, response)
00121 {
00122 var result;
00123 eval('result = ' + data);
00124
00125 if (result)
00126 {
00127 var lon = result.lon;
00128 var lat = result.lat;
00129
00130 map.panTo(new GLatLng(lat, lon));
00131
00132 $('mapDebug').innerHTML = '';
00133 }
00134 else
00135 $('mapDebug').innerHTML = '<b>Location not found.</b>';
00136
00137 Form.enable('mapLookup');
00138 });
00139 }
00140 }
00141
00142 function mapDebug(txt)
00143 {
00144 $('mapDebug').innerHTML += txt + '<br/>';
00145 }
00146 <?
00147 }
00148 }
00149 ?>