Netbrain has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75839


Change subject: Added method to toggle kml (geoxml3) layers on and off.
......................................................................

Added method to toggle kml (geoxml3) layers on and off.

Users will now be presented with a set of checkboxes for each
kml file loaded on the map. clicking the checkboxes will hide or show the
corresponding kml data.

Also added feedback to user in the form of an error message when
failure occurs in parsing kml files.

Change-Id: Iade1c305e70d9aa98c3927f52794a5009056ad88
---
M Maps.i18n.php
M includes/services/GoogleMaps3/GoogleMaps3.php
A includes/services/GoogleMaps3/geoxml3/ProjectedOverlay.js
M includes/services/GoogleMaps3/jquery.googlemap.js
4 files changed, 183 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Maps 
refs/changes/39/75839/1

diff --git a/Maps.i18n.php b/Maps.i18n.php
index 0467abf..b41c743 100644
--- a/Maps.i18n.php
+++ b/Maps.i18n.php
@@ -27,6 +27,7 @@
        'maps-copycoords-prompt' => 'CTRL+C, ENTER',
        'maps-searchmarkers-text' => 'Filter markers',
        'maps-others' => 'others',
+       'maps-kml-parsing-failed' => 'Failed parsing one or more kml files, 
usually due to retrieval failure or malformed XML.',
        //TODO: move to namespaces i18n
        'maps-ns-layer' => 'Layer',
        'maps-ns-layer-talk' => 'Layer talk',
@@ -259,6 +260,7 @@
        'right-geocode' => '{{doc-right|geocode}}',
        'maps_map' => '{{Identical|Map}}',
        'maps-copycoords-prompt' => 'text displayed in javascript prompt to 
indicate first press ctrl+c to copy text, and press enter to close prompt',
+       'maps-kml-parsing-failed' => 'text displayed in the event of parsing 
failure of kml file(s).',
        'maps-others' => '{{Identical|Other}}',
        'maps-layer-property' => '{{Identical|Property}}',
        'maps-layer-value' => '{{Identical|Value}}',
diff --git a/includes/services/GoogleMaps3/GoogleMaps3.php 
b/includes/services/GoogleMaps3/GoogleMaps3.php
index 8f74e34..a83d055 100644
--- a/includes/services/GoogleMaps3/GoogleMaps3.php
+++ b/includes/services/GoogleMaps3/GoogleMaps3.php
@@ -65,6 +65,7 @@
        'scripts' => array(
                'geoxml3.js',
                'ZipFile.complete.js', //kmz handling
+               'ProjectedOverlay.js', //Overlay handling
        ),
 );
 
diff --git a/includes/services/GoogleMaps3/geoxml3/ProjectedOverlay.js 
b/includes/services/GoogleMaps3/geoxml3/ProjectedOverlay.js
new file mode 100644
index 0000000..4056c2c
--- /dev/null
+++ b/includes/services/GoogleMaps3/geoxml3/ProjectedOverlay.js
@@ -0,0 +1,139 @@
+// Create an overlay on the map from a projected image - Maps v3...
+// Author. John D. Coryat 05/2009
+// USNaviguide LLC - http://www.usnaviguide.com
+// Thanks go to Mile Williams EInsert: 
http://econym.googlepages.com/einsert.js, Google's GOverlay Example and 
Bratliff's suggestion...
+// Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html
+// This program is free software; you can redistribute it and/or modify it 
under the terms of the GNU General Public License as published by the Free 
Software Foundation; either version 2 of the License, or (at your option) any 
later version. This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
more details. You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software Foundation, Inc., 
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// Parameters:
+//    map: This Map
+//    imageUrl: URL of the image (Mandatory)
+//    bounds: Bounds object of image destination (Mandatory)
+//    Options:
+//    addZoom: Added Zoom factor as a parameter to the imageUrl (include 
complete parameter, including separater like '?zoom='
+//    percentOpacity: Default 50, percent opacity to use when the image is 
loaded 0-100.
+//    id: Default imageUrl, ID of the div
+//
+       
+function ProjectedOverlay(map, imageUrl, bounds, opts)
+{
+ google.maps.OverlayView.call(this);
+
+ this.map_ = map;
+ this.url_ = imageUrl ;
+ this.bounds_ = bounds ;
+ this.addZ_ = opts.addZoom || '' ;                             // Add the zoom 
to the image as a parameter
+ this.id_ = opts.id || this.url_ ;                             // Added to 
allow for multiple images
+ this.percentOpacity_ = opts.percentOpacity || 50 ;
+
+ this.setMap(map);
+}
+
+ProjectedOverlay.prototype = new google.maps.OverlayView();
+
+ProjectedOverlay.prototype.createElement = function()
+{
+ var panes = this.getPanes() ;
+ var div = this.div_ ;
+
+ if (!div)
+ {
+  div = this.div_ = document.createElement("div");
+  div.style.position = "absolute" ;
+  div.setAttribute('id',this.id_) ;
+  this.div_ = div ;
+  this.lastZoom_ = -1 ;
+  if( this.percentOpacity_ )
+  {
+   this.setOpacity(this.percentOpacity_) ;
+  }
+  panes.overlayLayer.appendChild(div);
+ }
+}
+
+// Remove the main DIV from the map pane
+
+ProjectedOverlay.prototype.remove = function()
+{
+ if (this.div_) 
+ {
+  this.div_.parentNode.removeChild(this.div_);
+  this.div_ = null;
+  this.setMap(null);
+ }
+}
+
+// Redraw based on the current projection and zoom level...
+
+ProjectedOverlay.prototype.draw = function(firstTime)
+{
+ // Creates the element if it doesn't exist already.
+
+ this.createElement();
+
+ if (!this.div_)
+ {
+  return ;
+ }
+
+ var c1 = 
this.get('projection').fromLatLngToDivPixel(this.bounds_.getSouthWest());
+ var c2 = 
this.get('projection').fromLatLngToDivPixel(this.bounds_.getNorthEast());
+
+ if (!c1 || !c2) return;
+
+ // Now position our DIV based on the DIV coordinates of our bounds
+
+ this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
+ this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
+ this.div_.style.left = Math.min(c2.x, c1.x) + "px";
+ this.div_.style.top = Math.min(c2.y, c1.y) + "px";
+
+ // Do the rest only if the zoom has changed...
+ 
+ if ( this.lastZoom_ == this.map_.getZoom() )
+ {
+  return ;
+ }
+
+ this.lastZoom_ = this.map_.getZoom() ;
+
+ var url = this.url_ ;
+
+ if ( this.addZ_ )
+ {
+  url += this.addZ_ + this.map_.getZoom() ;
+ }
+
+ this.div_.innerHTML = '<img src="' + url + '"  width=' + 
this.div_.style.width + ' height=' + this.div_.style.height + ' >' ;
+}
+
+ProjectedOverlay.prototype.setOpacity=function(opacity)
+{
+ if (opacity < 0)
+ {
+  opacity = 0 ;
+ }
+ if(opacity > 100)
+ {
+  opacity = 100 ;
+ }
+ var c = opacity/100 ;
+
+ if (typeof(this.div_.style.filter) =='string')
+ {
+  this.div_.style.filter = 'alpha(opacity:' + opacity + ')' ;
+ }
+ if (typeof(this.div_.style.KHTMLOpacity) == 'string' )
+ {
+  this.div_.style.KHTMLOpacity = c ;
+ }
+ if (typeof(this.div_.style.MozOpacity) == 'string')
+ {
+  this.div_.style.MozOpacity = c ;
+ }
+ if (typeof(this.div_.style.opacity) == 'string')
+ {
+  this.div_.style.opacity = c ;
+ }
+}
+
diff --git a/includes/services/GoogleMaps3/jquery.googlemap.js 
b/includes/services/GoogleMaps3/jquery.googlemap.js
index ca6cfa1..3934816 100644
--- a/includes/services/GoogleMaps3/jquery.googlemap.js
+++ b/includes/services/GoogleMaps3/jquery.googlemap.js
@@ -184,7 +184,47 @@
                        // If there are any non-Google KML/KMZ layers, load the 
geoxml library and use it to add these layers.
                        if (options.kml.length != 0) {
                                mw.loader.using('ext.maps.gm3.geoxml', function 
() {
-                                       var geoXml = new geoXML3.parser({ 
map:_this.map, zoom:options.kmlrezoom });
+                                       var geoXml = new geoXML3.parser({
+                                               map:_this.map,
+                                               zoom:options.kmlrezoom,
+                                               failedParse:function(){
+                                                       
alert(mediaWiki.msg('maps-kml-parsing-failed'));
+                                               }
+                                       });
+                                       geoXml.options.afterParse = 
function(docs){
+                                               //add toggle functionality
+                                               var toggleDiv = 
document.createElement('div');
+                                               toggleDiv.style.backgroundColor 
= 'white';
+                                               toggleDiv.style.marginTop = 
'5px';
+                                               toggleDiv.style.padding = '5px';
+                                               toggleDiv.style.border = '1px 
solid grey';
+                                               for(var i = docs.length-1; i >= 
0; i--){
+                                                       (function(doc){
+                                                               var label = 
document.createElement('label');
+                                                               
label.style.display = 'block';
+                                                               var text = 
document.createTextNode(doc.baseUrl.substring(doc.baseDir.length));
+                                                               var checkbox = 
document.createElement('input');
+                                                               
checkbox.setAttribute('type','checkbox');
+                                                               
checkbox.style.verticalAlign = '-0.2em';
+                                                               
checkbox.checked = true;
+                                                               
checkbox.onclick = function(){
+                                                                       
if(this.checked){
+                                                                               
geoXml.showDocument(doc);
+                                                                       }else{
+                                                                               
geoXml.hideDocument(doc);
+                                                                       }
+                                                               };
+                                                               
label.appendChild(checkbox);
+                                                               
label.appendChild(text);
+
+                                                               
toggleDiv.appendChild(label);
+
+                                                               
console.log(toggleDiv);
+                                                       })(docs[i]);
+                                               }
+                                               
_this.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleDiv);
+                                       };
+
                                        geoXml.parse(options.kml);
                                });
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/75839
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iade1c305e70d9aa98c3927f52794a5009056ad88
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Maps
Gerrit-Branch: master
Gerrit-Owner: Netbrain <[email protected]>

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

Reply via email to