Changeset 12719 for extensions


Ignore:
Timestamp:
Dec 11, 2011, 8:55:04 PM (12 years ago)
Author:
rvelices
Message:

rv_gmaps can show now different markers based on number of photos at the location

Location:
extensions/rv_gmaps/trunk
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_gmaps/trunk/admin/admin_config.tpl

    r12700 r12719  
    4747  <li>
    4848  <label>
    49     Marker image:
     49    Marker style:
    5050    <select name="marker_icon">
    5151      <option value="">Default</option>
  • extensions/rv_gmaps/trunk/changelog.txt

    r12706 r12719  
    33- fix some bad markers not showing (google removed some images from their servers)
    44- added some new marker icons
     5- markers can have different shape depending on the number of pictures
    56- full migration to maps api v3
    67
  • extensions/rv_gmaps/trunk/include/cluster_maker.php

    r3447 r12719  
    33function cluster_area_compare( &$a, &$b )
    44{
    5         $aa = bounds_lat_range($a['bounds']) * bounds_lon_range($a['bounds']);
    6         $ab = bounds_lat_range($b['bounds']) * bounds_lon_range($b['bounds']);
     5        $aa = bounds_lat_range($a->bounds) * bounds_lon_range($a->bounds);
     6        $ab = bounds_lat_range($b->bounds) * bounds_lon_range($b->bounds);
    77        return -$aa+$ab; // biggest first
     8}
     9
     10final class Cluster
     11{
     12        public $bounds;
     13        public $items;
     14
     15        function __construct($b = array(), $i = array())
     16        {
     17                $this->bounds = $b;
     18                $this->items = $i;
     19        }
    820}
    921
     
    3042                        $this->bounds = bounds_add($this->bounds, $img['lat'], $img['lon'] );
    3143
    32                 $pending_split = array(
    33                                 array(
    34                                         'bounds' => $this->bounds,
    35                                         'items' => array_keys( $this->_image_map ),
    36                                 )
    37                         );
     44                $pending_split = array( new Cluster($this->bounds, array_keys($this->_image_map) ) );
    3845                $result = array();
    3946
     
    5158                                        foreach( $splitted as $k => $split )
    5259                                                echo("sub $k: " . var_export($split['bounds'],true)."\n" );*/
    53                                         $total_iterations += count($current['items']);
     60                                        $total_iterations += count($current->items);
    5461                                        $next_level_to_split = array_merge($next_level_to_split, $splitted );
    5562                                        if ( count($result)+count($pending_split)+count($next_level_to_split) >= $maxNbMarkers )
     
    6673                        usort( $pending_split, 'cluster_area_compare' );
    6774                }
     75
    6876                $merged = $this->_try_merge_clusters( $result, $maxLatPrecision, $maxLonPrecision );
    6977                $this->debug_str = get_elapsed_time($start, get_moment()) .' gen:'.$total_generations.' alg:'.count($this->_image_map).'+'.$total_iterations;
     
    7987                for ($i=0; $i<count($clusters)-1; $i++)
    8088                {
    81                         $ci = bounds_center( $clusters[$i]['bounds'] );
     89                        $ci = bounds_center( $clusters[$i]->bounds );
    8290                        for ($j=$i+1; $j<count($clusters); $j++)
    8391                        {
    84                                 $cj = bounds_center( $clusters[$j]['bounds'] );
    85                                 if ( abs($ci['lat']-$cj['lat']) < $maxLatPrecision/2
    86                                         and abs($ci['lon']-$cj['lon']) < $maxLonPrecision/2 )
     92                                $cj = bounds_center( $clusters[$j]->bounds );
     93                                $rlat = abs($ci['lat']-$cj['lat']) / $maxLatPrecision;
     94                                $rlon = abs($ci['lon']-$cj['lon']) / $maxLonPrecision;
     95                                if ( $rlat<1 && $rlon<1
     96                                                && $rlat+$rlon<1.1)
    8797                                {
    8898                                        //print_r( "i=$i; j=$j \n"); var_export( $clusters[$i]['bounds'] ); var_export( $clusters[$j]['bounds'] );
    89                                         $clusters[$i]['items'] = array_merge( $clusters[$i]['items'], $clusters[$j]['items'] );
     99                                        $clusters[$i]->items = array_merge( $clusters[$i]->items, $clusters[$j]->items );
    90100                                        if ( empty($this->_image_ranks) )
    91101                                                $this->_image_ranks = array_flip( array_keys($this->_image_map) );
    92                                         usort( $clusters[$i]['items'], array($this, '_image_rank_compare') );
    93                                         $clusters[$i]['bounds'] = bounds_union($clusters[$i]['bounds'], $clusters[$j]['bounds'] );
     102                                        usort( $clusters[$i]->items, array($this, '_image_rank_compare') );
     103                                        $clusters[$i]->bounds = bounds_union($clusters[$i]->bounds, $clusters[$j]->bounds );
    94104                                        array_splice( $clusters, $j, 1);
    95105                                        $j--;
    96                                         $ci = bounds_center( $clusters[$i]['bounds'] );
     106                                        $ci = bounds_center( $clusters[$i]->bounds );
    97107                                        $ret++;
    98108                                }
     
    109119        function _split_cluster($cluster, $maxLatPrecision, $maxLonPrecision)
    110120        {
    111                 $latRange = bounds_lat_range($cluster['bounds']);
    112                 $lonRange = bounds_lon_range($cluster['bounds']);
     121                $latRange = bounds_lat_range($cluster->bounds);
     122                $lonRange = bounds_lon_range($cluster->bounds);
    113123
    114124                $lat_nb_tiles = max( 1, $latRange/$maxLatPrecision );
     
    146156                }
    147157
    148                 if ( $cluster['bounds']['count'] > 200 )
     158                if ( $cluster->bounds['count'] > 200 )
    149159                {
    150160                        if ($lat_step>4*$maxLatPrecision) $lat_step = $lat_step/2;
     
    159169
    160170                $clusters = array();
    161                 foreach ( $cluster['items'] as $id )
     171                foreach ( $cluster->items as $id )
    162172                {
    163173                        $lon = $this->_image_map[$id]['lon'];
    164174                        $lat = $this->_image_map[$id]['lat'];
    165175
    166                         $idx_lon = floor ( ( $lon - $cluster['bounds']['w'] ) / $lon_step );
    167                         $idx_lat = floor ( ( $lat - $cluster['bounds']['s'] ) / $lat_step );
     176                        $idx_lon = floor ( ( $lon - $cluster->bounds['w'] ) / $lon_step );
     177                        $idx_lat = floor ( ( $lat - $cluster->bounds['s'] ) / $lat_step );
    168178
    169179                        $idx = $lon_nb_tiles * $idx_lat + $idx_lon;
     
    171181                        if ( !isset($clusters[$idx]) )
    172182                        {
    173                                 $clusters[$idx] = array(
    174                                         'bounds'  => array(),
    175                                         'items'   => array(),
    176                                         );
     183                                $clusters[$idx] = new Cluster();
    177184                        }
    178                         array_push( $clusters[$idx]['items'], $id );
    179                         $clusters[$idx]['bounds'] = bounds_add( $clusters[$idx]['bounds'] , $lat, $lon );
     185                        array_push( $clusters[$idx]->items, $id );
     186                        $clusters[$idx]->bounds = bounds_add( $clusters[$idx]->bounds , $lat, $lon );
    180187                }
    181188                return $clusters;
  • extensions/rv_gmaps/trunk/map.php

    r12698 r12719  
    8484}
    8585else
    86   $template->assign('MAP_MARKER_ICON_JS', 'return {}');
     86  $template->assign('MAP_MARKER_ICON_JS', 'new PwgSingleStyler()');
    8787
    8888$template->pparse('map');
  • extensions/rv_gmaps/trunk/map_data.php

    r12706 r12719  
    122122  if ($i) rvo( ",\n\n" );
    123123  rvo( "{" );
    124   rvo( 'position: '. jsgm_position( bounds_center($c['bounds']) ) );
     124  rvo( 'position: '. jsgm_position( bounds_center($c->bounds) ) );
    125125  rvo( ",\n" );
    126   rvo( 'bounds: '. jsgm_bounds( $c['bounds'] ) );
     126  rvo( 'bounds: '. jsgm_bounds( $c->bounds ) );
    127127  rvo( ",\n" );
    128   rvo( 'nb_items: '.count($c['items']) );
     128  rvo( 'nb_items: '.count($c->items) );
    129129  rvo( ",\n" );
    130130
    131   rvo( 'blowup_url: "'.rvm_duplicate_blowup_url(array('box'=>$c['bounds']), array('start') ). '"' );
     131  rvo( 'blowup_url: "'.rvm_duplicate_blowup_url(array('box'=>$c->bounds), array('start') ). '"' );
    132132  rvo( ",\n" );
    133133
    134134  $max_per_cluster = rvm_get_config_var('nb_images_per_marker',20);
    135   if ( count($c['items']) >  $max_per_cluster )
     135  if ( count($c->items) >  $max_per_cluster )
    136136  {
    137     $c['items'] = array_slice($c['items'], 0, $max_per_cluster);
     137    $c->items = array_slice($c->items, 0, $max_per_cluster);
    138138  }
    139139  rvo( 'items: [' );
    140   for ($j=0; $j<count($c['items']); $j++)
     140  for ($j=0; $j<count($c->items); $j++)
    141141  {
    142     $img = $page['items'] [ $c['items'][$j] ];
     142    $img = $page['items'] [ $c->items[$j] ];
    143143    $img['file'] = basename( $img['path'] );
    144144    if (!empty( $img['name'] ) )
  • extensions/rv_gmaps/trunk/template/data_handler.js

    r12706 r12719  
    44        this._map = map;
    55        this._infoWindow = new google.maps.InfoWindow();
     6        this.styler = opts.styler;
    67        this.options = jQuery.fn.extend(
    78                {
    8                         markerOptions: {},
    99                        show_all_img_src: null
    1010                }
     
    6868        if (changed)
    6969        {
    70 // BEGIN NEW ****************   
    71                 var markersToRemove=[], clustersToAdd=[], newMarkers=[];
     70                var markersToRemove=[], clustersToAdd=[], newMarkers=[], cluster, marker;
    7271                data.image_clusters.sort( function(a,b) { return PwgDataHandler.cmpll( a.position, b.position); } );
    7372                for (i=0; i<data.image_clusters.length; i++)
    7473                {
    75                         var cluster = data.image_clusters[i];
     74                        cluster = data.image_clusters[i];
    7675                        while(this._markers.length)
    7776                        {
    78                                 var marker = this._markers[0];
     77                                marker = this._markers[0];
    7978                                if (PwgDataHandler.cmpll(cluster.position, marker.getPosition()) == 0)
    8079                                {
     80                                        marker.setOptions(this.styler.changeStyle(cluster, marker.pwg));
    8181                                        marker.pwg = {
    8282                                                nb_items: cluster.nb_items,
     
    111111                for (i=0; i<clustersToAdd.length; i++)
    112112                {
    113                         var cluster = clustersToAdd[i];
    114                         var theTitle = "";
    115                         if (cluster.nb_items>1)
    116                                 theTitle = Localization.fmt1("%d photos", cluster.nb_items);
    117                         else
    118                                 theTitle = cluster.items[0].name;
    119 
    120                         var marker = markersToRemove.pop();
     113                        cluster = clustersToAdd[i];
     114                       
     115                        var theTitle = (cluster.nb_items>1) ? Localization.fmt1("%d photos", cluster.nb_items) : cluster.items[0].name;
     116                        marker = markersToRemove.pop();
    121117                        if (marker && marker==infoWindowMarker)
    122118                        {
     
    129125                        if (!marker)
    130126                        {
    131                                 marker = new google.maps.Marker(this.options.markerOptions);
     127                                marker = new google.maps.Marker(this.styler.getStyle(cluster));
    132128                                marker.setPosition(cluster.position);
    133129                                marker.setTitle(theTitle);
     
    141137                                marker.setPosition( cluster.position );
    142138                                marker.setTitle(theTitle);
     139                                marker.setOptions(this.styler.changeStyle(cluster, marker.pwg));
    143140                        }
    144141
     
    161158                this._markers = newMarkers;
    162159                this._markers.sort( function(a,b) { return PwgDataHandler.cmpll( a.getPosition(), b.getPosition()); } );
    163 // END new
    164                
    165 /*              var newMarkers = [];
    166                 var infoWindowMarker = this._infoWindow.getAnchor();
    167 
    168                 for (i=0; i<data.image_clusters.length; i++)
    169                 {
    170                         var cluster = data.image_clusters[i];
    171                         var theTitle = "";
    172                         if (cluster.nb_items>1)
    173                                 theTitle = Localization.fmt1("%d photos", cluster.nb_items);
    174                         else
    175                                 theTitle = cluster.items[0].name;
    176 
    177                         var marker;
    178                         marker = this._markers.pop();
    179                         if (marker && marker==infoWindowMarker)
    180                         {
    181                                 marker.setMap(null);
    182                                 google.maps.event.clearInstanceListeners(marker);
    183                                 if (document.is_debug) glog('removed marker with infoWindow');
    184                                 marker = this._markers.pop();
    185                         }
    186 
    187                         if (!marker)
    188                         {
    189                                 marker = new google.maps.Marker(this.options.markerOptions);
    190                                 marker.setPosition(cluster.position);
    191                                 marker.setTitle(theTitle);
    192                                 google.maps.event.addListener( marker, "click", pwgBind(this, this._onMarkerClick, marker) );
    193                                 google.maps.event.addListener( marker, "dblclick", pwgBind(this, this._onMarkerDblClick, marker) );
    194                         }
    195                         else
    196                         {
    197                                 marker.currentImageIndex=0;
    198                                 marker.setPosition( cluster.position );
    199                                 marker.setTitle(theTitle);
    200                         }
    201                         marker.setMap(this._map);
    202 
    203                         newMarkers.push(marker);
    204 
    205                         marker.pwg = {
    206                                 nb_items: cluster.nb_items,
    207                                 images: cluster.items,
    208                                 bounds: cluster.bounds,
    209                                 blowup_url: cluster.blowup_url
    210                                 };
    211                 }
    212 
    213                 for (i=0; i<this._markers.length; i++)
    214                 {
    215                         this._markers[i].setMap(null);
    216                         google.maps.event.clearInstanceListeners(this._markers[i]);
    217                 }
    218 */
    219                 this._markers = newMarkers;
    220160                this._prevResult.nb_items=data.nb_items;
    221161        }
  • extensions/rv_gmaps/trunk/template/data_loader.js

    r12706 r12719  
    3737{
    3838        this._urlMapData = urlMapData;
    39         google.maps.event.bind( this._map, "movestart", this, this.clearTimerReloadData );
     39        google.maps.event.bind( this._map, "dragstart", this, this.clearTimerReloadData );
    4040        google.maps.event.bind( this._map, "idle", this, this._onIdle );
    4141        //this._loadData();
     
    102102       
    103103        if (isOver)
    104                 bounds = new google.maps.LatLngBounds( new google.maps.LatLng(this._map.getBounds().getSouthWest().lat(),-179.9), new google.maps.LatLng(this._map.getBounds().getNorthEast().lat(), 179.9) );
     104                bounds = new google.maps.LatLngBounds( new google.maps.LatLng(this._map.getBounds().getSouthWest().lat(),-180), new google.maps.LatLng(this._map.getBounds().getNorthEast().lat(), 179.99) );
    105105        //END bug
    106106       
     
    184184        catch (e)       {
    185185                this._previousLoadDataReq.box=null;
    186                 google.maps.event.trigger( this, "dataloadfailed", responseCode, e );
     186                google.maps.event.trigger( this, "dataloadfailed", textStatus, e );
    187187                var s = e.message;
    188188                s += '\n' + data.substr(0,1000);
  • extensions/rv_gmaps/trunk/template/map.tpl

    r12706 r12719  
    1717{combine_script id='rvm.dh' load='header' path="`$PLUGIN_LOCATION`/template/data_handler.js" version=$RVM_PLUGIN_VERSION}
    1818{combine_script id='rvm.pl' load='header' path="`$PLUGIN_LOCATION`/template/page_linker.js" version=$RVM_PLUGIN_VERSION}
     19{combine_script id='rvm.st' load='header' path="`$PLUGIN_LOCATION`/template/styler.js" version=$RVM_PLUGIN_VERSION}
    1920{combine_script id='core.scripts' load='header' path='themes/default/js/scripts.js'}
    2021
     
    4041//<![CDATA[
    4142var map;
    42 var geocoder;
    4343
    4444document.is_debug = false;
    4545if ( document.location.search.match(/[\?&]debug/) ) {
    4646        document.is_debug = true;
    47         document._window = window;
    4847}
    4948
     
    9796        pwgPageLinker = new PageLinker(map, "aLinkToThisPage" );
    9897
    99         var pwgMarkerOptions = (function(){ {/literal}{$MAP_MARKER_ICON_JS}{literal} }).call(null);
    100 
    101         map.pwgDataLoader = new PwgDataLoader(map, {rectangle_of_confusion: pwgMarkerOptions.roc} );
     98        /*var pwgMarkerOptions = (function(){ {/literal}{$MAP_MARKER_ICON_JS}{literal} }).call(null);*/
     99        var pwgStyler = {/literal}{$MAP_MARKER_ICON_JS}{literal};
     100
     101        map.pwgDataLoader = new PwgDataLoader(map, {rectangle_of_confusion: pwgStyler.roc} );
    102102        google.maps.event.addListener(map.pwgDataLoader, "dataloading", function() {
    103103                var pre = '<img src="{/literal}{$PLUGIN_ROOT_URL}{literal}/icons/progress_s.gif" width="16" height="16" alt="~" /> ';
     
    111111                );
    112112
    113         map.pwgDataHandler = new PwgDataHandler(map, {markerOptions: pwgMarkerOptions, show_all_img_src: "{/literal}{$PLUGIN_ROOT_URL}{literal}/icons/pic_s.gif" } );
     113        map.pwgDataHandler = new PwgDataHandler(map, {styler: pwgStyler, show_all_img_src: "{/literal}{$PLUGIN_ROOT_URL}{literal}/icons/pic_s.gif" } );
    114114        google.maps.event.addListener(map.pwgDataLoader, "dataloaded", pwgBind(map.pwgDataHandler, map.pwgDataHandler.handle) );
    115115
     
    136136                !map.pwgDataHandler || map.pwgDataHandler.terminate();
    137137        }
    138 }
    139 
    140 function searchLocation(q)
    141 {
    142         if (!q.length) return false;
    143         if (!geocoder)
    144                 geocoder = new google.maps.Geocoder();
    145         geocoder.geocode(q, function(results, status) {
    146                 document._geoResponse = results;
    147                 if ( status == google.maps.GeocoderStatus.OK )
    148                 {
    149                         map.fitBounds( results[0].geometry.viewport );
    150                 }
    151           else
    152                         alert("This address has not been found\nCode: "+status);
    153         });
    154         return false;
    155138}
    156139
  • extensions/rv_gmaps/trunk/template/markers/medium_gradient_blue.tpl

    r12706 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(12, 20),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/medium_gradient_blue.png",
    43                        new google.maps.Size(12, 20), //size
     
    65                        new google.maps.Point(6, 20) //anchor
    76                        )
    8 }
     7                        },
     8                        new google.maps.Size(12, 20) )
     9
  • extensions/rv_gmaps/trunk/template/markers/medium_gradient_purple.tpl

    r12706 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(12, 20),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/medium_gradient_purple.png",
    43                        new google.maps.Size(12, 20), //size
     
    65                        new google.maps.Point(6, 20) //anchor
    76                        )
    8 }
     7                        },
     8                        new google.maps.Size(12, 20) )
     9
  • extensions/rv_gmaps/trunk/template/markers/medium_gradient_red.tpl

    r12706 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(12, 20),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/medium_gradient_red.png",
    43                        new google.maps.Size(12, 20), //size
     
    65                        new google.maps.Point(6, 20) //anchor
    76                        )
    8 }
     7                        },
     8                        new google.maps.Size(12, 20) )
     9
  • extensions/rv_gmaps/trunk/template/markers/medium_standard_red.tpl

    r12706 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(12, 20),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/medium_standard_red.png",
    43                        new google.maps.Size(12, 20), //size
    54                        new google.maps.Point(0, 0), //origin
    65                        new google.maps.Point(6, 20) //anchor
    7                         )/*,
    8         shadow: "{$PLUGIN_ROOT_URL}/template/markers/medium_standard_shadow.png"*/
    9 }
     6                        )
     7                        },
     8                        new google.maps.Size(12, 20) )
  • extensions/rv_gmaps/trunk/template/markers/small_bullet_orange.tpl

    r12700 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(11, 11),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/small_bullet_orange.png",
    4                         new google.maps.Size(11, 11),
    5                         new google.maps.Point(0, 0),
    6                         new google.maps.Point(5, 0))
    7 }
     3                        new google.maps.Size(11, 11), //size
     4                        new google.maps.Point(0, 0), //origin
     5                        new google.maps.Point(5, 0) //anchor
     6                        )
     7                        },
     8                        new google.maps.Size(11, 11) )
  • extensions/rv_gmaps/trunk/template/markers/small_bullet_red.tpl

    r12700 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(11, 11),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/small_bullet_red.png",
    4                         new google.maps.Size(11, 11),
    5                         new google.maps.Point(0, 0),
    6                         new google.maps.Point(5, 5))
    7 }
     3                        new google.maps.Size(11, 11), //size
     4                        new google.maps.Point(0, 0), //origin
     5                        new google.maps.Point(5, 0) //anchor
     6                        )
     7                        },
     8                        new google.maps.Size(11, 11) )
  • extensions/rv_gmaps/trunk/template/markers/small_bullet_yellow.tpl

    r12700 r12719  
    1 return {ldelim}
    2         rectangle_of_precision: new google.maps.Size(11, 11),
     1new PwgSingleStyler( {ldelim}
    32        icon: new google.maps.MarkerImage("{$PLUGIN_ROOT_URL}/template/markers/small_bullet_yellow.png",
    4                         new google.maps.Size(11, 11),
    5                         new google.maps.Point(0, 0),
    6                         new google.maps.Point(5, 5))
    7 }
     3                        new google.maps.Size(11, 11), //size
     4                        new google.maps.Point(0, 0), //origin
     5                        new google.maps.Point(5, 0) //anchor
     6                        )
     7                        },
     8                        new google.maps.Size(11, 11) )
  • extensions/rv_gmaps/trunk/template/picture_map_content.tpl

    r12706 r12719  
    11
    22{html_head}
    3 <script src="http://maps.google<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;language={$lang_info.code}" type="text/javascript"></script>
     3<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;language={$lang_info.code}" type="text/javascript"></script>
    44{combine_script id='jquery' load='header' path='themes/default/js/jquery.min.js'}
    55{combine_script id='jquery.nyroModal' load='async' path="`$PLUGIN_LOCATION`/template/nyroModal/jquery.nyroModal-1.6.2.js" version='1.6.2'}
Note: See TracChangeset for help on using the changeset viewer.