https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114599

Revision: 114599
Author:   netbrain
Date:     2012-03-29 11:16:43 +0000 (Thu, 29 Mar 2012)
Log Message:
-----------
added polygons parameter, can draw polygons on map

Modified Paths:
--------------
    trunk/extensions/Maps/Maps.i18n.php
    trunk/extensions/Maps/Maps.php
    trunk/extensions/Maps/RELEASE-NOTES
    trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php
    trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js
    trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js

Modified: trunk/extensions/Maps/Maps.i18n.php
===================================================================
--- trunk/extensions/Maps/Maps.i18n.php 2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/Maps.i18n.php 2012-03-29 11:16:43 UTC (rev 114599)
@@ -16,7 +16,9 @@
 $messages['en'] = array(
        // General
        'maps-desc' => "Enables embedding of dynamic maps into wiki pages, 
geocoding of addresses and other geographical operations. 
([http://mapping.referata.com/wiki/Examples demos])",
+       
        'right-geocode' => 'Geocode',
+       
        'maps_map' => 'Map',
        'maps-loading-map' => 'Loading map...',
        'maps-load-failed' => 'Could not load the map!',
@@ -51,7 +53,7 @@
        // Mapsdoc parser hook
        'maps-mapsdoc-par-service' => 'The mapping service to display parameter 
documentation for.',
        'maps-mapsdoc-par-language' => 'The language in which to display the 
documentation. If no such translation is available, English will be used 
instead.',
-
+       
        // Coordinates parser hook
        'maps-coordinates-par-location' => 'The coordinates you want to 
format.',
        'maps-coordinates-par-format' => 'The target format for the 
coordinates.',
@@ -124,7 +126,8 @@
 
        'validation-error-invalid-goverlay' => 'Parameter $1 must be a valid 
overlay.',
        'validation-error-invalid-goverlays' => 'Parameter $1 must be one or 
more valid overlays.',
-       'validation-error-invalid-line-param' => 'Invalid "lines" parameter 
specified.',
+       'validation-error-invalid-line-param' => 'Invalid "lines" parameter 
specified.',
+       'validation-error-invalid-polyline-param' => 'Invalid "polylines" 
parameter specified.',
 
        // Coordinate handling
        'maps-abb-north' => 'N',
@@ -250,9 +253,6 @@
        'maps-googlemaps3-par-tilt' => '{{maps-par|googlemaps3|tilt}}',
        'maps-googlemaps3-par-kmlrezoom' => 
'{{maps-par|googlemaps3|kmlrezoom}}',
        'maps-googlemaps3-par-poi' => '{{maps-par|googlemaps3|poi}}',
-       'maps-copycoords-prompt' => 'text displayed in javascript prompt to 
indicate first press ctrl+c to copy text, and press enter to close prompt',
-       'maps-clustering-unsupportedservice' => 'text describing that the 
chosen maps service doesn\'t support clustering of markers',
-       'validation-error-invalid-line-param' => 'validation text indicating 
that there is something wrong with the "lines" parameter'
 );
 
 /** Afrikaans (Afrikaans)

Modified: trunk/extensions/Maps/Maps.php
===================================================================
--- trunk/extensions/Maps/Maps.php      2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/Maps.php      2012-03-29 11:16:43 UTC (rev 114599)
@@ -81,6 +81,7 @@
 $wgAutoloadClasses['MapsLayers']                               = $incDir . 
'Maps_Layers.php';
 $wgAutoloadClasses['MapsLocation']                             = $incDir . 
'Maps_Location.php';
 $wgAutoloadClasses['MapsLine']                                     = $incDir . 
'Maps_Line.php';
+$wgAutoloadClasses['MapsPolygon']                              = $incDir . 
'Maps_Polygon.php';
 $wgAutoloadClasses['iMappingService']                  = $incDir . 
'iMappingService.php';
 $wgAutoloadClasses['MapsMappingServices']              = $incDir . 
'Maps_MappingServices.php';
 $wgAutoloadClasses['MapsMappingService']               = $incDir . 
'Maps_MappingService.php';
@@ -95,6 +96,7 @@
 $wgAutoloadClasses['CriterionMapDimension']    = $criDir . 
'CriterionMapDimension.php';
 $wgAutoloadClasses['CriterionMapLayer']                = $criDir . 
'CriterionMapLayer.php';
 $wgAutoloadClasses['CriterionLine']            = $criDir . 'CriterionLine.php';
+$wgAutoloadClasses['CriterionPolygon']                 = $criDir . 
'CriterionPolygon.php';
 unset( $criDir );
 
 // Autoload the "includes/features/" classes.
@@ -126,6 +128,7 @@
 $wgAutoloadClasses['MapsParamService']                         = $manDir . 
'Maps_ParamService.php';
 $wgAutoloadClasses['MapsParamZoom']                    = $manDir . 
'Maps_ParamZoom.php';
 $wgAutoloadClasses['MapsParamLine']                    = $manDir . 
'Maps_ParamLine.php';
+$wgAutoloadClasses['MapsParamPolygon']                         = $manDir . 
'Maps_ParamPolygon.php';
 unset( $manDir );
 
 // Autoload the "includes/parserHooks/" classes.

Modified: trunk/extensions/Maps/RELEASE-NOTES
===================================================================
--- trunk/extensions/Maps/RELEASE-NOTES 2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/RELEASE-NOTES 2012-03-29 11:16:43 UTC (rev 114599)
@@ -19,6 +19,7 @@
 * 'display_line' new parser function which has the parameter lines where one 
can specify coordinates/locations where a line should be drawn between, lines 
color. Currently supported with googlemaps and openlayers.
 * 'display_line' new parameter copycoords, when set to "on" will give right 
clicks on map a prompt of longitude and latitude coordinates
 * 'display_line' new parameter markercluster, when set to "on" will cluster 
closely adjacent markers together.
+* 'display_line' new parameter polygons, has same syntax as lines parameter 
and can draw polygons on map
 
 === Maps 1.0.5 ===
 (2011-11-30)

Modified: trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php
===================================================================
--- trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php     
2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php     
2012-03-29 11:16:43 UTC (rev 114599)
@@ -68,6 +68,11 @@
         $params['lines']->addCriteria(new CriterionLine());
         $params['lines']->addManipulations( new MapsParamLine() );
 
+        $params['polygons'] = new ListParameter( 'polygons', ';' );
+        $params['polygons']->setDefault(array());
+        $params['polygons']->addCriteria(new CriterionPolygon());
+        $params['polygons']->addManipulations( new MapsParamPolygon() );
+
         $params['copycoords'] = new Parameter(
             'copycoords',
             Parameter::TYPE_BOOLEAN
@@ -95,6 +100,6 @@
      * @return array
      */
     protected function getDefaultParameters( $type ) {
-        return array( 'coordinates','lines' );
+        return array( 'coordinates','lines','polygons' );
     }
 }
\ No newline at end of file

Modified: 
trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js
===================================================================
--- trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js     
2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js     
2012-03-29 11:16:43 UTC (rev 114599)
@@ -27,6 +27,11 @@
      */
     this.lines = [];
 
+    /**
+     * All polygons currently on the map,
+     */
+    this.polygons = [];
+
        /**
         * Creates a new marker with the provided data,
         * adds it to the map, and returns it.
@@ -188,8 +193,59 @@
             this.lines[i].setMap( null );
         }
         this.lines = [];
-    }
+    };
 
+    this.addPolygon = function(properties){
+        var paths = new google.maps.MVCArray();
+        for(var x = 0; x < properties.pos.length; x++){
+            paths.push(new google.maps.LatLng( properties.pos[x].lat , 
properties.pos[x].lon ));
+        }
+
+        var polygon = new google.maps.Polygon({
+            map:this.map,
+            path:paths,
+            strokeColor:properties.strokeColor,
+            strokeOpacity:properties.strokeOpacity,
+            strokeWeight:properties.strokeWeight,
+            fillColor:properties.fillColor,
+            fillOpacity: properties.fillOpacity
+        });
+        this.polygons.push(polygon);
+
+        google.maps.event.addListener(polygon,"click", function(event){
+            if (this.openWindow != undefined) {
+                this.openWindow.close();
+            }
+            this.openWindow = new google.maps.InfoWindow();
+            this.openWindow.content = properties.text;
+            this.openWindow.position = event.latLng;
+            this.openWindow.closeclick = function() {
+                polygon.openWindow = undefined;
+            };
+            this.openWindow.open(_this.map);
+        });
+    };
+
+    this.removePolygon = function(polygon){
+        polygon.setMap( null );
+
+        for ( var i = this.polygon.length - 1; i >= 0; i-- ) {
+            if ( this.polygon[i] === polygon ) {
+                delete this.polygon[i];
+                break;
+            }
+        }
+
+        delete polygon;
+    };
+
+    this.removePolygons = function(){
+        for ( var i = this.polygon.length - 1; i >= 0; i-- ) {
+            this.polygon[i].setMap( null );
+        }
+        this.polygon = [];
+    };
+
        this.setup = function() {
                var showEarth = $.inArray( 'earth', options.types ) !== -1; 
                
@@ -380,6 +436,15 @@
         }
 
         /**
+         * used in display_line to draw polygons
+         */
+        if(options.polygons){
+            for ( var i = 0; i < options.polygons.length; i++ ) {
+                this.addPolygon(options.polygons[i]);
+            }
+        }
+
+        /**
          * used in display_line functionality
          * allows the copy to clipboard of coordinates
          */

Modified: 
trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js
===================================================================
--- trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js     
2012-03-29 11:16:40 UTC (rev 114598)
+++ trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js     
2012-03-29 11:16:43 UTC (rev 114599)
@@ -125,6 +125,30 @@
         var lineFeature = new OpenLayers.Feature.Vector(line, 
{text:properties.text}, style);
         this.lineLayer.addFeatures([lineFeature]);
     }
+
+    this.addPolygon = function(properties){
+        var pos = new Array();
+        for(var x = 0; x < properties.pos.length; x++){
+            var point = new 
OpenLayers.Geometry.Point(properties.pos[x].lon,properties.pos[x].lat);
+            point.transform(
+                new OpenLayers.Projection("EPSG:4326"), // transform from WGS 
1984
+                map.getProjectionObject() // to Spherical Mercator Projection
+            );
+            pos.push(point);
+        }
+
+        var style = {
+            'strokeColor':properties.strokeColor,
+            'strokeWidth': properties.strokeWeight,
+            'strokeOpacity': properties.strokeOpacity,
+            'fillColor': properties.fillColor,
+            'fillOpacity': properties.fillOpacity
+        }
+
+        var polygon = new OpenLayers.Geometry.LinearRing(pos);
+        var polygonFeature = new OpenLayers.Feature.Vector(polygon, 
{text:properties.text}, style);
+        this.polygonLayer.addFeatures([polygonFeature]);
+    }
        
        /**
         * Gets a valid control name (with excat lower and upper case letters),
@@ -232,6 +256,47 @@
         }
     }
 
+    if(options.polygons && options.polygons.length > 0){
+        this.polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
+        this.polygonLayer.events.on({
+            'featureselected':function(feature){
+                if(feature.feature.attributes.text != undefined && 
feature.feature.attributes.text != ''){
+                    var mousePos = 
map.getControlsByClass("OpenLayers.Control.MousePosition")[0].lastXy
+                    var lonlat = map.getLonLatFromPixel(mousePos);
+                    var popup = new OpenLayers.Popup(null,lonlat, null, 
feature.feature.attributes.text, true,function(){
+                        
map.getControlsByClass('OpenLayers.Control.SelectFeature')[0].unselectAll();
+                        map.removePopup(this);
+                    })
+                    this.map.addPopup( popup );
+                }
+            },
+            'featureunselected':function(feature){
+                //do nothing
+            }
+        });
+
+        var controls = {
+            select: new OpenLayers.Control.SelectFeature(this.polygonLayer,{
+                clickout: true, toggle: false,
+                multiple: true, hover: false
+            })
+        };
+
+        for(key in controls){
+            var control = controls[key];
+            map.addControl(control);
+            control.activate();
+        }
+
+        map.addLayer(this.polygonLayer);
+        map.raiseLayer(this.polygonLayer,-1);
+        map.resetLayersZIndex();
+
+        for ( var i = 0; i < options.polygons.length; i++ ) {
+            this.addPolygon(options.polygons[i]);
+        }
+    }
+
        if ( options.centre === false ) {
                if ( options.locations.length == 1 ) {
                        centre = new OpenLayers.LonLat( 
options.locations[0].lon, options.locations[0].lat );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to