Changeset 7082

Show
Ignore:
Timestamp:
11/26/08 01:26:00 (6 weeks ago)
Author:
daybreaker
Message:

refs #1131: merging 1.7 to trunk

Location:
trunk
Files:
4 modified

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  
    33 
    44var geocoder = null; 
    5 var locationMap = null; 
     5 
     6function GMap_normalizeAddress(address) { 
     7    //return address.split('/').slice(0,4).join(' '); 
     8    return address.split('/').join(' '); 
     9} 
    610 
    711/** 
     
    1822    if (!geocoder) 
    1923        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 
     28function 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++; 
    2259} 
    2360 
     
    3976 * @brief (내부용 함수) geocoder.getLocations()에 의해 호출되는 비동기 콜백 함수 
    4077 */ 
    41 function GMap_findLocationCallback(response, gmap, address, title, link, boundary, locations) { 
     78function GMap_findLocationCallback(response, gmap, location_info, title, link, boundary, locations) { 
    4279    if (!response || response.Status.code != 200) { 
    4380        // alert('Can\'t retrieve this address "'+address+'"'); 
     
    4582        var place = response.Placemark[0]; 
    4683        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); 
    7585    } 
    76     if (process_count != undefined) 
    77         process_count++; 
    7886} 
    7987 
  • trunk/plugins/GoogleMap/index.php

    r7067 r7082  
    1818        $api_key = $config['apiKey']; 
    1919        $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&amp;v=2&amp;key=$api_key\"></script>\n"; 
     20        $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&amp;v=2&amp;sensor=false&amp;key=$api_key\"></script>\n"; 
    2121        $target .= "<script type=\"text/javascript\" src=\"$pluginURL/gmap_common.js?".time()."\"></script>\n"; 
    2222        $target .= "<script type=\"text/javascript\"> 
     
    3636        $api_key = $config['apiKey']; // should exist here 
    3737        $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&amp;v=2&amp;key=$api_key\"></script>\n"; 
     38        $target .= "<script type=\"text/javascript\" src=\"http://maps.google.co.kr/maps?file=api&amp;v=2&amp;sensor=false&amp;key=$api_key\"></script>\n"; 
    3939        $target .= "<script type=\"text/javascript\"> 
    4040        //<![CDATA[ 
     
    8989 
    9090function GoogleMap_LocationLogView($target) { 
    91     global $blogid, $blog, $blogURL, $pluginURL, $configVal, $service; 
     91    global $blogid, $blog, $blogURL, $pluginURL, $configVal, $service, $database; 
    9292    requireComponent('Textcube.Function.Misc'); 
    9393    $config = Setting::fetchConfigVal($configVal); 
     
    107107    var process_count = 0; 
    108108    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() { 
    115112        var z = locationMap.getBoundsZoomLevel(boundary); 
    116113        if (z > 8) 
     
    121118        locationMap.setCenter(boundary.getCenter()); 
    122119    } 
     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    } 
    123127    STD.addLoadEventListener(function() { 
    124128        var c = document.getElementById('<?php echo $id;?>'); 
     
    128132            locationMap = new GMap2(c); 
    129133            locationMap.setMapType(<?php echo $default_type;?>); 
    130             locationMap.setCenter(new GLatLng(<?php echo $lat;?>, <?php echo $lng;?>), <?php echo $zoom;?>); 
    131134            locationMap.addControl(new GHierarchicalMapTypeControl()); 
    132135            locationMap.addControl(new GLargeMapControl()); 
    133136            locationMap.addControl(new GScaleControl()); 
    134137            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;?>)); 
    136140            var locations = new Array(); 
    137141<?php 
     
    139143    foreach ($locatives as $locative) { 
    140144        $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"; 
    142196        $count++; 
    143197    } 
    144198?> 
    145             window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 
     199            //window.setTimeout('locationFetchPoller(<?php echo $count;?>);', polling_interval); 
     200            adjustToBoundary(); 
    146201        } else { 
    147202            c.innerHTML = '<p style="text-align:center; color:#c99;">이 웹브라우저는 구글맵과 호환되지 않습니다.</p>'; 
     
    226281    <script type="text/javascript" src="<?php echo $pluginURL;?>/mootools-1.2.1-core-yc.js"></script> 
    227282    <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&amp;v=2&amp;key=<?php echo $api_key;?>"></script> 
     283    <script type="text/javascript" src="http://maps.google.co.kr/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo $api_key;?>"></script> 
    229284    <script type="text/javascript" src="<?php echo $pluginURL;?>/gmap_common.js?<?php echo time();?>"></script> 
    230285    <script type="text/javascript" src="<?php echo $pluginURL;?>/gmap_ui.js?<?php echo time();?>"></script> 
     
    255310<?php 
    256311} 
     312 
     313function _GMap_normalizeAddress($address) { 
     314    //return trim(implode(' ', array_slice(explode('/', $address), 0, 4))); 
     315    return trim(implode(' ', explode('/', $address))); 
     316} 
    257317/* vim: set noet ts=4 sts=4 sw=4: */ 
    258318?> 
  • trunk/plugins/GoogleMap/index.xml

    r6982 r7082  
    3636      </fieldset> 
    3737      <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> 
    4343      </fieldset> 
    4444    </config> 
     
    5656      </fieldset> 
    5757      <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> 
    6363      </fieldset> 
    6464    </config> 
    6565  </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> 
    6678</plugin> 
     79<!-- vim: set sts=2 sw=2 et: -->