r114599 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114598‎ | r114599 | r114600 >
Date:11:16, 29 March 2012
Author:netbrain
Status:deferred
Tags:
Comment:
added polygons parameter, can draw polygons on map
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.php
@@ -16,7 +16,9 @@
1717 $messages['en'] = array(
1818 // General
1919 'maps-desc' => "Enables embedding of dynamic maps into wiki pages, geocoding of addresses and other geographical operations. ([http://mapping.referata.com/wiki/Examples demos])",
 20+
2021 'right-geocode' => 'Geocode',
 22+
2123 'maps_map' => 'Map',
2224 'maps-loading-map' => 'Loading map...',
2325 'maps-load-failed' => 'Could not load the map!',
@@ -51,7 +53,7 @@
5254 // Mapsdoc parser hook
5355 'maps-mapsdoc-par-service' => 'The mapping service to display parameter documentation for.',
5456 'maps-mapsdoc-par-language' => 'The language in which to display the documentation. If no such translation is available, English will be used instead.',
55 -
 57+
5658 // Coordinates parser hook
5759 'maps-coordinates-par-location' => 'The coordinates you want to format.',
5860 'maps-coordinates-par-format' => 'The target format for the coordinates.',
@@ -124,7 +126,8 @@
125127
126128 'validation-error-invalid-goverlay' => 'Parameter $1 must be a valid overlay.',
127129 'validation-error-invalid-goverlays' => 'Parameter $1 must be one or more valid overlays.',
128 - 'validation-error-invalid-line-param' => 'Invalid "lines" parameter specified.',
 130+ 'validation-error-invalid-line-param' => 'Invalid "lines" parameter specified.',
 131+ 'validation-error-invalid-polyline-param' => 'Invalid "polylines" parameter specified.',
129132
130133 // Coordinate handling
131134 'maps-abb-north' => 'N',
@@ -250,9 +253,6 @@
251254 'maps-googlemaps3-par-tilt' => '{{maps-par|googlemaps3|tilt}}',
252255 'maps-googlemaps3-par-kmlrezoom' => '{{maps-par|googlemaps3|kmlrezoom}}',
253256 'maps-googlemaps3-par-poi' => '{{maps-par|googlemaps3|poi}}',
254 - 'maps-copycoords-prompt' => 'text displayed in javascript prompt to indicate first press ctrl+c to copy text, and press enter to close prompt',
255 - 'maps-clustering-unsupportedservice' => 'text describing that the chosen maps service doesn\'t support clustering of markers',
256 - 'validation-error-invalid-line-param' => 'validation text indicating that there is something wrong with the "lines" parameter'
257257 );
258258
259259 /** Afrikaans (Afrikaans)
Index: trunk/extensions/Maps/Maps.php
@@ -81,6 +81,7 @@
8282 $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
8383 $wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php';
8484 $wgAutoloadClasses['MapsLine'] = $incDir . 'Maps_Line.php';
 85+$wgAutoloadClasses['MapsPolygon'] = $incDir . 'Maps_Polygon.php';
8586 $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
8687 $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
8788 $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php';
@@ -95,6 +96,7 @@
9697 $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
9798 $wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php';
9899 $wgAutoloadClasses['CriterionLine'] = $criDir . 'CriterionLine.php';
 100+$wgAutoloadClasses['CriterionPolygon'] = $criDir . 'CriterionPolygon.php';
99101 unset( $criDir );
100102
101103 // Autoload the "includes/features/" classes.
@@ -126,6 +128,7 @@
127129 $wgAutoloadClasses['MapsParamService'] = $manDir . 'Maps_ParamService.php';
128130 $wgAutoloadClasses['MapsParamZoom'] = $manDir . 'Maps_ParamZoom.php';
129131 $wgAutoloadClasses['MapsParamLine'] = $manDir . 'Maps_ParamLine.php';
 132+$wgAutoloadClasses['MapsParamPolygon'] = $manDir . 'Maps_ParamPolygon.php';
130133 unset( $manDir );
131134
132135 // Autoload the "includes/parserHooks/" classes.
Index: trunk/extensions/Maps/RELEASE-NOTES
@@ -19,6 +19,7 @@
2020 * '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.
2121 * 'display_line' new parameter copycoords, when set to "on" will give right clicks on map a prompt of longitude and latitude coordinates
2222 * 'display_line' new parameter markercluster, when set to "on" will cluster closely adjacent markers together.
 23+* 'display_line' new parameter polygons, has same syntax as lines parameter and can draw polygons on map
2324
2425 === Maps 1.0.5 ===
2526 (2011-11-30)
Index: trunk/extensions/Maps/includes/services/GoogleMaps3/jquery.googlemap.js
@@ -27,6 +27,11 @@
2828 */
2929 this.lines = [];
3030
 31+ /**
 32+ * All polygons currently on the map,
 33+ */
 34+ this.polygons = [];
 35+
3136 /**
3237 * Creates a new marker with the provided data,
3338 * adds it to the map, and returns it.
@@ -188,8 +193,59 @@
189194 this.lines[i].setMap( null );
190195 }
191196 this.lines = [];
192 - }
 197+ };
193198
 199+ this.addPolygon = function(properties){
 200+ var paths = new google.maps.MVCArray();
 201+ for(var x = 0; x < properties.pos.length; x++){
 202+ paths.push(new google.maps.LatLng( properties.pos[x].lat , properties.pos[x].lon ));
 203+ }
 204+
 205+ var polygon = new google.maps.Polygon({
 206+ map:this.map,
 207+ path:paths,
 208+ strokeColor:properties.strokeColor,
 209+ strokeOpacity:properties.strokeOpacity,
 210+ strokeWeight:properties.strokeWeight,
 211+ fillColor:properties.fillColor,
 212+ fillOpacity: properties.fillOpacity
 213+ });
 214+ this.polygons.push(polygon);
 215+
 216+ google.maps.event.addListener(polygon,"click", function(event){
 217+ if (this.openWindow != undefined) {
 218+ this.openWindow.close();
 219+ }
 220+ this.openWindow = new google.maps.InfoWindow();
 221+ this.openWindow.content = properties.text;
 222+ this.openWindow.position = event.latLng;
 223+ this.openWindow.closeclick = function() {
 224+ polygon.openWindow = undefined;
 225+ };
 226+ this.openWindow.open(_this.map);
 227+ });
 228+ };
 229+
 230+ this.removePolygon = function(polygon){
 231+ polygon.setMap( null );
 232+
 233+ for ( var i = this.polygon.length - 1; i >= 0; i-- ) {
 234+ if ( this.polygon[i] === polygon ) {
 235+ delete this.polygon[i];
 236+ break;
 237+ }
 238+ }
 239+
 240+ delete polygon;
 241+ };
 242+
 243+ this.removePolygons = function(){
 244+ for ( var i = this.polygon.length - 1; i >= 0; i-- ) {
 245+ this.polygon[i].setMap( null );
 246+ }
 247+ this.polygon = [];
 248+ };
 249+
194250 this.setup = function() {
195251 var showEarth = $.inArray( 'earth', options.types ) !== -1;
196252
@@ -380,6 +436,15 @@
381437 }
382438
383439 /**
 440+ * used in display_line to draw polygons
 441+ */
 442+ if(options.polygons){
 443+ for ( var i = 0; i < options.polygons.length; i++ ) {
 444+ this.addPolygon(options.polygons[i]);
 445+ }
 446+ }
 447+
 448+ /**
384449 * used in display_line functionality
385450 * allows the copy to clipboard of coordinates
386451 */
Index: trunk/extensions/Maps/includes/services/OpenLayers/jquery.openlayers.js
@@ -125,6 +125,30 @@
126126 var lineFeature = new OpenLayers.Feature.Vector(line, {text:properties.text}, style);
127127 this.lineLayer.addFeatures([lineFeature]);
128128 }
 129+
 130+ this.addPolygon = function(properties){
 131+ var pos = new Array();
 132+ for(var x = 0; x < properties.pos.length; x++){
 133+ var point = new OpenLayers.Geometry.Point(properties.pos[x].lon,properties.pos[x].lat);
 134+ point.transform(
 135+ new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
 136+ map.getProjectionObject() // to Spherical Mercator Projection
 137+ );
 138+ pos.push(point);
 139+ }
 140+
 141+ var style = {
 142+ 'strokeColor':properties.strokeColor,
 143+ 'strokeWidth': properties.strokeWeight,
 144+ 'strokeOpacity': properties.strokeOpacity,
 145+ 'fillColor': properties.fillColor,
 146+ 'fillOpacity': properties.fillOpacity
 147+ }
 148+
 149+ var polygon = new OpenLayers.Geometry.LinearRing(pos);
 150+ var polygonFeature = new OpenLayers.Feature.Vector(polygon, {text:properties.text}, style);
 151+ this.polygonLayer.addFeatures([polygonFeature]);
 152+ }
129153
130154 /**
131155 * Gets a valid control name (with excat lower and upper case letters),
@@ -232,6 +256,47 @@
233257 }
234258 }
235259
 260+ if(options.polygons && options.polygons.length > 0){
 261+ this.polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
 262+ this.polygonLayer.events.on({
 263+ 'featureselected':function(feature){
 264+ if(feature.feature.attributes.text != undefined && feature.feature.attributes.text != ''){
 265+ var mousePos = map.getControlsByClass("OpenLayers.Control.MousePosition")[0].lastXy
 266+ var lonlat = map.getLonLatFromPixel(mousePos);
 267+ var popup = new OpenLayers.Popup(null,lonlat, null, feature.feature.attributes.text, true,function(){
 268+ map.getControlsByClass('OpenLayers.Control.SelectFeature')[0].unselectAll();
 269+ map.removePopup(this);
 270+ })
 271+ this.map.addPopup( popup );
 272+ }
 273+ },
 274+ 'featureunselected':function(feature){
 275+ //do nothing
 276+ }
 277+ });
 278+
 279+ var controls = {
 280+ select: new OpenLayers.Control.SelectFeature(this.polygonLayer,{
 281+ clickout: true, toggle: false,
 282+ multiple: true, hover: false
 283+ })
 284+ };
 285+
 286+ for(key in controls){
 287+ var control = controls[key];
 288+ map.addControl(control);
 289+ control.activate();
 290+ }
 291+
 292+ map.addLayer(this.polygonLayer);
 293+ map.raiseLayer(this.polygonLayer,-1);
 294+ map.resetLayersZIndex();
 295+
 296+ for ( var i = 0; i < options.polygons.length; i++ ) {
 297+ this.addPolygon(options.polygons[i]);
 298+ }
 299+ }
 300+
236301 if ( options.centre === false ) {
237302 if ( options.locations.length == 1 ) {
238303 centre = new OpenLayers.LonLat( options.locations[0].lon, options.locations[0].lat );
Index: trunk/extensions/Maps/includes/parserHooks/Maps_DisplayLine.php
@@ -68,6 +68,11 @@
6969 $params['lines']->addCriteria(new CriterionLine());
7070 $params['lines']->addManipulations( new MapsParamLine() );
7171
 72+ $params['polygons'] = new ListParameter( 'polygons', ';' );
 73+ $params['polygons']->setDefault(array());
 74+ $params['polygons']->addCriteria(new CriterionPolygon());
 75+ $params['polygons']->addManipulations( new MapsParamPolygon() );
 76+
7277 $params['copycoords'] = new Parameter(
7378 'copycoords',
7479 Parameter::TYPE_BOOLEAN
@@ -95,6 +100,6 @@
96101 * @return array
97102 */
98103 protected function getDefaultParameters( $type ) {
99 - return array( 'coordinates','lines' );
 104+ return array( 'coordinates','lines','polygons' );
100105 }
101106 }
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114598added polygons parameter, can draw polygons on mapnetbrain11:16, 29 March 2012

Status & tagging log