Changeset 8012
- Timestamp:
- 09/12/08 12:24:20 (2 years ago)
- Files:
-
- branches/openlayers/2.7/build/license.txt (modified) (1 diff)
- branches/openlayers/2.7/examples/animator.js (copied) (copied from trunk/openlayers/examples/animator.js)
- branches/openlayers/2.7/examples/measure.html (modified) (3 diffs)
- branches/openlayers/2.7/examples/protocol-gears.html (copied) (copied from trunk/openlayers/examples/protocol-gears.html)
- branches/openlayers/2.7/examples/proxy.cgi (modified) (2 diffs)
- branches/openlayers/2.7/examples/spherical-mercator.html (modified) (4 diffs)
- branches/openlayers/2.7/examples/strategy-bbox.html (copied) (copied from trunk/openlayers/examples/strategy-bbox.html)
- branches/openlayers/2.7/examples/strategy-cluster.html (copied) (copied from trunk/openlayers/examples/strategy-cluster.html)
- branches/openlayers/2.7/examples/strategy-paging.html (copied) (copied from trunk/openlayers/examples/strategy-paging.html)
- branches/openlayers/2.7/examples/vector-formats.html (modified) (4 diffs)
- branches/openlayers/2.7/examples/wfs-reprojection.html (modified) (2 diffs)
- branches/openlayers/2.7/lib/Gears (copied) (copied from trunk/openlayers/lib/Gears)
- branches/openlayers/2.7/lib/Gears/gears_init.js (copied) (copied from trunk/openlayers/lib/Gears/gears_init.js)
- branches/openlayers/2.7/lib/OpenLayers.js (modified) (4 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Control/Permalink.js (modified) (3 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Format.js (modified) (2 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Format/GML (copied) (copied from trunk/openlayers/lib/OpenLayers/Format/GML)
- branches/openlayers/2.7/lib/OpenLayers/Format/GML/Base.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Format/GML/Base.js)
- branches/openlayers/2.7/lib/OpenLayers/Format/GML/v2.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Format/GML/v2.js)
- branches/openlayers/2.7/lib/OpenLayers/Format/GML/v3.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Format/GML/v3.js)
- branches/openlayers/2.7/lib/OpenLayers/Format/XML.js (modified) (4 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Layer/TMS.js (modified) (1 diff)
- branches/openlayers/2.7/lib/OpenLayers/Layer/Vector.js (modified) (8 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Map.js (modified) (1 diff)
- branches/openlayers/2.7/lib/OpenLayers/Protocol/HTTP.js (modified) (2 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Protocol/SQL (copied) (copied from trunk/openlayers/lib/OpenLayers/Protocol/SQL)
- branches/openlayers/2.7/lib/OpenLayers/Protocol/SQL.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Protocol/SQL.js)
- branches/openlayers/2.7/lib/OpenLayers/Protocol/SQL/Gears.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Protocol/SQL/Gears.js)
- branches/openlayers/2.7/lib/OpenLayers/Renderer/Elements.js (modified) (1 diff)
- branches/openlayers/2.7/lib/OpenLayers/Renderer/SVG.js (modified) (1 diff)
- branches/openlayers/2.7/lib/OpenLayers/Renderer/VML.js (modified) (10 diffs)
- branches/openlayers/2.7/lib/OpenLayers/Request.js (modified) (1 diff)
- branches/openlayers/2.7/lib/OpenLayers/Strategy/BBOX.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Strategy/BBOX.js)
- branches/openlayers/2.7/lib/OpenLayers/Strategy/Cluster.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Strategy/Cluster.js)
- branches/openlayers/2.7/lib/OpenLayers/Strategy/Paging.js (copied) (copied from trunk/openlayers/lib/OpenLayers/Strategy/Paging.js)
- branches/openlayers/2.7/lib/OpenLayers/Util.js (modified) (2 diffs)
- branches/openlayers/2.7/tests/Control/Permalink.html (modified) (1 diff)
- branches/openlayers/2.7/tests/Format.html (modified) (2 diffs)
- branches/openlayers/2.7/tests/Format/GML (copied) (copied from trunk/openlayers/tests/Format/GML)
- branches/openlayers/2.7/tests/Format/GML/cases.js (copied) (copied from trunk/openlayers/tests/Format/GML/cases.js)
- branches/openlayers/2.7/tests/Format/GML/v2.html (copied) (copied from trunk/openlayers/tests/Format/GML/v2.html)
- branches/openlayers/2.7/tests/Format/GML/v3.html (copied) (copied from trunk/openlayers/tests/Format/GML/v3.html)
- branches/openlayers/2.7/tests/Format/XML.html (modified) (3 diffs)
- branches/openlayers/2.7/tests/Protocol/HTTP.html (modified) (4 diffs)
- branches/openlayers/2.7/tests/Protocol/SQL (copied) (copied from trunk/openlayers/tests/Protocol/SQL)
- branches/openlayers/2.7/tests/Protocol/SQL.html (copied) (copied from trunk/openlayers/tests/Protocol/SQL.html)
- branches/openlayers/2.7/tests/Protocol/SQL/Gears.html (copied) (copied from trunk/openlayers/tests/Protocol/SQL/Gears.html)
- branches/openlayers/2.7/tests/Renderer/Elements.html (modified) (1 diff)
- branches/openlayers/2.7/tests/Request.html (modified) (2 diffs)
- branches/openlayers/2.7/tests/Strategy/BBOX.html (copied) (copied from trunk/openlayers/tests/Strategy/BBOX.html)
- branches/openlayers/2.7/tests/Strategy/Cluster.html (copied) (copied from trunk/openlayers/tests/Strategy/Cluster.html)
- branches/openlayers/2.7/tests/Strategy/Paging.html (copied) (copied from trunk/openlayers/tests/Strategy/Paging.html)
- branches/openlayers/2.7/tests/geom_eq.js (copied) (copied from trunk/openlayers/tests/geom_eq.js)
- branches/openlayers/2.7/tests/list-tests.html (modified) (3 diffs)
- branches/openlayers/2.7/tests/run-tests.html (modified) (1 diff)
- branches/openlayers/2.7/tests/xml_eq.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/openlayers/2.7/build/license.txt
r7335 r8012 53 53 * http://www.apache.org/licenses/LICENSE-2.0 54 54 */ 55 56 /** 57 * Contains portions of Gears <http://code.google.com/apis/gears/> 58 * 59 * Copyright 2007, Google Inc. 60 * 61 * Redistribution and use in source and binary forms, with or without 62 * modification, are permitted provided that the following conditions are met: 63 * 64 * 1. Redistributions of source code must retain the above copyright notice, 65 * this list of conditions and the following disclaimer. 66 * 2. Redistributions in binary form must reproduce the above copyright notice, 67 * this list of conditions and the following disclaimer in the documentation 68 * and/or other materials provided with the distribution. 69 * 3. Neither the name of Google Inc. nor the names of its contributors may be 70 * used to endorse or promote products derived from this software without 71 * specific prior written permission. 72 * 73 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 74 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 75 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 76 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 77 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 78 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 79 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 80 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 81 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 82 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 83 * 84 * Sets up google.gears.*, which is *the only* supported way to access Gears. 85 * 86 * Circumvent this file at your own risk! 87 * 88 * In the future, Gears may automatically define google.gears.* without this 89 * file. Gears may use these objects to transparently fix bugs and compatibility 90 * issues. Applications that use the code below will continue to work seamlessly 91 * when that happens. 92 */ branches/openlayers/2.7/examples/measure.html
r7965 r8012 93 93 document.getElementById('noneToggle').checked = true; 94 94 } 95 96 function calcVincenty(geometry) { 97 /** 98 * Note: this function assumes geographic coordinates and 99 * will fail otherwise. OpenLayers.Util.distVincenty takes 100 * two objects representing points with geographic coordinates 101 * and returns the geodesic distance between them (shortest 102 * distance between the two points on an ellipsoid) in *kilometers*. 103 * 104 * It is important to realize that the segments drawn on the map 105 * are *not* geodesics (or "great circle" segments). This means 106 * that in general, the measure returned by this function 107 * will not represent the length of segments drawn on the map. 108 */ 109 var dist = 0; 110 for (var i = 1; i < geometry.components.length; i++) { 111 var first = geometry.components[i-1]; 112 var second = geometry.components[i]; 113 dist += OpenLayers.Util.distVincenty( 114 {lon: first.x, lat: first.y}, 115 {lon: second.x, lat: second.y} 116 ); 117 } 118 return dist; 119 } 95 120 96 121 function handleMeasurements(event) { … … 103 128 if(order == 1) { 104 129 out += "measure: " + measure.toFixed(3) + " " + units; 130 if (map.getProjection() == "EPSG:4326") { 131 out += "<br /> Great Circle Distance: " + 132 calcVincenty(geometry).toFixed(3) + " km *"; 133 } 105 134 } else { 106 135 out += "measure: " + measure.toFixed(3) + " " + units + "<sup>2</" + "sup>"; … … 145 174 </li> 146 175 </ul> 176 <p>* Note that the geometries drawn are planar geometries and the 177 metrics returned by the measure control are planar measures. The 178 "great circle" distance does not necessarily represent the length 179 of the segments drawn on the map. Instead, it is a geodesic metric that 180 represents the cumulative shortest path between all vertices in the 181 geometry were they projected onto a sphere.</p> 147 182 </div> 148 183 </body> branches/openlayers/2.7/examples/proxy.cgi
r7134 r8012 19 19 'labs.metacarta.com', 'world.freemap.in', 20 20 'prototype.openmnnd.org', 'geo.openplans.org', 21 'sigma.openplans.org' 21 'sigma.openplans.org', 22 22 'www.openstreetmap.org'] 23 23 … … 41 41 print "Content-Type: text/plain" 42 42 print 43 print "This proxy does not allow you to access that location ."44 print 43 print "This proxy does not allow you to access that location (%s)." % (host,) 44 print 45 45 print os.environ 46 46 branches/openlayers/2.7/examples/spherical-mercator.html
r7676 r8012 29 29 displayProjection: new OpenLayers.Projection("EPSG:4326"), 30 30 units: "m", 31 numZoomLevels: 18, 31 32 maxResolution: 156543.0339, 32 33 maxExtent: new OpenLayers.Bounds(-20037508, -20037508, … … 87 88 } 88 89 ); 89 // create O SM layer90 var mapnik= new OpenLayers.Layer.TMS(90 // create OAM layer 91 var oam = new OpenLayers.Layer.TMS( 91 92 "OpenAerialMap", 92 93 "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/", … … 97 98 98 99 // create OSM layer 100 var mapnik = new OpenLayers.Layer.TMS( 101 "OpenStreetMap (Mapnik)", 102 "http://a.tile.openstreetmap.org/", 103 { 104 type: 'png', getURL: osm_getTileURL, 105 displayOutsideMaxExtent: true, 106 attribution: '<a href="http://www.openstreetmap.org/">OpenStreetMap</a>' 107 } 108 ); 109 // create OSM layer 99 110 var osmarender = new OpenLayers.Layer.TMS( 100 111 "OpenStreetMap (Tiles@Home)", 101 "http://tah.openstreetmap.org/Tiles/tile .php/",112 "http://tah.openstreetmap.org/Tiles/tile/", 102 113 { 103 114 type: 'png', getURL: osm_getTileURL, … … 123 134 124 135 map.addLayers([gmap, gsat, ghyb, veroad, veaer, vehyb, 125 yahoo, yahoosat, yahoohyb, mapnik, osmarender,136 yahoo, yahoosat, yahoohyb, oam, mapnik, osmarender, 126 137 wms, vector]); 127 138 map.addControl(new OpenLayers.Control.LayerSwitcher()); branches/openlayers/2.7/examples/vector-formats.html
r7095 r8012 53 53 'internalProjection': map.baseLayer.projection, 54 54 'externalProjection': new OpenLayers.Projection(OpenLayers.Util.getElement("inproj").value) 55 } 55 }; 56 56 var out_options = { 57 57 'internalProjection': map.baseLayer.projection, 58 58 'externalProjection': new OpenLayers.Projection(OpenLayers.Util.getElement("outproj").value) 59 } 59 }; 60 var gmlOptions = { 61 featureType: "feature", 62 featureNS: "http://example.com/feature" 63 }; 64 var gmlOptionsIn = OpenLayers.Util.extend( 65 OpenLayers.Util.extend({}, gmlOptions), 66 in_options 67 ); 68 var gmlOptionsOut = OpenLayers.Util.extend( 69 OpenLayers.Util.extend({}, gmlOptions), 70 out_options 71 ); 60 72 formats = { 61 73 'in': { … … 63 75 geojson: new OpenLayers.Format.GeoJSON(in_options), 64 76 georss: new OpenLayers.Format.GeoRSS(in_options), 65 gml: new OpenLayers.Format.GML(in_options), 77 gml2: new OpenLayers.Format.GML.v2(gmlOptionsIn), 78 gml3: new OpenLayers.Format.GML.v3(gmlOptionsIn), 66 79 kml: new OpenLayers.Format.KML(in_options) 67 80 }, … … 70 83 geojson: new OpenLayers.Format.GeoJSON(out_options), 71 84 georss: new OpenLayers.Format.GeoRSS(out_options), 72 gml: new OpenLayers.Format.GML(out_options), 85 gml2: new OpenLayers.Format.GML.v2(gmlOptionsOut), 86 gml3: new OpenLayers.Format.GML.v3(gmlOptionsOut), 73 87 kml: new OpenLayers.Format.KML(out_options) 74 88 } … … 170 184 <option value="kml">KML</option> 171 185 <option value="georss">GeoRSS</option> 172 <option value="gml">GML</option> 186 <option value="gml2">GML (v2)</option> 187 <option value="gml3">GML (v3)</option> 173 188 <option value="wkt">Well-Known Text (WKT)</option> 174 189 </select> branches/openlayers/2.7/examples/wfs-reprojection.html
r7884 r8012 46 46 var wfs = layer = new OpenLayers.Layer.WFS( 47 47 "States (SVG)", 48 "http://sigma.openplans.org :8080/geoserver/ows",48 "http://sigma.openplans.org/geoserver/ows", 49 49 {typename: 'topp:states'}, 50 50 { … … 61 61 var wfs = layer = new OpenLayers.Layer.WFS( 62 62 "States (Canvas)", 63 "http://sigma.openplans.org :8080/geoserver/ows",63 "http://sigma.openplans.org/geoserver/ows", 64 64 {typename: 'topp:states'}, 65 65 { branches/openlayers/2.7/lib/OpenLayers.js
r7952 r8012 84 84 "Rico/Corner.js", 85 85 "Rico/Color.js", 86 "Gears/gears_init.js", 86 87 "OpenLayers/Ajax.js", 87 88 "OpenLayers/Request.js", … … 165 166 "OpenLayers/Control/SelectFeature.js", 166 167 "OpenLayers/Control/NavigationHistory.js", 168 "OpenLayers/Control/Measure.js", 167 169 "OpenLayers/Geometry.js", 168 170 "OpenLayers/Geometry/Rectangle.js", … … 185 187 "OpenLayers/Strategy.js", 186 188 "OpenLayers/Strategy/Fixed.js", 189 "OpenLayers/Strategy/Cluster.js", 190 "OpenLayers/Strategy/Paging.js", 191 "OpenLayers/Strategy/BBOX.js", 187 192 "OpenLayers/Protocol.js", 188 193 "OpenLayers/Protocol/HTTP.js", 194 "OpenLayers/Protocol/SQL.js", 195 "OpenLayers/Protocol/SQL/Gears.js", 189 196 "OpenLayers/Layer/PointTrack.js", 190 197 "OpenLayers/Layer/GML.js", … … 200 207 "OpenLayers/Format/XML.js", 201 208 "OpenLayers/Format/GML.js", 209 "OpenLayers/Format/GML/Base.js", 210 "OpenLayers/Format/GML/v2.js", 211 "OpenLayers/Format/GML/v3.js", 202 212 "OpenLayers/Format/KML.js", 203 213 "OpenLayers/Format/GeoRSS.js", branches/openlayers/2.7/lib/OpenLayers/Control/Permalink.js
r7881 r8012 169 169 createParams: function(center, zoom, layers) { 170 170 center = center || this.map.getCenter(); 171 zoom = zoom || this.map.getZoom();172 layers = layers || this.map.layers;173 171 174 172 var params = OpenLayers.Util.getParameters(this.base); … … 178 176 // base link. 179 177 if (center) { 180 181 params.zoom = this.map.getZoom(); 178 179 //zoom 180 params.zoom = zoom || this.map.getZoom(); 181 182 //lon,lat 182 183 var lat = center.lat; 183 184 var lon = center.lon; … … 193 194 params.lat = Math.round(lat*100000)/100000; 194 195 params.lon = Math.round(lon*100000)/100000; 195 196 197 //layers 198 layers = layers || this.map.layers; 196 199 params.layers = ''; 197 for (var i=0, len= this.map.layers.length; i<len; i++) {198 var layer = this.map.layers[i];200 for (var i=0, len=layers.length; i<len; i++) { 201 var layer = layers[i]; 199 202 200 203 if (layer.isBaseLayer) { branches/openlayers/2.7/lib/OpenLayers/Format.js
r7675 r8012 13 13 */ 14 14 OpenLayers.Format = OpenLayers.Class({ 15 16 /** 17 * Property: options 18 * {Object} A reference to options passed to the constructor. 19 */ 20 options: null, 15 21 16 22 /** … … 55 61 initialize: function(options) { 56 62 OpenLayers.Util.extend(this, options); 63 this.options = options; 64 }, 65 66 /** 67 * APIMethod: destroy 68 * Clean up. 69 */ 70 destroy: function() { 57 71 }, 58 72 branches/openlayers/2.7/lib/OpenLayers/Format/XML.js
r7870 r8012 21 21 22 22 /** 23 * Property: namespaces 24 * {Object} Mapping of namespace aliases to namespace URIs. Properties 25 * of this object should not be set individually. Read-only. All 26 * XML subclasses should have their own namespaces object. Use 27 * <setNamespace> to add or set a namespace alias after construction. 28 */ 29 namespaces: null, 30 31 /** 32 * Property: namespaceAlias 33 * {Object} Mapping of namespace URI to namespace alias. This object 34 * is read-only. Use <setNamespace> to add or set a namespace alias. 35 */ 36 namespaceAlias: null, 37 38 /** 39 * Property: defaultPrefix 40 * {String} The default namespace alias for creating element nodes. 41 */ 42 defaultPrefix: null, 43 44 /** 45 * Property: readers 46 * Contains public functions, grouped by namespace prefix, that will 47 * be applied when a namespaced node is found matching the function 48 * name. The function will be applied in the scope of this parser 49 * with two arguments: the node being read and a context object passed 50 * from the parent. 51 */ 52 readers: {}, 53 54 /** 55 * Property: writers 56 * As a compliment to the <readers> property, this structure contains public 57 * writing functions grouped by namespace alias and named like the 58 * node names they produce. 59 */ 60 writers: {}, 61 62 /** 23 63 * Property: xmldom 24 64 * {XMLDom} If this browser uses ActiveX, this will be set to a XMLDOM … … 45 85 } 46 86 OpenLayers.Format.prototype.initialize.apply(this, [options]); 87 // clone the namespace object and set all namespace aliases 88 this.namespaces = OpenLayers.Util.extend({}, this.namespaces); 89 this.namespaceAlias = {}; 90 for(var alias in this.namespaces) { 91 this.namespaceAlias[this.namespaces[alias]] = alias; 92 } 93 }, 94 95 /** 96 * APIMethod: destroy 97 * Clean up. 98 */ 99 destroy: function() { 100 this.xmldom = null; 101 OpenLayers.Format.prototype.destroy.apply(this, arguments); 102 }, 103 104 /** 105 * Method: setNamespace 106 * Set a namespace alias and URI for the format. 107 * 108 * Parameters: 109 * alias - {String} The namespace alias (prefix). 110 * uri - {String} The namespace URI. 111 */ 112 setNamespace: function(alias, uri) { 113 this.namespaces[alias] = uri; 114 this.namespaceAlias[uri] = alias; 47 115 }, 48 116 … … 290 358 */ 291 359 getChildValue: function(node, def) { 292 var value; 293 if (node && node.firstChild && node.firstChild.nodeValue) { 294 value = node.firstChild.nodeValue; 295 } else { 296 value = (def != undefined) ? def : ""; 360 var value = def || ""; 361 if(node) { 362 var child = node.firstChild; 363 if(child) { 364 value = child.nodeValue || value; 365 } 297 366 } 298 367 return value; … … 385 454 }, 386 455 456 /** 457 * Method: createElementNSPlus 458 * Shorthand for creating namespaced elements with optional attributes and 459 * child text nodes. 460 * 461 * Parameters: 462 * name - {String} The qualified node name. 463 * options - {Object} Optional object for node configuration. 464 * 465 * Valid options: 466 * uri - {String} Optional namespace uri for the element - supply a prefix 467 * instead if the namespace uri is a property of the format's namespace 468 * object. 469 * attributes - {Object} Optional attributes to be set using the 470 * <setAttributes> method. 471 * value - {String} Optional text to be appended as a text node. 472 * 473 * Returns: 474 * {Element} An element node. 475 */ 476 createElementNSPlus: function(name, options) { 477 options = options || {}; 478 var loc = name.indexOf(":"); 479 // order of prefix preference 480 // 1. in the uri option 481 // 2. in the prefix option 482 // 3. in the qualified name 483 // 4. from the defaultPrefix 484 var uri = options.uri || this.namespaces[options.prefix]; 485 if(!uri) { 486 loc = name.indexOf(":"); 487 uri = this.namespaces[name.substring(0, loc)]; 488 } 489 if(!uri) { 490 uri = this.namespaces[this.defaultPrefix]; 491 } 492 var node = this.createElementNS(uri, name); 493 if(options.attributes) { 494 this.setAttributes(node, options.attributes); 495 } 496 if(options.value) { 497 node.appendChild(this.createTextNode(options.value)); 498 } 499 return node; 500 }, 501 502 /** 503 * Method: setAttributes 504 * Set multiple attributes given key value pairs from an object. 505 * 506 * Parameters: 507 * node - {Element} An element node. 508 * obj - {Object || Array} An object whose properties represent attribute 509 * names and values represent attribute values. If an attribute name 510 * is a qualified name ("prefix:local"), the prefix will be looked up 511 * in the parsers {namespaces} object. If the prefix is found, 512 * setAttributeNS will be used instead of setAttribute. 513 */ 514 setAttributes: function(node, obj) { 515 var value, loc, alias, uri; 516 for(var name in obj) { 517 if(obj[name] != null && obj[name].toString) { 518 value = obj[name].toString(); 519 // check for qualified attribute name ("prefix:local") 520 uri = this.namespaces[name.substring(0, name.indexOf(":"))] || null; 521 this.setAttributeNS(node, uri, name, value); 522 } 523 } 524 }, 525 526 /** 527 * Method: readNode 528 * Shorthand for applying one of the named readers given the node 529 * namespace and local name. Readers take two args (node, obj) and 530 * generally extend or modify the second. 531 * 532 * Parameters: 533 * node - {DOMElement} The node to be read (required). 534 * obj - {Object} The object to be modified (optional). 535 * 536 * Returns: 537 * {Object} The input object, modified (or a new one if none was provided). 538 */ 539 readNode: function(node, obj) { 540 if(!obj) { 541 obj = {}; 542 } 543 var group = this.readers[this.namespaceAlias[node.namespaceURI]]; 544 if(group) { 545 var local = node.localName || node.nodeName.split(":").pop(); 546 var reader = group[local] || group["*"]; 547 if(reader) { 548 reader.apply(this, [node, obj]); 549 } 550 } 551 return obj; 552 }, 553 554 /** 555 * Method: readChildNodes 556 * Shorthand for applying the named readers to all children of a node. 557 * For each child of type 1 (element), <readSelf> is called. 558 * 559 * Parameters: 560 * node - {DOMElement} The node to be read (required). 561 * obj - {Object} The object to be modified (optional). 562 * 563 * Returns: 564 * {Object} The input object, modified. 565 */ 566 readChildNodes: function(node, obj) { 567 if(!obj) { 568 obj = {}; 569 } 570 var children = node.childNodes; 571 var child; 572 for(var i=0, len=children.length; i<len; ++i) { 573 child = children[i]; 574 if(child.nodeType == 1) { 575 this.readNode(child, obj); 576 } 577 } 578 return obj; 579 }, 580 581 /** 582 * Method: writeNode 583 * Shorthand for applying one of the named writers and appending the 584 * results to a node. If a qualified name is not provided for the 585 * second argument (and a local name is used instead), the namespace 586 * of the parent node will be assumed. 587 * 588 * Parameters: 589 * name - {String} The name of a node to generate. If a qualified name 590 * (e.g. "pre:Name") is used, the namespace prefix is assumed to be 591 * in the <writers> group. If a local name is used (e.g. "Name") then 592 * the namespace of the parent is assumed. If a local name is used 593 * and no parent is supplied, then the default namespace is assumed. 594 * obj - {Object} Structure containing data for the writer. 595 * parent - {DOMElement} Result will be appended to this node. If no parent 596 * is supplied, the node will not be appended to anything. 597 * 598 * Returns: 599 * {DOMElement} The child node. 600 */ 601 writeNode: function(name, obj, parent) { 602 var prefix, local; 603 var split = name.indexOf(":"); 604 if(split > 0) { 605 prefix = name.substring(0, split); 606 local = name.substring(split + 1); 607 } else { 608 if(parent) { 609 prefix = this.namespaceAlias[parent.namespaceURI]; 610 } else { 611 prefix = this.defaultPrefix; 612 } 613 local = name; 614 } 615 var child = this.writers[prefix][local].apply(this, [obj]); 616 if(parent) { 617 parent.appendChild(child); 618 } 619 return child; 620 }, 621 387 622 CLASS_NAME: "OpenLayers.Format.XML" 388 623 branches/openlayers/2.7/lib/OpenLayers/Layer/TMS.js
r6418 r8012 6 6 /** 7 7 * @requires OpenLayers/Layer/Grid.js 8 * @requires OpenLayers/Tile/Image.js 8 9 */ 9 10 branches/openlayers/2.7/lib/OpenLayers/Layer/Vector.js
r7959 r8012 39 39 * - *beforefeatureadded* Triggered before a feature is added. Listeners 40 40 * will receive an object with a *feature* property referencing the 41 * feature to be added. 41 * feature to be added. To stop the feature from being added, a 42 * listener should return false. 43 * - *beforefeaturesadded* Triggered before an array of features is added. 44 * Listeners will receive an object with a *features* property 45 * referencing the feature to be added. To stop the features from 46 * being added, a listener should return false. 42 47 * - *featureadded* Triggered after a feature is added. The event 43 48 * object passed to listeners will have a *feature* property with a … … 73 78 * for a new set of features. 74 79 */ 75 EVENT_TYPES: ["beforefeatureadded", "featureadded", "featuresadded", 80 EVENT_TYPES: ["beforefeatureadded", "beforefeaturesadded", 81 "featureadded", "featuresadded", 76 82 "beforefeatureremoved", "featureremoved", "featuresremoved", 77 83 "beforefeatureselected", "featureselected", "featureunselected", … … 408 414 409 415 if(!zoomChanged && coordSysUnchanged) { 410 var unrenderedFeatures = {};411 416 for(var i in this.unrenderedFeatures) { 412 417 var feature = this.unrenderedFeatures[i]; 413 if(!this.drawFeature(feature)) { 414 unrenderedFeatures[i] = feature; 415 } 418 this.drawFeature(feature); 416 419 } 417 this.unrenderedFeatures = unrenderedFeatures;418 420 } 419 421 } 420 422 421 423 if (!this.drawn || zoomChanged || !coordSysUnchanged) { 422 this.unrenderedFeatures = {};423 424 this.drawn = true; 424 425 var feature; … … 430 431 } 431 432 feature = this.features[i]; 432 if (!this.drawFeature(feature)) { 433 this.unrenderedFeatures[feature.id] = feature; 434 }; 433 this.drawFeature(feature); 435 434 } 436 435 } … … 451 450 452 451 var notify = !options || !options.silent; 452 if(notify) { 453 var event = {features: features}; 454 var ret = this.events.triggerEvent("beforefeaturesadded", event); 455 if(ret === false) { 456 return; 457 } 458 features = event.features; 459 } 460 453 461 454 462 for (var i=0, len=features.length; i<len; i++) { … … 477 485 478 486 if (notify) { 479 this.events.triggerEvent("beforefeatureadded", { 480 feature: feature 481 }); 487 if(this.events.triggerEvent("beforefeatureadded", 488 {feature: feature}) === false) { 489 continue; 490 }; 482 491 this.preFeatureInsert(feature); 483 492 } 484 493 485 494 if (this.drawn) { 486 if(!this.drawFeature(feature)) { 487 this.unrenderedFeatures[feature.id] = feature; 488 } 495 this.drawFeature(feature); 489 496 } 490 497 … … 604 611 * feature - {<OpenLayers.Feature.Vector>} 605 612 * style - {Object} Symbolizer hash or {String} renderIntent 606 *607 * Returns:608 * {Boolean} true if the renderer was able to draw the feature, false609 * otherwise610 613 */ 611 614 drawFeature: function(feature, style) { … … 619 622 } 620 623 621 return this.renderer.drawFeature(feature, style); 624 if (!this.renderer.drawFeature(feature, style)) { 625 this.unrenderedFeatures[feature.id] = feature; 626 } else { 627 delete this.unrenderedFeatures[feature.id]; 628 }; 622 629 }, 623 630 branches/openlayers/2.7/lib/OpenLayers/Map.js
r7889 r8012 168 168 /** 169 169 * Property: controls 170 * {Array(<OpenLayers.Control>)} List of controls associated with the map 170 * {Array(<OpenLayers.Control>)} List of controls associated with the map. 171 * 172 * If not provided in the map options at construction, the map will 173 * be given the following controls by default: 174 * - <OpenLayers.Control.Navigation> 175 * - <OpenLayers.Control.PanZoom> 176 * - <OpenLayers.Control.ArgParser> 177 * - <OpenLayers.Control.Attribution> 171 178 */ 172 179 controls: null, branches/openlayers/2.7/lib/OpenLayers/Protocol/HTTP.js
r7960 r8012 113 113 * This object is modified and should not be reused. 114 114 * 115 * Valid options: 116 * url - {String} Url for the request. 117 * params - {Object} Parameters to get serialized as a query string. 118 * headers - {Object} Headers to be set on the request. 119 * filter - {<OpenLayers.Filter.BBOX>} If a bbox filter is sent, it will be 120 * serialized according to the OpenSearch Geo extension 121 * (bbox=minx,miny,maxx,maxy). Note that a BBOX filter as the child 122 * of a logical filter will not be serialized. 123 * 115 124 * Returns: 116 125 * {<OpenLayers.Protocol.Response>} A response object, whose "priv" property … … 122 131 options = OpenLayers.Util.applyDefaults(options, this.options); 123 132 var resp = new OpenLayers.Protocol.Response({requestType: "read"}); 133 134 if(options.filter && options.filter instanceof OpenLayers.Filter.Spatial) { 135 if(options.filter.type == OpenLayers.Filter.Spatial.BBOX) { 136 options.params = OpenLayers.Util.extend(options.params, { 137 bbox: options.filter.value.toArray() 138 }); 139 } 140 } 124 141 125 142 resp.priv = OpenLayers.Request.GET({ branches/openlayers/2.7/lib/OpenLayers/Renderer/Elements.js
r7953 r8012 811 811 if (this.indexer) { 812 812 this.indexer.remove(element); 813 813 } 814 815 if (element._style.backgroundGraphic) { 814 816 var backgroundId = geometry.id + this.BACKGROUND_ID_SUFFIX; 815 817 var bElem = OpenLayers.Util.getElement(backgroundId); branches/openlayers/2.7/lib/OpenLayers/Renderer/SVG.js
r7930 r8012 154 154 * 155 155 * Returns: 156 * {Boolean} true if the translation parameters ar in the valid coordinates156 * {Boolean} true if the translation parameters are in the valid coordinates 157 157 * range, false otherwise. 158 158 */ branches/openlayers/2.7/lib/OpenLayers/Renderer/VML.js
r7975 r8012 35 35 36 36 /** 37 * Property: offset 38 * {Object} Hash with "x" and "y" properties 39 */ 40 offset: null, 41 42 /** 37 43 * Constructor: OpenLayers.Renderer.VML 38 44 * Create a new VML renderer. … … 51 57 "position: absolute; display: inline-block;"); 52 58 } 59 53 60 OpenLayers.Renderer.Elements.prototype.initialize.apply(this, 54 61 arguments); 62 this.offset = {x: 0, y: 0}; 55 63 }, 56 64 … … 91 99 var resolution = this.getResolution(); 92 100 93 var org = extent.left/resolution + " " + 94 (extent.top/resolution - this.size.h); 101 var left = extent.left/resolution; 102 var top = extent.top/resolution - this.size.h; 103 if (resolutionChanged) { 104 this.offset = {x: left, y: top}; 105 left = 0; 106 top = 0; 107 } else { 108 left = left - this.offset.x; 109 top = top - this.offset.y; 110 } 111 112 var org = left + " " + top; 95 113 this.root.setAttribute("coordorigin", org); 96 114 … … 192 210 style.graphicYOffset : -(0.5 * height); 193 211 194 node.style.left = ((geometry.x/resolution )+xOffset).toFixed();195 node.style.top = ((geometry.y/resolution )-(yOffset+height)).toFixed();212 node.style.left = ((geometry.x/resolution - this.offset.x)+xOffset).toFixed(); 213 node.style.top = ((geometry.y/resolution - this.offset.y)-(yOffset+height)).toFixed(); 196 214 node.style.width = width + "px"; 197 215 node.style.height = height + "px"; … … 449 467 450 468 var scaledBox = 451 new OpenLayers.Bounds((bbox.left/resolution ).toFixed(),452 (bbox.bottom/resolution ).toFixed(),453 (bbox.right/resolution ).toFixed(),454 (bbox.top/resolution ).toFixed());469 new OpenLayers.Bounds((bbox.left/resolution - this.offset.x).toFixed(), 470 (bbox.bottom/resolution - this.offset.y).toFixed(), 471 (bbox.right/resolution - this.offset.x).toFixed(), 472 (bbox.top/resolution - this.offset.y).toFixed()); 455 473 456 474 // Set the internal coordinate system to draw the path … … 614 632 if(!isNaN(geometry.x)&& !isNaN(geometry.y)) { 615 633 var resolution = this.getResolution(); 616 617 node.style.left = ((geometry.x /resolution ).toFixed() - radius) + "px";618 node.style.top = ((geometry.y /resolution ).toFixed() - radius) + "px";634 635 node.style.left = ((geometry.x /resolution - this.offset.x).toFixed() - radius) + "px"; 636 node.style.top = ((geometry.y /resolution - this.offset.y).toFixed() - radius) + "px"; 619 637 620 638 var diameter = radius * 2; … … 681 699 for (var i = 0; i < numComponents; i++) { 682 700 comp = geometry.components[i]; 683 x = (comp.x/resolution );684 y = (comp.y/resolution );701 x = (comp.x/resolution - this.offset.x); 702 y = (comp.y/resolution - this.offset.y); 685 703 parts[i] = " " + x.toFixed() + "," + y.toFixed() + " l "; 686 704 } … … 714 732 for (i=0, ilen=linearRing.components.length; i<ilen; i++) { 715 733 comp = linearRing.components[i]; 716 x = comp.x / resolution ;717 y = comp.y / resolution ;734 x = comp.x / resolution - this.offset.x; 735 y = comp.y / resolution - this.offset.y; 718 736 path.push(" " + x.toFixed() + "," + y.toFixed()); 719 737 if (i==0) { … … 742 760 var resolution = this.getResolution(); 743 761 744 node.style.left = geometry.x/resolution+ "px";745 node.style.top = geometry.y/resolution+ "px";762 node.style.left = (geometry.x/resolution - this.offset.x) + "px"; 763 node.style.top = (geometry.y/resolution - this.offset.y) + "px"; 746 764 node.style.width = geometry.width/resolution + "px"; 747 765 node.style.height = geometry.height/resolution + "px"; … … 770 788 for (var i=0, len=geometry.components.length; i<len; i++) { 771 789 comp = geometry.components[i]; 772 x = comp.x / resolution ;773 y = comp.y / resolution ;790 x = comp.x / resolution - this.offset.x; 791 y = comp.y / resolution - this.offset.y; 774 792 if ((i%3)==0 && (i/3)==0) { 775 793 path.push("m"); branches/openlayers/2.7/lib/OpenLayers/Request.js
r7975 r8012 88 88 var url = config.url; 89 89 if(config.params) { 90 url += "?" + OpenLayers.Util.getParameterString(config.params); 90 var paramString = OpenLayers.Util.getParameterString(config.params); 91 if(paramString.length > 0) { 92 var separator = (url.indexOf('?') > -1) ? '&' : '?'; 93 url += separator + paramString; 94 } 91 95 } 92 96 if(config.proxy && (url.indexOf("http") == 0)) { branches/openlayers/2.7/lib/OpenLayers/Util.js
r7975 r8012 797 797 /** 798 798 * Function: distVincenty 799 * Given two objects representing points with geographic coordinates, this 800 * calculates the distance between those points on the surface of an 801 * ellipsoid. 799 802 * 800 803 * Parameters: … … 803 806 * 804 807 * Returns: 805 * {Float} 808 * {Float} The distance (in km) between the two input points as measured on an 809 * ellipsoid. Note that the input point objects must be in geographic 810 * coordinates (decimal degrees) and the return distance is in kilometers. 806 811 */ 807 812 OpenLayers.Util.distVincenty=function(p1, p2) { branches/openlayers/2.7/tests/Control/Permalink.html
r7881 r8012 135 135 t.eq(control.div.firstChild.getAttribute("href"), "./edit.html?zoom=2&lat=0&lon=1.75781&layers=B&customParam=foo", "Custom parameter encoded correctly."); 136 136 } 137 138 function test_Control_Permalink_createParams(t) { 139 t.plan(18); 140 141 var baseLayer = { 'isBaseLayer': true }; 142 143 var m = { 144 'getCenter': function() { return null; } 145 }; 146 147 var pl = { 148 'map': m, 149 'base': {} 150 }; 151 152 old_getParameters = OpenLayers.Util.getParameters; 153 OpenLayers.Util.getParameters = function(base) { 154 t.ok(base == pl.base, "correct base sent in to Util.getParameters()"); 155 return g_Params; 156 }; 157 158 //null center, null map.getCenter() 159 g_Params = {}; 160 m.baseLayer = baseLayer; 161 var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, []); 162 t.ok(returnParams == g_Params, "correct params returned on null center"); 163 164 //valid center, zoom, layers 165 g_Params = { 'test': {} }; 166 var center = { 'lon': 1.2345678901, 'lat': 9.8765432109 }; 167 var zoom = {}; 168 var layers = [ 169 { 'isBaseLayer': true }, 170 baseLayer, 171 { 'isBaseLayer': false, 'getVisibility': function() { return true; } }, 172 { 'isBaseLayer': false, 'getVisibility': function() { return false; } } 173 ]; 174 var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]); 175 176 t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when valid center, zoom, layers"); 177 t.ok(returnParams.zoom == zoom, "params.zoom set correctly when valid center, zoom, layers"); 178 t.eq(returnParams.lon, 1.23457, "lon set and rounded correctly when valid center, zoom, layers"); 179 t.eq(returnParams.lat, 9.87654, "lat set and rounded correctly when valid center, zoom, layers"); 180 t.eq(returnParams.layers, "0BTF", "layers processed correctly when valid center, zoom, layers") 181 182 183 //null center, zoom, layers, with displayProjection 184 g_Params = { 'test': {} }; 185 g_Projection = {}; 186 m = { 187 'baseLayer': baseLayer, 188 'getProjectionObject': function() { return g_Projection; }, 189 'center': { 'lon': {}, 'lat': {} }, 190 'getCenter': function() { return this.center; }, 191 'zoom': {}, 192 'getZoom': function() { return this.zoom; }, 193 'layers': [ 194 { 'isBaseLayer': false, 'getVisibility': function() { return true; } }, 195 baseLayer, 196 { 'isBaseLayer': false, 'getVisibility': function() { return false; } }, 197 { 'isBaseLayer': true } 198 ], 199 'getLayers': function() { return this.layers; } 200 }; 201 pl = { 202 'base': {}, 203 'map': m, 204 'displayProjection': {} 205 }; 206 207 old_transform = OpenLayers.Projection.transform; 208 OpenLayers.Projection.transform = function(point, projObj, dispProj) { 209 t.ok(point.x = m.center.lon, "correct x value passed into transform"); 210 t.ok(point.y = m.center.lat, "correct x value passed into transform"); 211 t.ok(projObj == g_Projection, "correct projection object from map passed into transform"); 212 t.ok(dispProj == pl.displayProjection, "correct displayProjection from control passed into transform"); 213 214 return { 'x': 9.8765432109, 'y': 1.2345678901 }; 215 }; 216 217 center = zoom = layers = null; 218 219 var returnParams = OpenLayers.Control.Permalink.prototype.createParams.apply(pl, [center, zoom, layers]); 220 t.ok(returnParams.test == g_Params.test, "correct params returned from Util.getParameters() when null center, zoom, layers, with displayProjection"); 221 t.ok(returnParams.zoom == m.zoom, "params.zoom set correctly when null center, zoom, layers, with displayProjection"); 222 t.eq(returnParams.lon, 9.87654, "lon set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection"); 223 t.eq(returnParams.lat, 1.23457, "lat set, transformed, and rounded correctly when null center, zoom, layers, with displayProjection"); 224 t.eq(returnParams.layers, "TBF0", "layers processed correctly when null center, zoom, layers, with displayProjection"); 225 226 OpenLayers.Util.getParameters = old_getParameters; 227 OpenLayers.Projection.transform = old_transform; 228 } 229 137 230 </script> 138 231 </head> branches/openlayers/2.7/tests/Format.html
r6724 r8012 5 5 6 6 function test_Format_constructor(t) { 7 t.plan( 4);7 t.plan(5); 8 8 9 9 var options = {'foo': 'bar'}; … … 14 14 t.eq(typeof format.read, "function", "format has a read function"); 15 15 t.eq(typeof format.write, "function", "format has a write function"); 16 t.eq(format.options, options, "format.options correctly set"); 16 17 } 17 18 branches/openlayers/2.7/tests/Format/XML.html
r6719 r8012 28 28 29 29 function test_Format_XML_constructor(t) { 30 t.plan( 5);30 t.plan(13); 31 31 32 32 var options = {'foo': 'bar'}; … … 39 39 40 40 t.ok(!window.ActiveXObject || format.xmldom, "browsers with activeX must have xmldom"); 41 42 // test namespaces 43 t.ok(format.namespaces instanceof Object, "format has namespace object"); 44 var namespaces = {"foo": "bar"}; 45 format = new OpenLayers.Format.XML({namespaces: namespaces}); 46 t.eq(format.namespaces, namespaces, "format.namespaces correctly set in constructor"); 47 48 // test default prefix 49 t.eq(format.defaultPrefix, null, "defaultPrefix is null by default"); 50 format = new OpenLayers.Format.XML({defaultPrefix: "foo"}); 51 t.eq(format.defaultPrefix, "foo", "defaultPrefix correctly set in constructor"); 52 53 // test readers 54 t.ok(format.readers instanceof Object, "format has readers object"); 55 var readers = {"foo": "bar"}; 56 format = new OpenLayers.Format.XML({readers: readers}); 57 t.eq(format.readers, readers, "format.readers correctly set in constructor"); 58 59 // test readers 60 t.ok(format.writers instanceof Object, "format has writers object"); 61 var writers = {"foo": "bar"}; 62 format = new OpenLayers.Format.XML({writers: writers}); 63 t.eq(format.writers, writers, "format.writers correctly set in constructor"); 64 } 65 66 function test_destroy(t) { 67 t.plan(1); 68 var format = new OpenLayers.Format.XML(); 69 format.destroy(); 70 t.eq(format.xmldom, null, "xmldom set to null for all browsers"); 41 71 } 42 72 … … 261 291 t.ok(found === false, "returns false for bad attribute"); 262 292 } 293 294 function test_namespaces(t) { 295 t.plan(2); 296 297 var format = new OpenLayers.Format.XML({ 298 namespaces: { 299 "def": "http://example.com/default", 300 "foo": "http://example.com/foo", 301 "bar": "http://example.com/bar" 302 }, 303 defaultPrefix: "def" 304 }); 305 306 // test that prototype has not been altered 307 t.eq(OpenLayers.Format.XML.prototype.namespaces, null, 308 "setting namespaces at construction does not modify prototype"); 309 310 // test that namespaceAlias has been set 311 t.eq(format.namespaceAlias["http://example.com/foo"], "foo", 312 "namespaceAlias mapping has been set"); 313 314 } 315 316 function test_setNamespace(t) { 317 t.plan(3); 318 319 var format = new OpenLayers.Format.XML(); 320 321 // test that namespaces is an object 322 t.ok(format.namespaces instanceof Object, "empty namespace object set"); 323 324 format.setNamespace("foo", "http://example.com/foo"); 325 t.eq(format.namespaces["foo"], "http://example.com/foo", "alias -> uri mapping set"); 326 t.eq(format.namespaceAlias["http://example.com/foo"], "foo", "uri -> alias mapping set"); 327 328 } 329 330 function test_readChildNodes(t) { 331 332 var text = "<?xml version='1.0' encoding='UTF-8'?>" + 333 "<container xmlns='http://example.com/foo'>" + 334 "<marker name='my marker 1'>" + 335 "<position>" + 336 "<lon>-180</lon>" + 337 "<lat>90</lat>" + 338 "</position>" + 339 "<detail>some text for first marker</detail>" + 340 "<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/1'/>" + 341 "</marker>" + 342 "<marker name='my marker 2'>" + 343 "<position>" + 344 "<lon>180</lon>" + 345 "<lat>-90</lat>" + 346 "</position>" + 347 "<detail>some text for second marker</detail>" + 348 "<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/2'/>" + 349 "</marker>" + 350 "</container>"; 351 352 var expect = [ 353 new OpenLayers.Feature.Vector( 354 new OpenLayers.Geometry.Point(-180, 90), 355 { 356 name: 'my marker 1', 357 link: 'http://host/path/1', 358 detail: 'some text for first marker' 359 } 360 ), 361 new OpenLayers.Feature.Vector( 362 new OpenLayers.Geometry.Point(180, -90), 363 { 364 name: 'my marker 2', 365 link: 'http://host/path/2', 366 detail: 'some text for second marker' 367 } 368 ) 369 ]; 370 371 var format = new OpenLayers.Format.XML({ 372 defaultPrefix: "foo", 373 namespaces: { 374 "foo": "http://example.com/foo", 375 "atom": "http://www.w3.org/2005/Atom" 376 }, 377 readers: { 378 "foo": { 379 "container": function(node, obj) { 380 var list = []; 381 this.readChildNodes(node, list); 382 obj.list = list; 383 }, 384 "marker": function(node, list) { 385 var feature = new OpenLayers.Feature.Vector(); 386 feature.attributes.name = node.getAttribute("name"); 387 this.readChildNodes(node, feature); 388 list.push(feature); 389 }, 390 "position": function(node, feature) { 391 var obj = {}; 392 this.readChildNodes(node, obj); 393 feature.geometry = new OpenLayers.Geometry.Point(obj.x, obj.y); 394 }, 395 "lon": function(node, obj) { 396 obj.x = this.getChildValue(node); 397 }, 398 "lat": function(node, obj) { 399 obj.y = this.getChildValue(node); 400 }, 401 "detail": function(node, feature) { 402 feature.attributes.detail = this.getChildValue(node); 403 } 404 }, 405 "atom": { 406 "link": function(node, feature) { 407 feature.attributes.link = node.getAttribute("href"); 408 } 409 } 410 } 411 }); 412 413 // convert text to document node 414 var doc = format.read(text); 415 // read child nodes to get back some object 416 var obj = format.readChildNodes(doc); 417 // start comparing what we got to what we expect 418 var got = obj.list; 419 420 t.plan(11); 421 t.eq(got.length, expect.length, "correct number of items parsed"); 422 t.eq(got[0].geometry.x, expect[0].geometry.x, "correct x coord parsed for marker 1"); 423 t.eq(got[0].geometry.y, expect[0].geometry.y, "correct y coord parsed for marker 1"); 424 t.eq(got[0].attributes.name, expect[0].attributes.name, "correct name parsed for marker 1"); 425 t.eq(got[0].attributes.detail, expect[0].attributes.detail, "correct detail parsed for marker 1"); 426 t.eq(got[0].attributes.link, expect[0].attributes.link, "correct link parsed for marker 1"); 427 t.eq(got[1].geometry.x, expect[1].geometry.x, "correct x coord parsed for marker 2"); 428 t.eq(got[1].geometry.y, expect[1].geometry.y, "correct y coord parsed for marker 2"); 429 t.eq(got[1].attributes.name, expect[1].attributes.name, "correct name parsed for marker 2"); 430 t.eq(got[1].attributes.detail, expect[1].attributes.detail, "correct detail parsed for marker 2"); 431 t.eq(got[1].attributes.link, expect[1].attributes.link, "correct link parsed for marker 2"); 432 433 } 434 435 function test_writeNode(t) { 436 437 var features = [ 438 new OpenLayers.Feature.Vector( 439 new OpenLayers.Geometry.Point(-180, 90), 440 { 441 name: 'my marker 1', 442 link: 'http://host/path/1', 443 detail: 'some text for first marker' 444 } 445 ), 446 new OpenLayers.Feature.Vector( 447 new OpenLayers.Geometry.Point(180, -90), 448 { 449 name: 'my marker 2', 450 link: 'http://host/path/2', 451 detail: 'some text for second marker' 452 } 453 ) 454 ]; 455 456 var expect = "<?xml version='1.0' encoding='UTF-8'?>" + 457 "<container xmlns='http://example.com/foo'>" + 458 "<marker name='my marker 1'>" + 459 "<position>" + 460 "<lon>-180</lon>" + 461 "<lat>90</lat>" + 462 "</position>" + 463 "<detail>some text for first marker</detail>" + 464 "<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/1'/>" + 465 "</marker>" + 466 "<marker name='my marker 2'>" + 467 "<position>" + 468 "<lon>180</lon>" + 469 "<lat>-90</lat>" + 470 "</position>" + 471 "<detail>some text for second marker</detail>" + 472 "<atom:link xmlns:atom='http://www.w3.org/2005/Atom' href='http://host/path/2'/>" + 473 "</marker>" + 474 "</container>"; 475 476 var format = new OpenLayers.Format.XML({ 477 defaultPrefix: "foo", 478 namespaces: { 479 "foo": "http://example.com/foo", 480 "atom": "http://www.w3.org/2005/Atom" 481 }, 482 writers: { 483 "foo": { 484 "container": function(features) { 485 var node = this.createElementNSPlus("container"); 486 var feature; 487 for(var i=0; i<features.length; ++i) { 488 feature = features[i]; 489 this.writeNode("marker", features[i], node); 490 } 491 return node; 492 }, 493 "marker": function(feature) { 494 var node = this.createElementNSPlus("marker", { 495 attributes: {name: feature.attributes.name} 496 }); 497 this.writeNode("position", feature.geometry, node); 498 this.writeNode("detail", feature.attributes.detail, node); 499 this.writeNode("atom:link", feature.attributes.link, node); 500 return node; 501 }, 502 "position": function(geometry) { 503 var node = this.createElementNSPlus("position"); 504 this.writeNode("lon", geometry.x, node); 505 this.writeNode("lat", geometry.y, node); 506 return node; 507 }, 508 "lon": function(x) { 509 return this.createElementNSPlus("lon", { 510 value: x 511 }); 512 }, 513 "lat": function(y) { 514 return this.createElementNSPlus("lat", { 515 value: y 516 }); 517 }, 518 "detail": function(text) { 519 return this.createElementNSPlus("detail", { 520 value: text 521 }); 522 } 523 }, 524 "atom": { 525 "link": function(href) { 526 return this.createElementNSPlus("atom:link", { 527 attributes: {href: href} 528 }); 529 } 530 } 531 } 532 533 }); 534 535 t.plan(1); 536 // test that we get what we expect from writeNode 537 var got = format.writeNode("container", features); 538 t.xml_eq(got, expect, "features correctly written"); 539 } 540 541 function test_createElementNSPlus(t) { 542 543 var format = new OpenLayers.Format.XML({ 544 defaultPrefix: "def", 545 namespaces: { 546 "def": "http://example.com/default", 547 "foo": "http://example.com/foo", 548 "bar": "http://example.com/bar" 549 } 550 }); 551 552 var cases = [ 553 { 554 description: "unprefixed name with default options", 555 node: format.createElementNSPlus("FooNode"), 556 expect: "<def:FooNode xmlns:def='http://example.com/default'/>" 557 }, { 558 description: "def prefixed name with default options", 559 node: format.createElementNSPlus("def:FooNode"), 560 expect: "<def:FooNode xmlns:def='http://example.com/default'/>" 561 }, { 562 description: "foo prefixed name with default options", 563 node: format.createElementNSPlus("foo:FooNode"), 564 expect: "<foo:FooNode xmlns:foo='http://example.com/foo'/>" 565 }, { 566 description: "unprefixed name with uri option", 567 node: format.createElementNSPlus("FooNode", { 568 uri: "http://example.com/elsewhere" 569 }), 570 expect: "<FooNode xmlns='http://example.com/elsewhere'/>" 571 }, { 572 description: "foo prefixed name with uri option (overriding format.namespaces)", 573 node: format.createElementNSPlus("foo:FooNode", { 574 uri: "http://example.com/elsewhere" 575 }), 576 expect: "<foo:FooNode xmlns:foo='http://example.com/elsewhere'/>" 577 }, { 578 description: "foo prefixed name with attributes option", 579 node: format.createElementNSPlus("foo:FooNode", { 580 attributes: { 581 "id": "123", 582 "foo:attr1": "namespaced attribute 1", 583 "bar:attr2": "namespaced attribute 2" 584 } 585 }), 586 expect: "<foo:FooNode xmlns:foo='http://example.com/foo' xmlns:bar='http://example.com/bar' id='123' foo:attr1='namespaced attribute 1' bar:attr2='namespaced attribute 2'/>" 587 }, { 588 description: "foo prefixed name with attributes and value options", 589 node: format.createElementNSPlus("foo:FooNode", { 590 attributes: {"id": "123"}, 591 value: "text value" 592 }), 593 expect: "<foo:FooNode xmlns:foo='http://example.com/foo' id='123'>text value<" + "/foo:FooNode>" 594 } 595 ]; 596 597 t.plan(cases.length); 598 var test; 599 for(var i=0; i<cases.length; ++i) { 600 test = cases[i]; 601 t.xml_eq(test.node, test.expect, test.description); 602 } 603 604 } 605 606 function test_setAttributes(t) { 607 608 var format = new OpenLayers.Format.XML({ 609 defaultPrefix: "def", 610 namespaces: { 611 "def": "http://example.com/default", 612 "foo": "http://example.com/foo", 613 "bar": "http://example.com/bar" 614 } 615 }); 616 617 var cases = [ 618 { 619 description: "unprefixed attribute", 620 node: format.createElementNSPlus("foo:Node"), 621 attributes: {"id": "123"}, 622 expect: "<foo:Node xmlns:foo='http://example.com/foo' id='123'/>" 623 }, { 624 description: "foo prefixed attribute", 625 node: format.createElementNSPlus("foo:Node"), 626 attributes: {"foo:id": "123"}, 627 expect: "<foo:Node xmlns:foo='http://example.com/foo' foo:id='123'/>" 628 }, { 629 description: "foo prefixed attribute with def prefixed node", 630 node: format.createElementNSPlus("def:Node"), 631 attributes: {"foo:id": "123"}, 632 expect: "<def:Node xmlns:def='http://example.com/default' xmlns:foo='http://example.com/foo' foo:id='123'/>" 633 }, { 634 description: "multiple attributes", 635 node: format.createElementNSPlus("def:Node"), 636 attributes: {"id": "123", "foo": "bar"}, 637 expect: "<def:Node xmlns:def='http://example.com/default' id='123' foo='bar'/>" 638 } 639 ]; 640 641 t.plan(cases.length); 642 var test; 643 for(var i=0; i<cases.length; ++i) { 644 test = cases[i]; 645 format.setAttributes(test.node, test.attributes); 646 t.xml_eq(test.node, test.expect, test.description); 647 } 648 649 } 263 650 264 651 </script> branches/openlayers/2.7/tests/Protocol/HTTP.html
r7940 r8012 103 103 104 104 var resp = protocol.read(readOptions); 105 106 OpenLayers.Request.GET = _get; 107 } 108 109 function test_read_bbox(t) { 110 t.plan(1); 111 var protocol = new OpenLayers.Protocol.HTTP(); 112 113 // fake XHR request object 114 var request = {'status': 200}; 115 116 var _get = OpenLayers.Request.GET; 117 118 var bounds = new OpenLayers.Bounds(1, 2, 3, 4); 119 var filter = new OpenLayers.Filter.Spatial({ 120 type: OpenLayers.Filter.Spatial.BBOX, 121 value: bounds, 122 projection: "foo" 123 }); 124 125 OpenLayers.Request.GET = function(options) { 126 t.eq(options.params['bbox'].toString(), bounds.toArray().toString(), 127 'GET called with bbox filter in params'); 128 return request; 129 }; 130 131 var resp = protocol.read({filter: filter}); 132 133 OpenLayers.Request.GET = _get; 105 134 } 106 135 … … 218 247 219 248 var resp = protocol.create(features, createOptions); 249 250 OpenLayers.Request.POST = _post; 220 251 } 221 252 … … 285 316 286 317 var resp = protocol.update(feature, updateOptions); 287 288 } 318 319 OpenLayers.Request.PUT = _put; 320 } 321 289 322 function test_handleResponse(t) { 290 323 t.plan(6); … … 405 438 var resp = protocol['delete'](feature, deleteOptions); 406 439 440 OpenLayers.Request.DELETE = _delete; 407 441 } 408 442 branches/openlayers/2.7/tests/Renderer/Elements.html
r7954 r8012 429 429 gElemRemoved = elem; 430 430 } 431 } 431 }, 432 '_style' : {backgroundGraphic: "foo"} 432 433 }; 433 434 gBackElement = { branches/openlayers/2.7/tests/Request.html
r7609 r8012 21 21 setup(); 22 22 23 t.plan( 19);23 t.plan(22); 24 24 var request, config; 25 25 var proto = OpenLayers.Request.XMLHttpRequest.prototype; … … 47 47 t.eq(user, config.user, "open called with correct user"); 48 48 t.eq(password, config.password, "open called with correct password"); 49 } 50 request = issue(config); 49 }; 50 request = issue(config); 51 52 // test that params are serialized as query string - 1 test 53 config = { 54 method: "GET", 55 url: "http://example.com/", 56 params: {"foo": "bar"} 57 }; 58 proto.open = function(method, url, async, user, password) { 59 t.eq(url, config.url + "?foo=bar", "params serialized as query string"); 60 }; 61 request = issue(config); 62 63 // test that empty params object doesn't produce query string - 1 test 64 config = { 65 method: "GET", 66 url: "http://example.com/", 67 params: {} 68 }; 69 proto.open = function(method, url, async, user, password) { 70 t.eq(url, config.url, "empty params doesn't produce query string"); 71 } 72 request = issue(config); 73 74 // test that query string doesn't get two ? separators 75 config = { 76 method: "GET", 77 url: "http://example.com/?existing=query", 78 params: {"foo": "bar"} 79 }; 80 proto.open = function(method, url, async, user, password) { 81 t.eq(url, config.url + "&foo=bar", "existing query string gets extended with &"); 82 } 83 request = issue(config); 84 85 // reset open method 51 86 proto.open = _open; 52 87 branches/openlayers/2.7/tests/list-tests.html
r7952 r8012 44 44 <li>Format/GeoRSS.html</li> 45 45 <li>Format/GML.html</li> 46 <li>Format/GML/v2.html</li> 47 <li>Format/GML/v3.html</li> 46 48 <li>Format/GPX.html</li> 47 49 <li>Format/JSON.html</li> … … 116 118 <li>Protocol.html</li> 117 119 <li>Protocol/HTTP.html</li> 120 <li>Protocol/SQL.html</li> 121 <li>Protocol/SQL/Gears.html</li> 118 122 <li>Renderer.html</li> 119 123 <li>Renderer/Canvas.html</li> … … 125 129 <li>Rule.html</li> 126 130 <li>Strategy.html</li> 131 <li>Strategy/Cluster.html</li> 127 132 <li>Strategy/Fixed.html</li> 133 <li>Strategy/Paging.html</li> 134 <li>Strategy/BBOX.html</li> 128 135 <li>Style.html</li> 129 136 <li>StyleMap.html</li> branches/openlayers/2.7/tests/run-tests.html
r7665 r8012 2308 2308 </script> 2309 2309 <script type="text/javascript" src="xml_eq.js"></script> 2310 <script type="text/javascript" src="geom_eq.js"></script> 2310 2311 </head><body> 2311 2312 branches/openlayers/2.7/tests/xml_eq.js
r7321 r8012 98 98 * got - {DOMElement} 99 99 * expected - {DOMElement} 100 * options - {Object} Optional object for configuring test options. Set 101 * 'prefix' property to true in order to compare element and attribute 102 * prefixes (namespace uri always tested). By default, prefixes 103 * are not tested. 100 * options - {Object} Optional object for configuring test options. 101 * 102 * Valid options: 103 * prefix - {Boolean} Compare element and attribute 104 * prefixes (namespace uri always tested). Default is false. 105 * includeWhiteSpace - {Boolean} Include whitespace only nodes when 106 * comparing child nodes. Default is false. 104 107 */ 105 108 function assertElementNodesEqual(got, expected, options) { … … 191 194 192 195 // compare children 196 var gotChildNodes = getChildNodes(got, options); 197 var expChildNodes = getChildNodes(expected, options); 198 193 199 assertEqual( 194 got .childNodes.length, expected.childNodes.length,200 gotChildNodes.length, expChildNodes.length, 195 201 "Children length mismatch for " + got.nodeName 196 202 ); 197 for(var j=0; j<got .childNodes.length; ++j) {203 for(var j=0; j<gotChildNodes.length; ++j) { 198 204 try { 199 205 assertElementNodesEqual( 200 got .childNodes[j], expected.childNodes[j]206 gotChildNodes[j], expChildNodes[j], options 201 207 ); 202 208 } catch(err) { … … 207 213 return true; 208 214 } 215 216 /** 217 * Function getChildNodes 218 * Returns the child nodes of the specified nodes. By default this method 219 * will ignore child text nodes which are made up of whitespace content. 220 * The 'includeWhiteSpace' option is used to control this behaviour. 221 * 222 * Parameters: 223 * node - {DOMElement} 224 * options - {Object} Optional object for test configuration. 225 * 226 * Valid options: 227 * includeWhiteSpace - {Boolean} Include whitespace only nodes when 228 * comparing child nodes. Default is false. 229 * 230 * Returns: 231 * {Array} of {DOMElement} 232 */ 233 function getChildNodes(node, options) { 234 //check whitespace 235 if (options && options.includeWhiteSpace) { 236 return node.childNodes; 237 } 238 else { 239 nodes = []; 240 for (var i = 0; i < node.childNodes.length; i++ ) { 241 var child = node.childNodes[i]; 242 if (child.nodeType == 1) { 243 //element node, add it 244 nodes.push(child); 245 } 246 else if (child.nodeType == 3) { 247 //text node, add if non empty 248 if (child.nodeValue && 249 child.nodeValue.replace(/^\s*(.*?)\s*$/, "$1") != "" ) { 250 251 nodes.push(child); 252 } 253 } 254 } 255 256 return nodes; 257 } 258 } 209 259 210 260 /** … … 222 272 * expected - {DOMElement | String} The expected DOM node or XML string. 223 273 * msg - {String} A message to print with test output. 224 * options - {Object} Optional object for configuring test options. Set 225 * 'prefix' property to true in order to compare element and attribute 226 * prefixes (namespace uri always tested). By default, prefixes 227 * are not tested. 274 * options - {Object} Optional object for configuring test. 275 * 276 * Valid options: 277 * prefix - {Boolean} Compare element and attribute 278 * prefixes (namespace uri always tested). Default is false. 279 * includeWhiteSpace - {Boolean} Include whitespace only nodes when 280 * comparing child nodes. Default is false. 228 281 */ 229 282 var proto = Test.AnotherWay._test_object_t.prototype;
