Ignore:
Timestamp:
Dec 6, 2011, 5:42:24 AM (12 years ago)
Author:
rvelices
Message:

rv_gmaps towards full maps api v3 migration (still to test)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_gmaps/trunk/template/data_handler.js

    r8724 r12698  
    33{
    44        this._map = map;
     5        this._infoWindow = new google.maps.InfoWindow();
    56        this.options = jQuery.fn.extend(
    67                {
    7                         icon: G_DEFAULT_ICON,
     8                        markerOptions: {},
    89                        show_all_img_src: null
    910                }
    1011                , opts || {} );
    1112
    12         google.maps.Event.addListener( map, "infowindowclose", function() {map.getInfoWindow().pwgMarker=null;} );
     13        google.maps.event.addListener( map, "infowindowclose", function() {map.getInfoWindow().pwgMarker=null;} );
    1314}
    1415
     
    1617
    1718_map: null,
     19_infoWindow: null,
    1820options: {},
    1921_markers: [],
     
    6062        {
    6163                changed = false;
    62                 if (this._markers.length>0 && !this._markers[0].getLatLng().equals( data.image_clusters[0].position ) )
     64                if (this._markers.length>0 && !this._markers[0].getPosition().equals( data.image_clusters[0].position ) )
    6365                        changed=true;
    6466        }
     
    6769        {
    6870                var newMarkers = [];
    69                 var infoWindowMarker = this._map.getInfoWindow().pwgMarker;
     71                var infoWindowMarker = this._infoWindow.pwgMarker;
    7072
    7173                for (i=0; i<data.image_clusters.length; i++)
     
    8284                        if (marker && marker==infoWindowMarker)
    8385                        {
    84                                 this._map.removeOverlay( marker );
    85                                 google.maps.Event.clearListeners(marker, "click" );
    86                                 google.maps.Event.clearListeners(marker, "dblclick" );
    87                                 this._map.getInfoWindow().pwgMarker = infoWindowMarker = null;
    88                                 if (document.is_debug) google.maps.Log.write('removed marker with infoWindow');
     86        marker.setMap(null);
     87                                google.maps.event.clearListeners(marker, "click" );
     88                                google.maps.event.clearListeners(marker, "dblclick" );
     89                                this._infoWindow.pwgMarker = infoWindowMarker = null;
     90                                if (document.is_debug) glog('removed marker with infoWindow');
    8991                                marker = this._markers.pop();
    9092                        }
     
    9294                        if (!marker)
    9395                        {
    94                                 marker = new google.maps.Marker( cluster.position, {title:  theTitle, icon: this.options.icon } );
    95                                 google.maps.Event.addListener( marker, "click", pwgBind(this, this._onMarkerClick, marker) );
    96                                 google.maps.Event.addListener( marker, "dblclick", pwgBind(this, this._onMarkerDblClick, marker) );
    97                                 this._map.addOverlay( marker );
     96                                marker = new google.maps.Marker(this.options.markerOptions);
     97        marker.setPosition(cluster.position);
     98        marker.setTitle(theTitle);
     99                                google.maps.event.addListener( marker, "click", pwgBind(this, this._onMarkerClick, marker) );
     100                                google.maps.event.addListener( marker, "dblclick", pwgBind(this, this._onMarkerDblClick, marker) );
     101        marker.setMap(this._map);
    98102                        }
    99103                        else
    100104                        {
    101105                                marker.currentImageIndex=0;
    102                                 marker.setLatLng( cluster.position );
    103                                 // changing the marker title is undocumented so we hack it
    104                                 if (!this.hack)
    105                                 {
    106                                         this.hack = {};
    107                                         for (var prop in marker)
    108                                         {
    109                                                 if ( typeof(marker[prop])!='object') continue;
    110                                                 if (!this.hack.markerHtmlElemWithTitle )
    111                                                 {
    112                                                         try {
    113                                                                 if (eval("typeof marker." + prop + "[0].src") == "string" && eval("typeof marker." + prop + "[0].title") == "string" )
    114                                                                         this.hack.markerHtmlElemWithTitle = prop;
    115                                                         }
    116                                                         catch (e) {}
    117                                                 }
    118                                                 if (!this.hack.markerOptions)
    119                                                         try {
    120                                                                 if ( eval("typeof marker."+prop+".title")=="string" && eval("typeof marker."+prop+".src")=="undefined")
    121                                                                         this.hack.markerOptions = prop;
    122                                                         }
    123                                                         catch (e) {}
    124                                         }
    125                                 }
    126                                 //undocumented marker.K , marker.ch and marker.jb and marker.l
    127                                 if (this.hack.markerOptions)
    128                                         eval( 'marker.'+this.hack.markerOptions+'.title=theTitle');
    129                                 if (this.hack.markerHtmlElemWithTitle)
    130                                         eval( 'marker.'+this.hack.markerHtmlElemWithTitle+'[0].title=theTitle');
     106                                marker.setPosition( cluster.position );
     107                                marker.setTitle(theTitle);
     108                                marker.setMap(this._map);
    131109                        }
    132110
     
    143121                for (i=0; i<this._markers.length; i++)
    144122                {
    145                         this._map.removeOverlay( this._markers[i] );
    146                         google.maps.Event.clearListeners(this._markers[i], "click" );
    147                         google.maps.Event.clearListeners(this._markers[i], "dblclick" );
     123                        this._markers[i].setMap(null);
     124                        google.maps.event.clearListeners(this._markers[i], "click" );
     125                        google.maps.event.clearListeners(this._markers[i], "dblclick" );
    148126                }
    149127
     
    158136_onMarkerClick: function( marker )
    159137{
    160         if (this._map.getInfoWindow().pwgMarker == marker )
     138        if (this._infoWindow.pwgMarker == marker )
    161139                return; // already open
    162140        var content = "";
     
    182160        content += '<div id="pwgImageDetail">' + this.buildCurrentPictureHtml( marker ) + '</div>';
    183161
    184         marker.openInfoWindowHtml( content );
     162        this._infoWindow.setContent( content );
     163        this._infoWindow.setPosition( marker.getPosition() );
     164        this._infoWindow.open( this._map );
    185165
    186166        // bind to next / prev a little later because sometimes the nodes are not immediately created
     
    193173_onMarkerDblClick: function( marker )
    194174{
    195         this._map.setCenter( marker.pwg.bounds.getCenter(), this._map.getBoundsZoomLevel( marker.pwg.bounds ) );
     175        this._map.fitBounds( marker.pwg.bounds );
    196176},
    197177
     
    228208        clearTimeout(this._timerBindPictureNavigation);
    229209        this._timerBindPictureNavigation = null;
    230         this._map.getInfoWindow().pwgMarker = marker;
     210        this._infoWindow.pwgMarker = marker;
    231211        for (var i=0; i< this._navHtmlIds.length; i++)
    232212        {
    233213                var elt = document.getElementById( this._navHtmlIds[i] );
    234214                if (elt)
    235                         google.maps.Event.addDomListener(elt, "click", pwgBind(this, this._onPictureNavigate, marker, i) );
     215                        google.maps.event.addDomListener(elt, "click", pwgBind(this, this._onPictureNavigate, marker, i) );
    236216        }
    237217},
Note: See TracChangeset for help on using the changeset viewer.