[fusion-commits] r2122 - sandbox/adsk/2.2gp/lib/OpenLayers

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue Mar 30 22:31:03 EDT 2010


Author: liuar
Date: 2010-03-30 22:31:02 -0400 (Tue, 30 Mar 2010)
New Revision: 2122

Modified:
   sandbox/adsk/2.2gp/lib/OpenLayers/OpenLayers.js
Log:
Integrate the new version of SVG.js in OpenLayers.js which fixed http://trac.openlayers.org/ticket/2402

Modified: sandbox/adsk/2.2gp/lib/OpenLayers/OpenLayers.js
===================================================================
--- sandbox/adsk/2.2gp/lib/OpenLayers/OpenLayers.js	2010-03-31 02:05:00 UTC (rev 2121)
+++ sandbox/adsk/2.2gp/lib/OpenLayers/OpenLayers.js	2010-03-31 02:31:02 UTC (rev 2122)
@@ -11043,6 +11043,14 @@
     isGecko: null,
 
     /**
+     * Property: supportUse
+     * {Boolean} true if defs/use is supported - known to not work as expected
+     * at least in some applewebkit/5* builds.
+     * See https://bugs.webkit.org/show_bug.cgi?id=33322
+     */
+    supportUse: null,
+
+    /**
      * Constructor: OpenLayers.Renderer.SVG
      * 
      * Parameters:
@@ -11055,6 +11063,7 @@
         OpenLayers.Renderer.Elements.prototype.initialize.apply(this, 
                                                                 arguments);
         this.translationParameters = {x: 0, y: 0};
+        this.supportUse = (navigator.userAgent.toLowerCase().indexOf("applewebkit/5") == -1);
         this.isGecko = (navigator.userAgent.toLowerCase().indexOf("gecko/") != -1);
     },
 
@@ -11198,7 +11207,7 @@
                 if (style.externalGraphic) {
                     nodeType = "image";
                 } else if (this.isComplexSymbol(style.graphicName)) {
-                    nodeType = "use";
+                    nodeType = this.supportUse === false ? "svg" : "use";
                 } else {
                     nodeType = "circle";
                 }
@@ -11278,7 +11287,6 @@
                 var offset = style.pointRadius * 3;
                 var size = offset * 2;
                 var id = this.importSymbol(style.graphicName);
-                var href = "#" + id;
                 pos = this.getPosition(node);
                 widthFactor = this.symbolSize[id] / size;
                 
@@ -11290,7 +11298,17 @@
                     parent.removeChild(node);
                 }
                 
-                node.setAttributeNS(this.xlinkns, "href", href);
+                if(this.supportUse === false) {
+                    // workaround for webkit versions that cannot do defs/use
+                    // (see https://bugs.webkit.org/show_bug.cgi?id=33322):
+                    // copy the symbol instead of referencing it
+                    var src = document.getElementById(id);
+                    node.firstChild && node.removeChild(node.firstChild);
+                    node.appendChild(src.firstChild.cloneNode(true));
+                    node.setAttributeNS(null, "viewBox", src.getAttributeNS(null, "viewBox"));
+                } else {
+                    node.setAttributeNS(this.xlinkns, "href", "#" + id);
+                }
                 node.setAttributeNS(null, "width", size);
                 node.setAttributeNS(null, "height", size);
                 node.setAttributeNS(null, "x", pos.x - offset);
@@ -11308,9 +11326,16 @@
             }
 
             if (typeof style.rotation != "undefined" && pos) {
-                var rotation = OpenLayers.String.format(
-                    "rotate(${0} ${1} ${2})", [style.rotation, pos.x, pos.y]);
-                node.setAttributeNS(null, "transform", rotation);
+                if(node.nodeName !== "svg") {
+                    node.setAttributeNS(null, "transform",
+                        "rotate(" + style.rotation + " " + pos.x + " " +
+                        pos.y + ")");
+                } else {
+                    var symbolCenter = 0.5 * this.symbolSize[id] / 3;
+                    node.firstChild.setAttributeNS(null, "transform",
+                        "rotate(" + style.rotation + " " + symbolCenter +
+                        " " +  symbolCenter + ")");
+                }
             }
         }
         
@@ -11358,8 +11383,8 @@
      */
     dashStyle: function(style, widthFactor) {
         var w = style.strokeWidth * widthFactor;
-
-        switch (style.strokeDashstyle) {
+        var str = style.strokeDashstyle;
+        switch (str) {
             case 'solid':
                 return 'none';
             case 'dot':
@@ -11373,7 +11398,7 @@
             case 'longdashdot':
                 return [8 * w, 4 * w, 1, 4 * w].join();
             default:
-                return style.strokeDashstyle.replace(/ /g, ",");
+                return OpenLayers.String.trim(str).replace(/\s+/g, ",");
         }
     },
     
@@ -11663,7 +11688,6 @@
 
         label.setAttributeNS(null, "x", x);
         label.setAttributeNS(null, "y", -y);
-        label.setAttributeNS(null, "pointer-events", "none");
         
         if (style.fontColor) {
             label.setAttributeNS(null, "fill", style.fontColor);
@@ -11677,6 +11701,15 @@
         if (style.fontWeight) {
             label.setAttributeNS(null, "font-weight", style.fontWeight);
         }
+        if(style.labelSelect === true) {
+            label.setAttributeNS(null, "pointer-events", "visible");
+            label._featureId = featureId;
+            tspan._featureId = featureId;
+            tspan._geometry = location;
+            tspan._geometryClass = location.CLASS_NAME;
+        } else {
+            label.setAttributeNS(null, "pointer-events", "none");
+        }
         var align = style.labelAlign || "cm";
         label.setAttributeNS(null, "text-anchor",
             OpenLayers.Renderer.SVG.LABEL_ALIGN[align[0]] || "middle");
@@ -11888,6 +11921,26 @@
         this.defs.appendChild(symbolNode);
         return symbolNode.id;
     },
+    
+    /**
+     * Method: getFeatureIdFromEvent
+     * 
+     * Parameters:
+     * evt - {Object} An <OpenLayers.Event> object
+     *
+     * Returns:
+     * {<OpenLayers.Geometry>} A geometry from an event that 
+     *     happened on a layer.
+     */
+    getFeatureIdFromEvent: function(evt) {
+        var featureId = OpenLayers.Renderer.Elements.prototype.getFeatureIdFromEvent.apply(this, arguments);
+        if(this.supportUse === false && !featureId) {
+            var target = evt.target;
+            featureId = target.parentNode && target != this.rendererRoot &&
+                target.parentNode._featureId;
+        }
+        return featureId;
+    },
 
     CLASS_NAME: "OpenLayers.Renderer.SVG"
 });



More information about the fusion-commits mailing list