OpenLayers OpenLayers

Changeset 4432

Show
Ignore:
Timestamp:
09/21/07 09:32:42 (1 year ago)
Author:
crschmidt
Message:

Pullup changes for RC3:

  • KML Examples broken (Closes #1001)
  • drag handler doesn't reset properties on left or improperly modified mousedown (Closes #1003)
  • Text nodes limited to 4096 in length (Closes #1006)
  • KML/GML Attribute CDATA Parsing (Closes #1007)
  • Control.MousePosition (Closes #1008)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/openlayers/2.5/examples/kml-layer.html

    r4222 r4432  
    2020                    "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 
    2121            map.addLayer(layer); 
    22             map.addLayer(new OpenLayers.Layer.GML("KML", "kml/mc-search.kml", {format: OpenLayers.Format.KML})); 
    23             map.zoomToMaxExtent(); 
     22            map.addLayer(new OpenLayers.Layer.GML("KML", "kml/lines.kml", {format: OpenLayers.Format.KML})); 
     23            map.zoomToExtent(new OpenLayers.Bounds(-112.306698,36.017792,-112.03204,36.18087)); 
    2424        } 
    2525    </script> 
  • branches/openlayers/2.5/lib/OpenLayers/Control/MousePosition.js

    r4234 r4432  
    6363 
    6464    /** 
     65     * Method: destroy 
     66     */ 
     67     destroy: function() { 
     68         if (this.map) { 
     69             this.map.events.unregister('mousemove', this, this.redraw); 
     70         } 
     71         OpenLayers.Control.prototype.destroy.apply(this, arguments); 
     72     }, 
     73 
     74    /** 
    6575     * Method: draw 
    6676     * {DOMElement} 
  • branches/openlayers/2.5/lib/OpenLayers/Format/GML.js

    r4390 r4432  
    296296            nodeList = this.getElementsByTagNameNS(node, this.gmlns, "posList"); 
    297297            if(nodeList.length > 0) { 
    298                 coordString = nodeList[0].firstChild.nodeValue
     298                coordString = this.concatChildValues(nodeList[0])
    299299                coordString = coordString.replace(this.regExes.trimSpace, ""); 
    300300                coords = coordString.split(this.regExes.splitSpace); 
     
    315315                                                       "coordinates"); 
    316316                if(nodeList.length > 0) { 
    317                     coordString = nodeList[0].firstChild.nodeValue
     317                    coordString = this.concatChildValues(nodeList[0])
    318318                    coordString = coordString.replace(this.regExes.trimSpace, 
    319319                                                      ""); 
     
    454454                        if(grandchildren.length == 1) { 
    455455                            grandchild = grandchildren[0]; 
    456                             if(grandchild.nodeType == 3) { 
     456                            if(grandchild.nodeType == 3 || 
     457                               grandchild.nodeType == 4) { 
    457458                                name = (child.prefix) ? 
    458459                                        child.nodeName.split(":")[1] : 
  • branches/openlayers/2.5/lib/OpenLayers/Format/KML.js

    r4390 r4432  
    327327                if(grandchildren.length == 1) { 
    328328                    grandchild = grandchildren[0]; 
    329                     if(grandchild.nodeType == 3) { 
     329                    if(grandchild.nodeType == 3 || grandchild.nodeType == 4) { 
    330330                        name = (child.prefix) ? 
    331331                                child.nodeName.split(":")[1] : 
  • branches/openlayers/2.5/lib/OpenLayers/Format/XML.js

    r4302 r4432  
    257257        return attributeValue; 
    258258    }, 
     259     
     260    /** 
     261     * APIMethod: getChildValue 
     262     * Get the value of the first child node if it exists, or return an 
     263     *     optional default string.  Returns an empty string if no first child 
     264     *     exists and no default value is supplied. 
     265     * 
     266     * Parameters: 
     267     * node - {DOMElement} The element used to look for a first child value. 
     268     * def - {String} Optional string to return in the event that no 
     269     *     first child value exists. 
     270     * 
     271     * Returns: 
     272     * {String} The value of the first child of the given node. 
     273     */ 
     274    getChildValue: function(node, def) { 
     275        var value; 
     276        try { 
     277            value = node.firstChild.nodeValue; 
     278        } catch(e) { 
     279            value = (def != undefined) ? def : ""; 
     280        } 
     281        return value; 
     282    }, 
     283 
     284    /** 
     285     * APIMethod: concatChildValues 
     286     * Concatenate the value of all child nodes if any exist, or return an 
     287     *     optional default string.  Returns an empty string if no children 
     288     *     exist and no default value is supplied.  Not optimized for large 
     289     *     numbers of child nodes. 
     290     * 
     291     * Parameters: 
     292     * node - {DOMElement} The element used to look for child values. 
     293     * def - {String} Optional string to return in the event that no 
     294     *     child exist. 
     295     * 
     296     * Returns: 
     297     * {String} The concatenated value of all child nodes of the given node. 
     298     */ 
     299    concatChildValues: function(node, def) { 
     300        var value = ""; 
     301        var child = node.firstChild; 
     302        var childValue; 
     303        while(child) { 
     304            childValue = child.nodeValue; 
     305            if(childValue) { 
     306                value += childValue; 
     307            } 
     308            child = child.nextSibling; 
     309        } 
     310        if(value == "" && def != undefined) { 
     311            value = def; 
     312        } 
     313        return value; 
     314    }, 
    259315 
    260316    /** 
  • branches/openlayers/2.5/lib/OpenLayers/Handler/Drag.js

    r4390 r4432  
    144144     */ 
    145145    mousedown: function (evt) { 
     146        var propagate = true; 
     147        this.dragging = false; 
    146148        if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 
    147149            this.started = true; 
    148             this.dragging = false; 
    149150            this.start = evt.xy; 
    150151            this.last = evt.xy; 
     
    160161            } 
    161162             
    162             return false; 
    163         } 
    164         return true; 
     163            propagate = false; 
     164        } else { 
     165            this.started = false; 
     166            this.start = null; 
     167            this.last = null; 
     168        } 
     169        return propagate; 
    165170    }, 
    166171 
  • branches/openlayers/2.5/tests/Format/test_GML.html

    r4206 r4432  
    148148    } 
    149149    function test_Format_GML_read_attributes(t) { 
    150         t.plan(1); 
     150        t.plan(2); 
    151151        var parser = new OpenLayers.Format.GML(); 
    152152        data = parser.read(test_content[0]); 
    153153        t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly."); 
     154        t.eq(data[0].attributes['LONGNAME'], "Wyoming", "Attribute data is read from CDATA node correctly."); 
    154155    }     
    155156 
    156     var test_content = ['<?xml version="1.0" encoding="utf-8" ?>\n<ogr:FeatureCollection\n     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n     xsi:schemaLocation="http://ogr.maptools.org/ testoutput.xsd"\n     xmlns:ogr="http://ogr.maptools.org/"\n     xmlns:gml="http://www.opengis.net/gml">\n  <gml:boundedBy>\n    <gml:Box>\n      <gml:coord><gml:X>-1254041.389711702</gml:X><gml:Y>250906.9515983529</gml:Y></gml:coord>\n      <gml:coord><gml:X>-634517.1199908922</gml:X><gml:Y>762236.2940800377</gml:Y></gml:coord>\n    </gml:Box>\n  </gml:boundedBy>                    \n  <gml:featureMember>\n    <ogr:states fid="F0">\n      <ogr:geometryProperty><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>\n      <ogr:NAME>WY</ogr:NAME>\n    </ogr:states>\n  </gml:featureMember>\n</ogr:FeatureCollection>\n', 
     157    var test_content = ['<?xml version="1.0" encoding="utf-8" ?>\n<ogr:FeatureCollection\n     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n     xsi:schemaLocation="http://ogr.maptools.org/ testoutput.xsd"\n     xmlns:ogr="http://ogr.maptools.org/"\n     xmlns:gml="http://www.opengis.net/gml">\n  <gml:boundedBy>\n    <gml:Box>\n      <gml:coord><gml:X>-1254041.389711702</gml:X><gml:Y>250906.9515983529</gml:Y></gml:coord>\n      <gml:coord><gml:X>-634517.1199908922</gml:X><gml:Y>762236.2940800377</gml:Y></gml:coord>\n    </gml:Box>\n  </gml:boundedBy>                    \n  <gml:featureMember>\n    <ogr:states fid="F0">\n      <ogr:geometryProperty><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>\n      <ogr:NAME>WY</ogr:NAME>\n    <ogr:LONGNAME><![CDATA[Wyoming]]></ogr:LONGNAME>\n    </ogr:states>\n  </gml:featureMember>\n</ogr:FeatureCollection>\n', 
    157158 '<wfs:FeatureCollection' +  
    158159 '   xmlns:fs="http://example.com/featureserver"' +  
  • branches/openlayers/2.5/tests/Format/test_KML.html

    r4219 r4432  
    2929    } 
    3030 
     31    function test_Format_KML_readCdataAttributes(t) { 
     32        t.plan(2); 
     33        var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><name><![CDATA[Pezinok]]></name><description><![CDATA[Full of text.]]></description><styleUrl>#rel1.0</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates></Point></Placemark></Document></kml>'; 
     34        var features = (new OpenLayers.Format.KML()).read(cdata); 
     35        t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly"); 
     36        t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly"); 
     37         
     38    } 
     39     
    3140    function test_Format_KML_write(t) { 
    3241        // make sure id, name, and description are preserved 
  • branches/openlayers/2.5/tests/Handler/test_Drag.html

    r4390 r4432  
    8888 
    8989    function test_Handler_Drag_callbacks(t) { 
    90         t.plan(27); 
     90        t.plan(33); 
    9191         
    9292        var map = new OpenLayers.Map('map', {controls: []}); 
     
    116116        handler.activate(); 
    117117         
    118         // test mousedown 
    119118        var oldIsLeftClick = OpenLayers.Event.isLeftClick; 
    120119        var oldStop = OpenLayers.Event.stop; 
    121120        var oldCheckModifiers = handler.checkModifiers; 
     121 
     122        // test mousedown with right click 
     123        OpenLayers.Event.isLeftClick = function() { 
     124            return false; 
     125        } 
     126        handler.checkModifiers = function() { 
     127            return true; 
     128        } 
     129        handler.started = true; 
     130        handler.start = {x: "foo", y: "bar"}; 
     131        handler.last = {x: "foo", y: "bar"}; 
     132        map.events.triggerEvent("mousedown", testEvents.down); 
     133        t.ok(!handler.started, "right-click sets started to false"); 
     134        t.eq(handler.start, null, "right-click sets start to null"); 
     135        t.eq(handler.last, null, "right-click sets last to null"); 
     136 
     137        // test mousedown with improper modifier 
     138        OpenLayers.Event.isLeftClick = function() { 
     139            return true; 
     140        } 
     141        handler.checkModifiers = function() { 
     142            return false; 
     143        } 
     144        handler.started = true; 
     145        handler.start = {x: "foo", y: "bar"}; 
     146        handler.last = {x: "foo", y: "bar"}; 
     147        map.events.triggerEvent("mousedown", testEvents.down); 
     148        t.ok(!handler.started, "bad modifier sets started to false"); 
     149        t.eq(handler.start, null, "bad modifier sets start to null"); 
     150        t.eq(handler.last, null, "bad modifier sets last to null"); 
     151 
     152        // test mousedown 
    122153        handler.checkModifiers = function(evt) { 
    123154            t.ok(evt.xy.x == testEvents.down.xy.x && 
     
    152183             handler.last.y == testEvents.down.xy.y, 
    153184             "mouse down sets handler.last correctly"); 
     185         
     186        OpenLayers.Event.stop = oldStop;         
    154187        OpenLayers.Event.isLeftClick = oldIsLeftClick; 
    155         OpenLayers.Event.stop = oldStop; 
    156188        handler.checkModifiers = oldCheckModifiers; 
    157189 
  • branches/openlayers/2.5/tests/list-tests.html

    r4272 r4432  
    7272    <li>Control/test_NavToolbar.html</li> 
    7373    <li>Control/test_MouseToolbar.html</li> 
     74    <li>Control/test_MousePosition.html</li> 
    7475    <li>Control/test_LayerSwitcher.html</li> 
    7576    <li>Control/test_Panel.html</li>