http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83445

Revision: 83445
Author:   jeroendedauw
Date:     2011-03-07 07:08:33 +0000 (Mon, 07 Mar 2011)
Log Message:
-----------
Yahoo! Maps js rewrite

Modified Paths:
--------------
    branches/Maps0.8/Maps_Settings.php
    branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMaps.php
    branches/Maps0.8/includes/services/YahooMaps/YahooMaps.php

Added Paths:
-----------
    branches/Maps0.8/includes/services/YahooMaps/ext.maps.yahoomaps.js
    branches/Maps0.8/includes/services/YahooMaps/jquery.yahoomaps.js

Removed Paths:
-------------
    branches/Maps0.8/includes/services/YahooMaps/YahooMapFunctions.js

Modified: branches/Maps0.8/Maps_Settings.php
===================================================================
--- branches/Maps0.8/Maps_Settings.php  2011-03-07 07:05:02 UTC (rev 83444)
+++ branches/Maps0.8/Maps_Settings.php  2011-03-07 07:08:33 UTC (rev 83445)
@@ -92,7 +92,7 @@
        include_once $egMapsDir . 'includes/services/OpenLayers/OpenLayers.php';
        
        # Yahoo! Maps API
-       // include_once $egMapsDir . 
'includes/services/YahooMaps/YahooMaps.php';
+       include_once $egMapsDir . 'includes/services/YahooMaps/YahooMaps.php';
        
        # WMF OSM
        include_once $egMapsDir . 'includes/services/OSM/OSM.php';      
@@ -101,7 +101,7 @@
        $egMapsAvailableServices = array(
                //'googlemaps2',
                'googlemaps3',
-               //'yahoomaps',
+               'yahoomaps',
                'openlayers',
                'osm'
        );

Modified: branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMaps.php
===================================================================
--- branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMaps.php     
2011-03-07 07:05:02 UTC (rev 83444)
+++ branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMaps.php     
2011-03-07 07:08:33 UTC (rev 83445)
@@ -51,10 +51,7 @@
                $params['controls'] = new ListParameter( 'controls' );
                $params['controls']->setDefault( $egMapsYMapControls );
                $params['controls']->addCriteria( new CriterionInArray( 
self::getControlNames() ) );
-               $params['controls']->addManipulations(
-                       new ParamManipulationFunctions( 'strtolower' ),
-                       new ParamManipulationImplode( ',', "'" )
-               );              
+               $params['controls']->addManipulations( new 
ParamManipulationFunctions( 'strtolower' ) );                
                
                $params['type'] = new Parameter(
                        'type',
@@ -78,14 +75,13 @@
                                new CriterionInArray( self::getTypeNames() ),
                        )
                );
-               $params['types']->addManipulations( new MapsParamYMapType(), 
new ParamManipulationImplode( ',', "'" ) );
+               $params['types']->addManipulations( new MapsParamYMapType() );
                
                $params['autozoom'] = new Parameter(
                        'autozoom',
                        Parameter::TYPE_BOOLEAN,
                        $egMapsYahooAutozoom
                );
-               $params['autozoom']->addManipulations( new 
ParamManipulationBoolstr() );
        }
        
        /**
@@ -147,5 +143,18 @@
                return array( 'scale', 'type', 'pan', 'zoom', 'zoom-short', 
'auto-zoom' );
        }
 
+       /**
+        * @see MapsMappingService::getResourceModules
+        * 
+        * @since 0.8
+        * 
+        * @return array of string
+        */
+       public function getResourceModules() {
+               return array_merge(
+                       parent::getResourceModules(),
+                       array( 'ext.maps.yahoomaps' )
+               );
+       }
+       
 }
-                                                       
\ No newline at end of file

Deleted: branches/Maps0.8/includes/services/YahooMaps/YahooMapFunctions.js
===================================================================
--- branches/Maps0.8/includes/services/YahooMaps/YahooMapFunctions.js   
2011-03-07 07:05:02 UTC (rev 83444)
+++ branches/Maps0.8/includes/services/YahooMaps/YahooMapFunctions.js   
2011-03-07 07:08:33 UTC (rev 83445)
@@ -1,113 +0,0 @@
- /**
-  * Javascript functions for Yahoo! Maps functionality in Maps and its 
extensions
-  *
-  * @file YahooMapFunctions.js
-  * @ingroup MapsYahooMaps
-  *
-  * @author Jeroen De Dauw
-  */
-
-
-/**
- * Returns YMarker object on the provided location.
- * It will show a popup baloon with title and label when clicked, if either of 
these is set.
- */
-function createYMarker(geoPoint, title, label, icon){
-       var newMarker;
-       
-       if ( icon != '' ) {
-               /* Determine size of icon and pass it in */
-               var newimg = new Image();
-               newimg.src = icon;
-               newMarker = new YMarker( geoPoint,  new YImage( icon, new 
YSize( newimg.width, newimg.height ) ) );
-       } else {
-               newMarker = new YMarker( geoPoint );
-       }       
-       
-       if ((title + label).length > 0) {
-               var bothTxtAreSet = title.length > 0 && label.length > 0;
-               var markerMarkup = bothTxtAreSet ? '<b>' + title + '</b><hr />' 
+ label : title + label;
-               YEvent.Capture(newMarker, EventsList.MouseClick, 
-                       function(){
-                               newMarker.openSmartWindow(markerMarkup);
-                       }
-               );
-       }
-
-       return newMarker;
-}
-
-/**
- * Returns YMap object with the provided properties and markers.
- */
-function initializeYahooMap( mapName, lat, lon, zoom, type, types, controls, 
scrollWheelZoom, markers ) {
-        var centre = ( lon != null && lat != null ) ? new YGeoPoint( lat, lon 
) : null;
-        return createYahooMap( document.getElementById( mapName ), centre, 
zoom, type, types, controls, scrollWheelZoom, markers );
-}
-
-/**
- * Returns YMap object with the provided properties.
- */
-function createYahooMap( mapElement, centre, zoom, type, types, controls, 
scrollWheelZoom, markers ) {
-       var typesContainType = false;
-
-       for (var i = 0; i < types.length; i++) {
-               if (types[i] == type) typesContainType = true;
-       }
-       
-       if (! typesContainType) types.push(type);        
-        
-       var map = new YMap(mapElement, type); 
-       
-       map.removeZoomScale();
-       
-       for ( var i = controls.length - 1; i >= 0; i-- ){
-               if ( controls[i].toLowerCase() == 'auto-zoom' ) {
-                       if ( mapElement.offsetHeight > 42 ) controls[i] = 
mapElement.offsetHeight > 100 ? 'zoom' : 'zoom-short';
-               }                       
-               
-               switch (controls[i]) {
-                       case 'scale' : 
-                               map.addZoomScale();
-                       case 'type' :
-                               map.addTypeControl(types);
-                               break;          
-                       case 'pan' :
-                               map.addPanControl();
-                               break;
-                       case 'zoom' : 
-                               map.addZoomLong();
-                               break;          
-                       case 'zoom-short' : 
-                               map.addZoomShort();                             
-                               break;
-               }
-       }
-       
-       map.setMapType( type );
-       
-       if ( !scrollWheelZoom ) map.disableKeyControls();
-       
-       var map_locations = ( ( zoom == null || centre == null ) && 
markers.length > 1 ) ? Array() : null;
-       
-       for ( var i= markers.length - 1; i >= 0; i-- ) {
-               var marker = markers[i];
-               marker.point = new YGeoPoint( marker.lat, marker.lon );         
-               map.addOverlay( createYMarker( marker.point, marker.title, 
marker.label, marker.icon ) );
-               if ( map_locations != null ) map_locations.push( marker.point );
-       }
-
-       if (map_locations != null) {
-               var centerAndZoom = map.getBestZoomAndCenter(map_locations);
-               map.drawZoomAndCenter(centerAndZoom.YGeoPoint, 
centerAndZoom.zoomLevel);
-       }
-       
-       if ( zoom != null ) map.setZoomLevel( zoom );
-       
-       // FIXME: the code after this line REFUSES to be executed
-       // This is probably caused by the YGeoPoint
-       // Notice that the map object will therefore NOT BE RETURNED!
-       if ( centre != null ) map.drawZoomAndCenter( centre );
-       
-       return map;
-}
\ No newline at end of file

Modified: branches/Maps0.8/includes/services/YahooMaps/YahooMaps.php
===================================================================
--- branches/Maps0.8/includes/services/YahooMaps/YahooMaps.php  2011-03-07 
07:05:02 UTC (rev 83444)
+++ branches/Maps0.8/includes/services/YahooMaps/YahooMaps.php  2011-03-07 
07:08:33 UTC (rev 83445)
@@ -20,6 +20,16 @@
        die( 'Not an entry point.' );
 }
 
+$wgResourceModules['ext.maps.yahoomaps'] = array(
+       'localBasePath' => dirname( __FILE__ ),
+       'remoteBasePath' => $egMapsScriptPath .  
'/includes/services/YahooMaps',        
+       'group' => 'ext.maps',
+       'scripts' =>   array(
+               'jquery.yahoomaps.js',
+               'ext.maps.yahoomaps.js'
+       ),
+);
+
 $wgHooks['MappingServiceLoad'][] = 'efMapsInitYahooMaps';
 
 function efMapsInitYahooMaps() {

Added: branches/Maps0.8/includes/services/YahooMaps/ext.maps.yahoomaps.js
===================================================================
--- branches/Maps0.8/includes/services/YahooMaps/ext.maps.yahoomaps.js          
                (rev 0)
+++ branches/Maps0.8/includes/services/YahooMaps/ext.maps.yahoomaps.js  
2011-03-07 07:08:33 UTC (rev 83445)
@@ -0,0 +1,21 @@
+/**
+ * JavasSript for Yahoo! Maps maps in the Maps extension.
+ * @see http://www.mediawiki.org/wiki/Extension:Maps
+ * 
+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
+ */
+
+jQuery(document).ready(function() {
+       if ( true ) {
+               for ( i in window.maps.yahoomaps ) {
+                       jQuery( '#' + i ).yahoomaps( i, 
window.maps.yahoomaps[i] );
+               }
+       }
+       else {
+               alert( mediaWiki.msg( 'maps-openlayers-incompatbrowser' ) );
+               
+               for ( i in window.maps.googlemaps3 ) {
+                       jQuery( '#' + i ).text( mediaWiki.msg( 
'maps-load-failed' ) );
+               }
+       }       
+});


Property changes on: 
branches/Maps0.8/includes/services/YahooMaps/ext.maps.yahoomaps.js
___________________________________________________________________
Added: svn:eol-style
   + native

Added: branches/Maps0.8/includes/services/YahooMaps/jquery.yahoomaps.js
===================================================================
--- branches/Maps0.8/includes/services/YahooMaps/jquery.yahoomaps.js            
                (rev 0)
+++ branches/Maps0.8/includes/services/YahooMaps/jquery.yahoomaps.js    
2011-03-07 07:08:33 UTC (rev 83445)
@@ -0,0 +1,108 @@
+/**
+ * JavasSript for OpenLayers maps in the Maps extension.
+ * @see http://www.mediawiki.org/wiki/Extension:Maps
+ * 
+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
+ */
+
+(function( $ ){ $.fn.yahoomaps = function( mapElementId, options ) {
+       
+       var typesContainType = false;
+
+       for ( var i = 0; i < options.types.length; i++ ) {
+               if ( options.types[i] == options.type ) typesContainType = true;
+       }
+       
+       if ( !typesContainType ) {
+               options.types.push( options.type );
+       }        
+        
+       var map = new YMap( mapElementId, eval( options.type ) ); 
+       
+       map.removeZoomScale();
+
+       for ( var i = options.controls.length - 1; i >= 0; i-- ){
+               if ( options.controls[i].toLowerCase() == 'auto-zoom' ) {
+                       if ( this.get( 0 ).offsetHeight > 42 ) 
options.controls[i] = this.get( 0 ).offsetHeight > 100 ? 'zoom' : 'zoom-short';
+               }                       
+               
+               switch ( options.controls[i] ) {
+                       case 'scale' : 
+                               map.addZoomScale();
+                       case 'type' :
+                               var types = [];
+                               
+                               for ( x in options.types ) {
+                                       types.push( eval( options.types[x] ) );
+                               }
+                               
+                               map.addTypeControl( types );
+                               break;          
+                       case 'pan' :
+                               map.addPanControl();
+                               break;
+                       case 'zoom' : 
+                               map.addZoomLong();
+                               break;          
+                       case 'zoom-short' : 
+                               map.addZoomShort();                             
+                               break;
+               }
+       }
+       
+       map.setMapType( eval( options.type ) );
+       
+       if ( !options.autozoom ) map.disableKeyControls();
+       
+       if ( !options.locations ) {
+               options.locations = [];
+       }
+       
+       var map_locations = ( ( options.zoom === false || options.centre === 
false ) && options.locations.length > 1 ) ? Array() : null;
+       
+       for ( var i= options.locations.length - 1; i >= 0; i-- ) {
+               var location = options.locations[i];
+               location.point = new YGeoPoint( location.lat, location.lon );   
+               map.addOverlay( createYMarker( location.point, location.title, 
location.text, location.icon ) );
+               if ( map_locations != null ) map_locations.push( location.point 
);
+       }
+
+       if ( map_locations != null ) {
+               var centerAndZoom = map.getBestZoomAndCenter( map_locations );
+               map.drawZoomAndCenter( centerAndZoom.YGeoPoint, 
centerAndZoom.zoomLevel );
+       }
+       
+       if ( options.zoom !== false ) map.setZoomLevel( options.zoom );
+       
+       if ( options.centre !== false ) map.drawZoomAndCenter( new YGeoPoint( 
options.centre.lat, options.centre.lon ) );
+       
+       /**
+        * Returns YMarker object on the provided location.
+        * It will show a popup baloon with title and label when clicked, if 
either of these is set.
+        */
+       function createYMarker(geoPoint, title, text, icon){
+               var newMarker;
+               
+               if ( icon != '' ) {
+                       // Determine size of icon and pass it in.
+                       var newimg = new Image();
+                       newimg.src = icon;
+                       newMarker = new YMarker( geoPoint,  new YImage( icon, 
new YSize( newimg.width, newimg.height ) ) );
+               } else {
+                       newMarker = new YMarker( geoPoint );
+               }       
+               
+               if ( text != '' ) {
+                       YEvent.Capture(newMarker, EventsList.MouseClick, 
+                               function() {
+                                       newMarker.openSmartWindow( text );
+                               }
+                       );
+               }
+
+               return newMarker;
+       }       
+       
+       return this;
+       
+}; })( jQuery );
\ No newline at end of file


Property changes on: 
branches/Maps0.8/includes/services/YahooMaps/jquery.yahoomaps.js
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to