Changeset 7082
- Timestamp:
- 11/26/08 01:26:00 (6 weeks ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
. (modified) (1 prop)
-
plugins/GoogleMap/gmap_common.js (modified) (4 diffs)
-
plugins/GoogleMap/index.php (modified) (9 diffs)
-
plugins/GoogleMap/index.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo set to /branches/1.7:7068-7070,7073,7079-7081
-
trunk/plugins/GoogleMap/gmap_common.js
r7067 r7082 3 3 4 4 var geocoder = null; 5 var locationMap = null; 5 6 function GMap_normalizeAddress(address) { 7 //return address.split('/').slice(0,4).join(' '); 8 return address.split('/').join(' '); 9 } 6 10 7 11 /** … … 18 22 if (!geocoder) 19 23 geocoder = new GClientGeocoder(); 20 var address = location_path.split('/').slice(0,4).join(' '); 21 geocoder.getLocations(address, function(response) {GMap_findLocationCallback(response, gmap, address, title, link, boundary, locations);}); 24 var address = GMap_normalizeAddress(location_path); 25 geocoder.getLocations(address, function(response) {GMap_findLocationCallback(response, gmap, {'address': address, 'path': location_path}, title, link, boundary, locations);}); 26 } 27 28 function GMap_addLocationMarkDirect(gmap, location_info, title, link, point, boundary, locations) { 29 var prev = null; 30 var i; 31 // Check duplicated locations 32 for (i = 0; i < locations.length; i++) { 33 if (locations[i].point.equals(point)) { 34 prev = locations[i]; 35 break; 36 } 37 } 38 if (prev == null) { 39 // Create a new marker for this location 40 var marker = new GMarker(point, {'title': location_info.address.split(' ').pop()}); 41 var locative = { 42 'point': point, 43 'marker': marker, 44 'address': location_info.address, 45 'entries': new Array({'title': title, 'link': link}) 46 }; 47 locations.push(locative); 48 marker.bindInfoWindowHtml(GMap_buildLocationInfoHTML(locative)); 49 gmap.addOverlay(marker); 50 boundary.extend(point); 51 } else { 52 // Add information to the existing marker for here 53 prev.entries.push({'title': title, 'link': link}); 54 prev.marker.bindInfoWindowHtml(null); 55 prev.marker.bindInfoWindowHtml(GMap_buildLocationInfoHTML(prev)); 56 } 57 if (process_count != undefined) 58 process_count++; 22 59 } 23 60 … … 39 76 * @brief (내부용 함수) geocoder.getLocations()에 의해 호출되는 비동기 콜백 함수 40 77 */ 41 function GMap_findLocationCallback(response, gmap, address, title, link, boundary, locations) {78 function GMap_findLocationCallback(response, gmap, location_info, title, link, boundary, locations) { 42 79 if (!response || response.Status.code != 200) { 43 80 // alert('Can\'t retrieve this address "'+address+'"'); … … 45 82 var place = response.Placemark[0]; 46 83 var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); 47 var prev = null; 48 var i; 49 // Check duplicated locations 50 for (i = 0; i < locations.length; i++) { 51 if (locations[i].point.equals(point)) { 52 prev = locations[i]; 53 break; 54 } 55 } 56 if (prev == null) { 57 // Create a new marker for this location 58 var marker = new GMarker(point, {'title': address.split(' ').pop()}); 59 var locative = { 60 'point': point, 61 'marker': marker, 62 'address': address, 63 'entries': new Array({'title': title, 'link': link}) 64 }; 65 locations.push(locative); 66 marker.bindInfoWindowHtml(GMap_buildLocationInfoHTML(locative)); 67 gmap.addOverlay(marker); 68 boundary.extend(point); 69 } else { 70 // Add information to the existing marker for here 71 prev.entries.push({'title': title, 'link': link}); 72 prev.marker.bindInfoWindowHtml(null); 73 prev.marker.bindInfoWindowHtml(GMap_buildLocationInfoHTML(prev)); 74 } 84 GMap_addLocationMarkDirect(gmap, location_info, title, link, point, boundary, locations); 75 85 } 76 if (process_count != undefined)77 process_count++;78 86 } 79 87 -
trunk/plugins/GoogleMap/index.php
r7067 r7082 18 18 $api_key = $config['apiKey']; 19 19 $target .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$pluginURL/common.css\" />\n"; 20 $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&v=2& key=$api_key\"></script>\n";20 $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&v=2&sensor=false&key=$api_key\"></script>\n"; 21 21 $target .= "<script type=\"text/javascript\" src=\"$pluginURL/gmap_common.js?".time()."\"></script>\n"; 22 22 $target .= "<script type=\"text/javascript\"> … … 36 36 $api_key = $config['apiKey']; // should exist here 37 37 $target .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$pluginURL/common.css\" />\n"; 38 $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&v=2& key=$api_key\"></script>\n";38 $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&v=2&sensor=false&key=$api_key\"></script>\n"; 39 39 $target .= "<script type=\"text/javascript\"> 40 40 //<![CDATA[ … … 89 89 90 90 function GoogleMap_LocationLogView($target) { 91 global $blogid, $blog, $blogURL, $pluginURL, $configVal, $service ;91 global $blogid, $blog, $blogURL, $pluginURL, $configVal, $service, $database; 92 92 requireComponent('Textcube.Function.Misc'); 93 93 $config = Setting::fetchConfigVal($configVal); … … 107 107 var process_count = 0; 108 108 var polling_interval = 60; // ms 109 var boundary; 110 function locationFetchPoller(target_count) { 111 if (process_count != target_count) { 112 window.setTimeout('locationFetchPoller('+target_count+');', polling_interval); 113 return; 114 } 109 var boundary = null; 110 var locationMap = null; 111 function adjustToBoundary() { 115 112 var z = locationMap.getBoundsZoomLevel(boundary); 116 113 if (z > 8) … … 121 118 locationMap.setCenter(boundary.getCenter()); 122 119 } 120 function locationFetchPoller(target_count) { 121 if (process_count != target_count) { 122 window.setTimeout('locationFetchPoller('+target_count+');', polling_interval); 123 return; 124 } 125 adjustToBoundary(); 126 } 123 127 STD.addLoadEventListener(function() { 124 128 var c = document.getElementById('<?php echo $id;?>'); … … 128 132 locationMap = new GMap2(c); 129 133 locationMap.setMapType(<?php echo $default_type;?>); 130 locationMap.setCenter(new GLatLng(<?php echo $lat;?>, <?php echo $lng;?>), <?php echo $zoom;?>);131 134 locationMap.addControl(new GHierarchicalMapTypeControl()); 132 135 locationMap.addControl(new GLargeMapControl()); 133 136 locationMap.addControl(new GScaleControl()); 134 137 locationMap.enableContinuousZoom(); 135 boundary = new GLatLngBounds(locationMap.getCenter(), locationMap.getCenter()); 138 locationMap.setCenter(new GLatLng(<?php echo $lat;?>, <?php echo $lng;?>), <?php echo $zoom;?>); 139 boundary = new GLatLngBounds(locationMap.getCenter()); //, new GLatLng(<?php echo $lat+0.1;?>, <?php echo $lng+0.1;?>)); 136 140 var locations = new Array(); 137 141 <?php … … 139 143 foreach ($locatives as $locative) { 140 144 $locative['link'] = "$blogURL/" . ($blog['useSloganOnPost'] ? 'entry/' . URL::encode($locative['slogan'],$service['useEncodedURL']) : $locative['id']); 141 echo "\t\t\tGMap_addLocationMark(locationMap, '{$locative['location']}', '".str_replace("'", "\\'", $locative['title'])."', encodeURI('".str_replace("'", "\\'", $locative['link'])."'), boundary, locations);\n"; 145 $row = POD::queryRow("SELECT * FROM {$database['prefix']}GMapLocations WHERE blogid = ".getBlogId()." AND address = '".POD::escapeString($locative['location'])."'"); 146 $found = false; 147 if ($row == null || empty($row)) { 148 //echo "\t\t\t/* New location query */\n"; 149 // Recursively repeat until location is found. (continuously reducing accuracy) 150 $addr = explode(' ', _GMap_normalizeAddress($locative['location'])); 151 while (true) { 152 $url = "http://maps.google.co.kr/maps/geo?q=".urlencode(trim(implode(' ', $addr)))."&output=csv&sensor=false&key={$config['apiKey']}"; 153 //echo "\t\t\t/* recurse : $addr */\n"; 154 $response = requestHttp('get', $url, false, 'text/plain'); 155 if ($response === false) { 156 $found = false; 157 break; 158 } else { 159 $response_lines = explode("\n", $response[1]); 160 $response_csv = explode(',', $response_lines[1]); 161 if ($response_csv[0] == '200') { 162 // Insert for later use. 163 //echo "\t\t\t/* read from api, {$locative['location']} */\n"; 164 $lat = $response_csv[2]; 165 $lng = $response_csv[3]; 166 POD::execute("INSERT INTO {$database['prefix']}GMapLocations VALUES (".getBlogId().", '".POD::escapeString($locative['location'])."', $lng, $lat, NOW())"); 167 $found = true; 168 break; 169 } else { 170 //echo "\t\t\t/* can't retrieve result for {$locative['location']} */\n"; 171 $lat = null; $lng = null; 172 $found = false; 173 if (count($addr) == 1) 174 break; 175 if (!$found) 176 array_pop($addr); 177 continue; 178 } 179 } 180 } 181 if (!$found) { 182 // Not found. 183 //echo "\t\t\t/* no result for {$locative['location']} */\n"; 184 POD::execute("INSERT INTO {$database['prefix']}GMapLocations VALUES (".getBlogId().", '".POD::escapeString($locative['location'])."', NULL, NULL, NOW())"); 185 } 186 } else { 187 //echo "\t\t\t/* read from db : {$locative['location']} */\n"; 188 $lat = $row['latitude']; 189 $lng = $row['longitude']; 190 $found = true; 191 } 192 if ($found && !is_null($lat)) { 193 echo "\t\t\tGMap_addLocationMarkDirect(locationMap, {address:GMap_normalizeAddress('{$locative['location']}'), path:'{$locative['location']}'}, '".str_replace("'", "\\'", $locative['title'])."', encodeURI('".str_replace("'", "\\'", $locative['link'])."'), new GLatLng($lat, $lng), boundary, locations);\n"; 194 } else 195 echo "\t\t\tif (process_count != undefined) process_count++;\n"; 142 196 $count++; 143 197 } 144 198 ?> 145 window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 199 //window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 200 adjustToBoundary(); 146 201 } else { 147 202 c.innerHTML = '<p style="text-align:center; color:#c99;">이 웹브라우저는 구글맵과 호환되지 않습니다.</p>'; … … 226 281 <script type="text/javascript" src="<?php echo $pluginURL;?>/mootools-1.2.1-core-yc.js"></script> 227 282 <script type="text/javascript" src="<?php echo $pluginURL;?>/mootools-1.2-more.js"></script> 228 <script type="text/javascript" src="http://maps.google.co.kr/maps?file=api&v=2& key=<?php echo $api_key;?>"></script>283 <script type="text/javascript" src="http://maps.google.co.kr/maps?file=api&v=2&sensor=false&key=<?php echo $api_key;?>"></script> 229 284 <script type="text/javascript" src="<?php echo $pluginURL;?>/gmap_common.js?<?php echo time();?>"></script> 230 285 <script type="text/javascript" src="<?php echo $pluginURL;?>/gmap_ui.js?<?php echo time();?>"></script> … … 255 310 <?php 256 311 } 312 313 function _GMap_normalizeAddress($address) { 314 //return trim(implode(' ', array_slice(explode('/', $address), 0, 4))); 315 return trim(implode(' ', explode('/', $address))); 316 } 257 317 /* vim: set noet ts=4 sts=4 sw=4: */ 258 318 ?> -
trunk/plugins/GoogleMap/index.xml
r6982 r7082 36 36 </fieldset> 37 37 <fieldset legend="지역로그 설정"> 38 <field title="기본 맵 형식" name="locative_maptype" type="select">39 <op value="G_NORMAL_MAP">일반 정보 지도</op>40 <op value="G_SATELLITE_MAP">위성 사진</op>41 <op value="G_HYBRID_MAP" selected="selected">위성 사진 + 정보 지도</op>42 </field>38 <field title="기본 맵 형식" name="locative_maptype" type="select"> 39 <op value="G_NORMAL_MAP">일반 정보 지도</op> 40 <op value="G_SATELLITE_MAP">위성 사진</op> 41 <op value="G_HYBRID_MAP" selected="selected">위성 사진 + 정보 지도</op> 42 </field> 43 43 </fieldset> 44 44 </config> … … 56 56 </fieldset> 57 57 <fieldset legend="Location Log"> 58 <field title="Default Map Type" name="locative_maptype" type="select">59 <op value="G_NORMAL_MAP" checked="checked">Normal</op>60 <op value="G_SATELLITE_MAP">Satellite</op>61 <op value="G_HYBRID_MAP">Hybrid (Normal+Satellite)</op>62 </field>58 <field title="Default Map Type" name="locative_maptype" type="select"> 59 <op value="G_NORMAL_MAP" checked="checked">Normal</op> 60 <op value="G_SATELLITE_MAP">Satellite</op> 61 <op value="G_HYBRID_MAP">Hybrid (Normal+Satellite)</op> 62 </field> 63 63 </fieldset> 64 64 </config> 65 65 </binding> 66 <storage> 67 <table> 68 <name>GMapLocations</name> 69 <fields> 70 <field><name>address</name><attribute>varchar</attribute><length>300</length><isnull>0</isnull><default></default></field> 71 <field><name>longitude</name><attribute>double</attribute><isnull>1</isnull></field> 72 <field><name>latitude</name><attribute>double</attribute><isnull>1</isnull></field> 73 <field><name>updated</name><attribute>timestamp</attribute><isnull>0</isnull><default>0</default></field> 74 </fields> 75 <key>address</key> 76 </table> 77 </storage> 66 78 </plugin> 79 <!-- vim: set sts=2 sw=2 et: -->
