Ignore:
Timestamp:
Mar 1, 2010, 10:29:55 PM (14 years ago)
Author:
rvelices
Message:
 
Location:
extensions/rv_gmaps/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_gmaps/trunk/changelog.txt

    r4070 r5018  
     12.0.d
     2  - hungarian translation thanks to external contributors
     3  - the map uses now the 3D Large map control as on google maps website
     4  - dirty fix for bug inroduced in api version 2.185 (and up to 2.193 as of now online) - http://code.google.com/p/gmaps-api-issues/issues/detail?id=2009&q=apitype%3AJavascript&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars
     5
    162.0.c
    27  - google maps api is loaded using the same language as piwigo
  • extensions/rv_gmaps/trunk/main.inc.php

    r4070 r5018  
    11<?php /*
    22Plugin Name: RV Maps&Earth
    3 Version: 2.0.c
     3Version: 2.0.d
    44Description: Extend your gallery with Google Maps and Google Earth ...
    55Plugin URI: http://piwigo.org/ext/extension_view.php?eid=122
     
    77Author URI: http://www.modusoptimus.com/
    88*/
    9 define( 'RVM_PLUGIN_VERSION', '2.0.c');
     9define( 'RVM_PLUGIN_VERSION', '2.0.d');
    1010if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1111
  • extensions/rv_gmaps/trunk/template/data_loader.js

    r3447 r5018  
    11function PwgDataLoader( map, opts )
    22{
    3   this._map = map;
    4   this.options = Object.extend(
    5     {
    6       reload_data_timeout: 1800,
    7       rectangle_of_confusion: G_DEFAULT_ICON.iconSize
    8     }
    9     , opts || {} );
    10   this.options.rectangle_of_confusion = new GSize( this.options.rectangle_of_confusion.width, this.options.rectangle_of_confusion.height );
    11   if (this.options.rectangle_of_confusion.width<16) this.options.rectangle_of_confusion.width=16;
    12   if (this.options.rectangle_of_confusion.height<16) this.options.rectangle_of_confusion.height=16;
     3        this._map = map;
     4        this.options = Object.extend(
     5                {
     6                        reload_data_timeout: 1800,
     7                        rectangle_of_confusion: G_DEFAULT_ICON.iconSize
     8                }
     9                , opts || {} );
     10        this.options.rectangle_of_confusion = new GSize( this.options.rectangle_of_confusion.width, this.options.rectangle_of_confusion.height );
     11        if (this.options.rectangle_of_confusion.width<16) this.options.rectangle_of_confusion.width=16;
     12        if (this.options.rectangle_of_confusion.height<16) this.options.rectangle_of_confusion.height=16;
    1313}
    1414
     
    1717getLatLonDigits = function(d, factor, exp)
    1818{
    19   if (d<0) return getLatLonDigits(-d,factor,exp);
    20   var digits = Math.ceil( exp - Math.log(d*factor)/Math.LN10 );
    21   return digits<0 ? 0 : (digits>6 ? 6 : digits);
     19        if (d<0) return getLatLonDigits(-d,factor,exp);
     20        var digits = Math.ceil( exp - Math.log(d*factor)/Math.LN10 );
     21        return digits<0 ? 0 : (digits>6 ? 6 : digits);
    2222}
    2323
     
    3636start: function(urlMapData)
    3737{
    38   this._urlMapData = urlMapData;
    39   GEvent.bind( this._map, "movestart", this, this.clearTimerReloadData );
    40   GEvent.bind( this._map, "moveend", this, this._onMapMoveEnd );
    41   this._loadData();
     38        this._urlMapData = urlMapData;
     39        GEvent.bind( this._map, "movestart", this, this.clearTimerReloadData );
     40        GEvent.bind( this._map, "moveend", this, this._onMapMoveEnd );
     41        this._loadData();
    4242},
    4343
    4444terminate: function()
    4545{
    46   this.clearTimerReloadData();
    47   this._map = null;
     46        this.clearTimerReloadData();
     47        this._map = null;
    4848},
    4949
    5050clearTimerReloadData : function()
    5151{
    52   if (this._timerReloadData)
    53   {
    54     clearTimeout( this._timerReloadData );
    55     this._timerReloadData = null;
    56     return true;
    57   }
    58   return false;
     52        if (this._timerReloadData)
     53        {
     54                clearTimeout( this._timerReloadData );
     55                this._timerReloadData = null;
     56                return true;
     57        }
     58        return false;
    5959},
    6060
    6161_onMapMoveEnd: function()
    6262{
    63   this.clearTimerReloadData();
    64   this._timerReloadData = setTimeout(
    65     this._onTimeoutLoadData.bind(this),
    66     this.options.reload_data_timeout);
     63        this.clearTimerReloadData();
     64        this._timerReloadData = setTimeout(  this._onTimeoutLoadData.bind(this), this.options.reload_data_timeout );
    6765},
    6866
     
    7068_onTimeoutLoadData: function ()
    7169{
    72   if (this._dataLoading) return; // still in progress
    73   this.clearTimerReloadData();
    74   this._loadData();
     70        if (this._dataLoading) return; // still in progress
     71        this.clearTimerReloadData();
     72        this._loadData();
    7573},
    7674
    7775_loadData: function()
    7876{
    79   var bounds = this._map.getBounds();
     77        var bounds = this._map.getBounds();
    8078
    81   var latRange = bounds.toSpan().lat();
    82   var latPrec = latRange * this.options.rectangle_of_confusion.height / this._map.getSize().height;
     79        // BEGIN BUG in maps api 2.185 up to "today" 2.193 - when map wraps horizontally more than 360 deg - the getBounds is wrong
     80        if ( this._map.getZoom() <= 2 )
     81        {
     82                bounds = new GLatLngBounds(
     83                                new GLatLng( bounds.getSouthWest().lat(),  -180 ),
     84                                new GLatLng( bounds.getNorthEast().lat(),  180 )
     85                        );
     86        }
     87        // END BUG
     88        var latRange = bounds.toSpan().lat();
     89        var latPrec = latRange * this.options.rectangle_of_confusion.height / this._map.getSize().height;
    8390
    84   var lonRange = bounds.toSpan().lng();
    85   var lonPrec = ( lonRange>=0 ? lonRange : 360-lonRange )* this.options.rectangle_of_confusion.width / this._map.getSize().width;
     91        var lonRange = bounds.toSpan().lng();
     92        var lonPrec = ( lonRange>=0 ? lonRange : 360-lonRange )* this.options.rectangle_of_confusion.width / this._map.getSize().width;
    8693
    87   if ( this._previousLoadDataReq.box!=null )
    88   { // not the first time
    89     if ( this._previousLoadDataReq.box.containsBounds( bounds ) )
    90     {
    91       if ( this._previousLoadDataReq.resultBounds == null )
    92         return; // no images here
    93       if ( this._map.getZoom() <= this._previousLoadDataReq.zoom )
    94         return;
    95       else
    96       {
    97         if (
    98           this._map.getZoom() == this._previousLoadDataReq.zoom + 1
    99           && this._map.getZoom() < this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds)
    100           )
    101         {
    102           if (document.is_debug) GLog.write('no load: zoom crt: '+this._map.getZoom()+'; prev: '+this._previousLoadDataReq.zoom+'; target: '+this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds));
    103           return;
    104         }
    105       }
    106     }
    107     else
    108     {
    109     }
    110   }
     94        if ( this._previousLoadDataReq.box!=null )
     95        { // not the first time
     96                if ( this._previousLoadDataReq.box.containsBounds( bounds ) )
     97                {
     98                        if ( this._previousLoadDataReq.resultBounds == null )
     99                                return; // no images here
     100                        if ( this._map.getZoom() <= this._previousLoadDataReq.zoom )
     101                                return;
     102                        else
     103                        {
     104                                if (
     105                                        this._map.getZoom() == this._previousLoadDataReq.zoom + 1
     106                                        && this._map.getZoom() < this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds)
     107                                        )
     108                                {
     109                                        if (document.is_debug) GLog.write('no load: zoom crt: '+this._map.getZoom()+'; prev: '+this._previousLoadDataReq.zoom+'; target: '+this._map.getBoundsZoomLevel(this._previousLoadDataReq.resultBounds));
     110                                        return;
     111                                }
     112                        }
     113                }
     114                else
     115                {
     116                }
     117        }
    111118
    112   var nd=0, sd=0, ed=0, wd=0;
    113   if ( !bounds.isFullLat() )
    114   {
    115     nd = latRange*12/100;
    116     sd = latRange*4/100;
    117   }
    118   if ( !bounds.isFullLng() )
    119   {
    120     ed = lonRange*9/100;
    121     wd = lonRange*7/100;
    122   }
    123   var digits = Math.max( getLatLonDigits(latRange,4,2), getLatLonDigits(lonRange,4,2) );
    124   var box = new GLatLngBounds(
    125       new GLatLng( Math.roundN(bounds.getSouthWest().lat()-sd,digits), Math.roundN( bounds.getSouthWest().lng()-wd,digits ) ),
    126       new GLatLng( Math.roundN(bounds.getNorthEast().lat()+nd,digits), Math.roundN(bounds.getNorthEast().lng()+ed,digits) )
    127     );
    128  
    129   var url = this._urlMapData;
    130   url += "&box=" + box.getSouthWest().toUrlValue(5) + "," + box.getNorthEast().toUrlValue(5);
    131   url += "&lap=" +  Math.roundN( latPrec, getLatLonDigits(latPrec,1,1) ).toString();
    132   url += "&lop=" +  Math.roundN( lonPrec, getLatLonDigits(lonPrec,1,1) ).toString();
    133  
    134   if (document.is_debug) {
    135     GLog.write( "bounds: " + bounds.getSouthWest().toUrlValue() + " " + bounds.getNorthEast().toUrlValue() +"; zoom: "+this._map.getZoom() +"; size: "+this._map.getSize().toString() +"; c: "+this._map.getCenter().toUrlValue() );
    136     GLog.writeUrl( url );
    137   }
    138  
    139   this._previousLoadDataReq.box = box;
    140   this._previousLoadDataReq.zoom = this._map.getZoom();
    141   this._previousLoadDataReq.resultBounds = null;
    142   this._dataLoading = true;
     119        var nd=0, sd=0, ed=0, wd=0;
     120        if ( !bounds.isFullLat() )
     121        {
     122                nd = latRange*12/100;
     123                sd = latRange*4/100;
     124        }
     125        if ( !bounds.isFullLng() )
     126        {
     127                ed = lonRange*9/100;
     128                wd = lonRange*7/100;
     129        }
     130        var digits = Math.max( getLatLonDigits(latRange,4,2), getLatLonDigits(lonRange,4,2) );
     131        var box = new GLatLngBounds(
     132                        new GLatLng( Math.roundN(bounds.getSouthWest().lat()-sd,digits), Math.roundN( bounds.getSouthWest().lng()-wd,digits ) ),
     133                        new GLatLng( Math.roundN(bounds.getNorthEast().lat()+nd,digits), Math.roundN( bounds.getNorthEast().lng()+ed,digits) )
     134                );
    143135
    144   try {
    145     GEvent.trigger( this, "dataloading" );
    146     GDownloadUrl(url, this._onDataReceived.bind(this) );
    147   }
    148   catch (e) {
    149     this._dataLoading = false;
    150     this._previousLoadDataReq.box=null;
    151     GEvent.trigger( this, "dataloadfailed", 600, e );
    152   }
     136        var url = this._urlMapData;
     137        url += "&box=" + box.getSouthWest().toUrlValue(5) + "," + box.getNorthEast().toUrlValue(5);
     138        url += "&lap=" +  Math.roundN( latPrec, getLatLonDigits(latPrec,1,1) ).toString();
     139        url += "&lop=" +  Math.roundN( lonPrec, getLatLonDigits(lonPrec,1,1) ).toString();
     140
     141        if (document.is_debug) {
     142                GLog.write( "bounds: " + this._map.getBounds().getSouthWest().toUrlValue() + " " + this._map.getBounds().getNorthEast().toUrlValue() +"; zoom: "+this._map.getZoom() +"; size: "+this._map.getSize().toString() +"; c: "+this._map.getCenter().toUrlValue() );
     143                GLog.writeUrl( url );
     144        }
     145
     146        this._previousLoadDataReq.box = box;
     147        this._previousLoadDataReq.zoom = this._map.getZoom();
     148        this._previousLoadDataReq.resultBounds = null;
     149        this._dataLoading = true;
     150
     151        try {
     152                GEvent.trigger( this, "dataloading" );
     153                GDownloadUrl(url, this._onDataReceived.bind(this) );
     154        }
     155        catch (e) {
     156                this._dataLoading = false;
     157                this._previousLoadDataReq.box=null;
     158                GEvent.trigger( this, "dataloadfailed", 600, e );
     159        }
    153160},
    154161
    155162_onDataReceived: function(data, responseCode)
    156163{
    157   var resp;
    158   try
    159   {
    160     if (responseCode!=200)
    161     {
    162       this._previousLoadDataReq.box=null;
    163       GEvent.trigger( this, "dataloadfailed", responseCode, null );
    164     }
    165     else
    166     try
    167     {
    168                 eval('resp = ' + data);
    169                 if (resp.nb_items == undefined)
    170         throw new Error( "DATA DECODING ERROR" );
     164        var resp;
     165        try
     166        {
     167                if (responseCode!=200)
     168                {
     169                        this._previousLoadDataReq.box=null;
     170                        GEvent.trigger( this, "dataloadfailed", responseCode, null );
     171                }
     172                else
     173                try
     174                {
     175                        eval('resp = ' + data);
     176                        if (resp.nb_items == undefined)
     177                                throw new Error( "DATA DECODING ERROR" );
    171178
    172                 this._previousLoadDataReq.resultBounds = resp.bounds;
    173                 if (document.is_debug && resp.debug) GLog.write( resp.debug );
    174                 GEvent.trigger( this, "dataloaded", resp );
    175         }
    176         catch (e)       {
    177       this._previousLoadDataReq.box=null;
    178           GEvent.trigger( this, "dataloadfailed", responseCode, e );
    179                 var s = e.message;
    180                 s += '\n' + data.substr(0,1000);
    181                 alert( s );
    182         }
    183   }
    184   finally {
    185     this._dataLoading = false;
    186   }
     179                        this._previousLoadDataReq.resultBounds = resp.bounds;
     180                        if (document.is_debug && resp.debug) GLog.write( resp.debug );
     181                        GEvent.trigger( this, "dataloaded", resp );
     182                }
     183                catch (e)       {
     184                        this._previousLoadDataReq.box=null;
     185                        GEvent.trigger( this, "dataloadfailed", responseCode, e );
     186                        var s = e.message;
     187                        s += '\n' + data.substr(0,1000);
     188                        alert( s );
     189                }
     190        }
     191        finally {
     192                this._dataLoading = false;
     193        }
    187194}
    188195
  • extensions/rv_gmaps/trunk/template/map.tpl

    r4070 r5018  
    3535document.is_debug = false;
    3636if ( document.location.search.match(/[\?&]debug/) ) {
    37   document.is_debug = true;
    38   document._window = window;
     37        document.is_debug = true;
     38        document._window = window;
    3939}
    4040 
     
    4848
    4949        map.addMapType( G_PHYSICAL_MAP );
    50         map.addControl(new GLargeMapControl());
     50        map.addControl(new GLargeMapControl3D());
    5151        map.addControl(new GHierarchicalMapTypeControl());
    5252        map.addControl(new GScaleControl());
     
    5757{/literal}
    5858                {if isset($initial_bounds)}
    59     var bounds = new GLatLngBounds( new GLatLng({$initial_bounds.s},{$initial_bounds.w}), new GLatLng({$initial_bounds.n},{$initial_bounds.e}) );
    60     map.setCenter( bounds.getCenter(), map.getBoundsZoomLevel( bounds ) );
     59                var bounds = new GLatLngBounds( new GLatLng({$initial_bounds.s},{$initial_bounds.w}), new GLatLng({$initial_bounds.n},{$initial_bounds.e}) );
     60                map.setCenter( bounds.getCenter(), map.getBoundsZoomLevel( bounds ) );
    6161                {/if}
    6262{literal}
    6363                if ( !map.isLoaded() )
    6464                        map.setCenter( new GLatLng(0,0), 2 );
    65   }
    66 
    67   try {
     65        }
     66
     67        try {
    6868                // the overview must be added after setting map center
    6969                var ovcontrol = new GOverviewMapControl(new GSize(165,165));
    7070                map.addControl(ovcontrol);
    71   }
    72   catch(e){ alert( e.message ); }
    73  
     71        }
     72        catch(e){ alert( e.message ); }
     73
    7474        map.enableScrollWheelZoom();
    7575        map.enableDoubleClickZoom();
    76  
     76
    7777        var pwgMarkerIcon = (function(){ {/literal}{$MAP_MARKER_ICON_JS}{literal} }).call(null);
    7878
     
    100100                GEvent.addListener(map, "infowindowopen", function() { GLog.write("infowindowopen");} );
    101101                GEvent.addListener(map, "infowindowclose", function() { GLog.write("infowindowclose");} );
    102   }
     102        }
    103103}
    104104
     
    120120        geocoder.getLocations(q, function(resp)
    121121          {
    122             if ( resp && resp.Status )
    123             {
    124               document._geoResponse = resp;
    125               if (resp.Status.code==200)
    126               {
    127                 var zoom = 2;
    128                 switch (resp.Placemark[0].AddressDetails.Accuracy)
    129                 {
    130                   case 1: zoom=5; break; //country
    131                   case 2: zoom=7; break; //region
    132                   case 3: zoom=8; break; //county
    133                   case 4: zoom=12; break; //town
    134                   case 5: zoom=13; break; //post code
    135                   case 6: zoom=14; break; //street
    136                   case 7: case 8: zoom=16; break; //intersection/exact
    137                 }
    138                 map.setCenter( new GLatLng( resp.Placemark[0].Point.coordinates[1], resp.Placemark[0].Point.coordinates[0] ), zoom);
    139               }
    140               else
    141                 alert("This address has not been found\nCode:"+resp.Status.code);
    142             }
     122                if ( resp && resp.Status )
     123                {
     124                  document._geoResponse = resp;
     125                  if (resp.Status.code==200)
     126                  {
     127                        var zoom = 2;
     128                        switch (resp.Placemark[0].AddressDetails.Accuracy)
     129                        {
     130                          case 1: zoom=5; break; //country
     131                          case 2: zoom=7; break; //region
     132                          case 3: zoom=8; break; //county
     133                          case 4: zoom=12; break; //town
     134                          case 5: zoom=13; break; //post code
     135                          case 6: zoom=14; break; //street
     136                          case 7: case 8: zoom=16; break; //intersection/exact
     137                        }
     138                        map.setCenter( new GLatLng( resp.Placemark[0].Point.coordinates[1], resp.Placemark[0].Point.coordinates[0] ), zoom);
     139                  }
     140                  else
     141                        alert("This address has not been found\nCode:"+resp.Status.code);
     142                }
    143143          });
    144144        return false;
Note: See TracChangeset for help on using the changeset viewer.