Ticket #1035: projections.2.patch
| File projections.2.patch, 11.0 kB (added by tschaub, 1 year ago) |
|---|
-
tests/Layer/test_WMS.html
old new 236 236 t.eq(str, 237 237 tUrl + "?" + OpenLayers.Util.getParameterString(tParams), 238 238 "getFullRequestString() adds SRS value"); 239 239 240 map.removeLayer(tLayer); 240 241 tLayer.projection = "none"; 242 map.addLayer(tLayer); 241 243 str = tLayer.getFullRequestString(); 242 244 delete tParams['SRS']; 243 245 t.eq(str, -
tests/list-tests.html
old new 87 87 <li>Handler/test_Path.html</li> 88 88 <li>Handler/test_Polygon.html</li> 89 89 <li>Handler/test_RegularPolygon.html</li> 90 <li>test_Projection.html</li> 90 91 <li>test_Map.html</li> 91 92 </ul> -
tests/test_Projection.html
old new 1 <html> 2 <head> 3 <script src="../lib/OpenLayers.js"></script> 4 <script type="text/javascript"> 5 6 function test_01_Projection_constructor(t) { 7 t.plan(7); 8 9 var options = {'foo': 'bar'}; 10 var projection = new OpenLayers.Projection("code", options); 11 t.ok(projection instanceof OpenLayers.Projection, 12 "new OpenLayers.Projection returns object" ); 13 t.eq(projection.projCode, "code", "The proj code is maintained"); 14 t.eq(projection.getCode(), "code", "The proj code is maintained."); 15 t.eq(projection.getUnits(), null, "Null units with no proj4js library."); 16 t.eq(projection.foo, "bar", "constructor sets options correctly"); 17 var projection2 = new OpenLayers.Projection("epsg:4325", options); 18 out = OpenLayers.Projection.transform({'x':10,'y':12}, projection, projection2); 19 t.eq(out.x, 10, "Null transform has no effect"); 20 t.eq(out.y, 12, "Null transform has no effect"); 21 } 22 23 </script> 24 </head> 25 <body> 26 </body> 27 </html> -
lib/OpenLayers/Layer.js
old new 126 126 127 127 /** 128 128 * APIProperty: projection 129 * {String} Set in the layer options to override the default projection 130 * string this layer - also set maxExtent, maxResolution, and units if 131 * appropriate. 129 * {<OpenLayers.Projection>} or {<String>} Set in the layer options to 130 * override the default projection string this layer - also set maxExtent, 131 * maxResolution, and units if appropriate. Can be either a string or 132 * an <OpenLayers.Projection> object when created -- will be converted 133 * to an object when setMap is called if a string is passed. 132 134 */ 133 135 projection: null, 134 136 … … 267 269 if (this.map != null) { 268 270 this.map.removeLayer(this, setNewBaseLayer); 269 271 } 272 this.projection = null; 270 273 this.map = null; 271 274 this.name = null; 272 275 this.div = null; … … 410 413 // been set 411 414 this.maxExtent = this.maxExtent || this.map.maxExtent; 412 415 this.projection = this.projection || this.map.projection; 413 this.units = this.units || this.map.units;414 416 417 if (this.projection && typeof this.projection == "string") { 418 this.projection = new OpenLayers.Projection(this.projection); 419 } 420 421 // Check the projection to see if we can get units -- if not, refer 422 // to properties. 423 this.units = this.projection.getUnits() || 424 this.units || this.map.units; 425 415 426 this.initResolutions(); 416 427 417 428 if (!this.isBaseLayer) { -
lib/OpenLayers/Projection.js
old new 1 /* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license. 2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 3 * for the full text of the license. */ 4 5 /** 6 * @requires OpenLayers/Util.js 7 * 8 * Class: OpenLayers.Projection 9 * Class for coordinate transformations between coordinate systems. 10 * Depends on the proj4js library. If proj4js is not available, 11 * then this is just an empty stub. 12 */ 13 OpenLayers.Projection = OpenLayers.Class({ 14 15 /** 16 * Constructor: OpenLayers.Projection 17 * This class offers several methods for interacting with a wrapped 18 * pro4js projection object. 19 * 20 * Parameters: 21 * options - {Object} An optional object with properties to set on the 22 * format 23 * 24 * Returns: 25 * {<OpenLayers.Projection>} A projection object. 26 */ 27 initialize: function(projCode, options) { 28 OpenLayers.Util.extend(this, options); 29 this.projCode = projCode; 30 if (window.Proj4js) { 31 this.proj = new Proj4js.Proj(projCode); 32 } 33 34 }, 35 36 /** 37 * APIMethod: getCode 38 * Get the string SRS code. 39 * 40 * Returns: 41 * {String} The SRS code. 42 */ 43 getCode: function() { 44 return this.proj ? this.proj.srsCode : this.projCode; 45 }, 46 47 /** 48 * APIMethod: getUnits 49 * Get the units string for the projection -- returns null if 50 * proj4js is not available. 51 * 52 * Returns: 53 * {String} The units abbreviation. 54 */ 55 getUnits: function() { 56 return this.proj ? this.proj.units : null; 57 }, 58 59 /** 60 * Method: toString 61 * Convert projection to string (getCode wrapper). 62 * 63 * Returns: 64 * {String} The projection code. 65 */ 66 toString: function() { 67 return this.getCode(); 68 }, 69 70 /** 71 * Method: equals 72 * Test equality of two projection instances. Determines equality based 73 * soley on the projection code. 74 * 75 * Returns: 76 * {Boolean} The two projections are equivalent. 77 */ 78 equals: function(projection) { 79 if (this.getCode() == projection.getCode()) { 80 return true; 81 } 82 return false; 83 }, 84 85 /* Method: destroy 86 * Destroy projection object. 87 */ 88 destroy: function() { 89 delete this.proj; 90 delete this.projCode; 91 }, 92 93 CLASS_NAME: "OpenLayers.Projection" 94 95 }); 96 97 /** 98 * APIMethod: transform 99 * Read data from a string, and return an object whose type depends on the 100 * subclass. 101 * 102 * Parameters: 103 * point - {object} input horizontal coodinate 104 * sourceProj - {OpenLayers.Projection} source map coordinate system 105 * destProj - {OpenLayers.Projection} destination map coordinate system 106 * 107 * Returns: 108 * point - {object} trasnformed coordinate 109 */ 110 OpenLayers.Projection.transform = function(point, source, dest) { 111 if (source.proj && dest.proj) { 112 point = Proj4js.transform(source.proj, dest.proj, point); 113 } 114 return point; 115 }; -
lib/OpenLayers/Map.js
old new 1250 1250 1251 1251 /** 1252 1252 * APIMethod: getProjection 1253 * This method returns a string representing the projection. In 1254 * the case of projection support, this will be the srsCode which 1255 * is loaded -- otherwise it will simply be the string value that 1256 * was passed to the projection at startup. 1257 * 1258 * FIXME: In 3.0, we will remove getProjectionObject, and instead 1259 * return a Projection object from this function. 1253 1260 * 1254 1261 * Returns: 1255 * {String} The Projection of the base layer.1262 * {String} The Projection string from the base layer or null. 1256 1263 */ 1257 1264 getProjection: function() { 1265 var projection = this.getProjectionObject(); 1266 return projection ? projection.getCode() : null; 1267 }, 1268 1269 /** 1270 * APIMethod: getProjectionObject 1271 * Returns the projection obect from the baselayer. 1272 * 1273 * Returns: 1274 * {<OpenLayers.Projection>} The Projection of the base layer. 1275 */ 1276 getProjectionObject: function() { 1258 1277 var projection = null; 1259 1278 if (this.baseLayer != null) { 1260 1279 projection = this.baseLayer.projection; -
lib/OpenLayers/Format/GeoJSON.js
old new 488 488 * of a GeoJSON object. 489 489 */ 490 490 createCRSObject: function(object) { 491 var proj = object.layer.projection ;491 var proj = object.layer.projection.toString(); 492 492 var crs = {}; 493 493 if (proj.match(/epsg:/i)) { 494 494 var code = parseInt(proj.substring(proj.indexOf(":") + 1)); -
lib/OpenLayers/Layer/WMS.js
old new 211 211 * {String} 212 212 */ 213 213 getFullRequestString:function(newParams, altUrl) { 214 var projection = this.map.getProjection();215 this.params.SRS = (projection == "none") ? null : projection;214 var projectionCode = this.map.getProjection(); 215 this.params.SRS = (projectionCode == "none") ? null : projectionCode; 216 216 217 217 return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( 218 218 this, arguments); -
lib/OpenLayers/Layer/WFS.js
old new 376 376 * altUrl - {String} Use this as the url instead of the layer's url 377 377 */ 378 378 getFullRequestString:function(newParams, altUrl) { 379 var projection = this.map.getProjection();380 this.params.SRS = (projection == "none") ? null : projection;379 var projectionCode = this.map.getProjection(); 380 this.params.SRS = (projectionCode == "none") ? null : projectionCode; 381 381 382 382 return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( 383 383 this, arguments); -
lib/OpenLayers.js
old new 175 175 "OpenLayers/Layer/WFS.js", 176 176 "OpenLayers/Control/MouseToolbar.js", 177 177 "OpenLayers/Control/NavToolbar.js", 178 "OpenLayers/Control/EditingToolbar.js" 178 "OpenLayers/Control/EditingToolbar.js", 179 "OpenLayers/Projection.js" 179 180 ); // etc. 180 181 181 182
