Ticket #1210: 1210.2.patch
| File 1210.2.patch, 10.8 kB (added by tschaub, 1 year ago) |
|---|
-
apidoc_config/Menu.txt
old new 168 168 File: Box (no auto-title, OpenLayers/Marker/Box.js) 169 169 } # Group: Marker 170 170 171 File: Projection (no auto-title, OpenLayers/Projection.js) 172 171 173 Group: Popup { 172 174 173 175 File: Popup (OpenLayers/Popup.js) -
doc_config/Menu.txt
old new 168 168 File: Box (no auto-title, OpenLayers/Marker/Box.js) 169 169 } # Group: Marker 170 170 171 File: Projection (no auto-title, OpenLayers/Projection.js) 172 171 173 Group: Popup { 172 174 173 175 File: Popup (OpenLayers/Popup.js) -
tests/Layer/test_SphericalMercator.html
old new 1 1 <html> 2 2 <head> 3 <!-- this gmaps key generated for http://openlayers.org/dev/ -->4 3 <script src="../../lib/OpenLayers.js"></script> 5 4 <script type="text/javascript"> 6 function test_SphericalMercator_forward Project(t) {5 function test_SphericalMercator_forwardMercator(t) { 7 6 t.plan(12); 8 7 var arctic = OpenLayers.Layer.SphericalMercator.forwardMercator(0, 85); 9 8 var antarctic = OpenLayers.Layer.SphericalMercator.forwardMercator(0, -85); … … 32 31 t.eq(sw.lon, -20037508.34, "SW lon is correct"); 33 32 } 34 33 35 function test_sphericalMercator_inverse Project(t) {34 function test_sphericalMercator_inverseMercator(t) { 36 35 t.plan(4); 37 36 var sw = OpenLayers.Layer.SphericalMercator.inverseMercator(-20037508.34, -20037508.34); 38 37 var ne = OpenLayers.Layer.SphericalMercator.inverseMercator(20037508.34, 20037508.34); … … 42 41 t.eq(sw.lat, -85.05112877980659, "Southwest lat correct"); 43 42 t.eq(ne.lat, 85.05112877980660, "Northeast lat correct"); 44 43 } 44 45 function strToFixed(str, dig) { 46 if(dig == undefined) { 47 dig = 5; 48 } 49 return str.replace(/(\d+\.\d+)/g, function(match) { 50 return parseFloat(match).toFixed(dig); 51 }); 52 } 53 54 function test_SphericalMercator_projectForward(t) { 55 t.plan(1); 56 var point = new OpenLayers.Geometry.Point(10, 20); 57 OpenLayers.Layer.SphericalMercator.projectForward(point); 58 59 t.eq(strToFixed(point.toString()), 60 strToFixed("POINT(1113194.9077777779 2273030.9266712805)"), 61 "point transforms from EPSG:4326 to Spherical Mercator"); 62 } 63 64 function test_SphericalMercator_to4326(t) { 65 t.plan(1); 66 var point = new OpenLayers.Geometry.Point(1113195, 2273031); 67 68 OpenLayers.Layer.SphericalMercator.projectInverse(point); 69 70 t.eq(strToFixed(point.toString()), 71 strToFixed("POINT(10.000000828446318 20.000000618997227)"), 72 "point transforms from EPSG:4326 to Spherical Mercator"); 73 } 45 74 75 function test_SphericalMercator_addTransform(t) { 76 // this class should add two methods to the 77 // OpenLayers.Projection.transforms object 78 t.plan(4); 79 var wgs84 = OpenLayers.Projection.transforms["EPSG:4326"]; 80 t.ok(wgs84 instanceof Object, "EPSG:4326 exists in table"); 81 82 var smerc = OpenLayers.Projection.transforms["EPSG:900913"]; 83 t.ok(smerc instanceof Object, "EPSG:900913 exists in table"); 84 85 t.ok(wgs84["EPSG:900913"] === OpenLayers.Layer.SphericalMercator.projectForward, 86 "from EPSG:4326 to EPSG:900913 correctly defined"); 87 t.ok(smerc["EPSG:4326"] === OpenLayers.Layer.SphericalMercator.projectInverse, 88 "from EPSG:900913 to EPSG:4326 correctly defined"); 89 } 90 46 91 </script> 47 92 </head> 48 93 <body> -
lib/OpenLayers/Projection.js
old new 6 6 * @requires OpenLayers/Util.js 7 7 * 8 8 * Class: OpenLayers.Projection 9 * Class for coordinate transform ations between coordinate systems.9 * Class for coordinate transforms between coordinate systems. 10 10 * Depends on the proj4js library. If proj4js is not available, 11 11 * then this is just an empty stub. 12 12 */ … … 102 102 }); 103 103 104 104 /** 105 * Property: transforms 106 * Transforms is an object, with from properties, each of which may 107 * have a to property. This allows you to define projections without 108 * requiring support for proj4js to be included. 109 * 110 * This object has keys which correspond to a 'source' projection object. The 111 * keys should be strings, corresponding to the projection.getCode() value. 112 * Each source projection object should have a set of destination projection 113 * keys included in the object. 114 * 115 * Each value in the destination object should be a transformation function, 116 * where the function is expected to be passed an object with a .x and a .y 117 * property. The function should return the object, with the .x and .y 118 * transformed according to the transformation function. 119 * 120 * Note - Properties on this object should not be set directly. To add a 121 * transform method to this object, use the <addTransform> method. For an 122 * example of usage, see the OpenLayers.Layer.SphericalMercator file. 123 */ 124 OpenLayers.Projection.transforms = {}; 125 126 /** 127 * APIMethod: addTransform 128 * Set a custom transform method between two projections. Use this method in 129 * cases where the proj4js lib is not available or where custom projections 130 * need to be handled. 131 * 132 * Parameters: 133 * from - {String} The code for the source projection 134 * to - {String} the code for the destination projection 135 * method - {Function} A function that takes a point as an argument and 136 * transforms that point from the source to the destination projection 137 * in place. The original point should be modified. 138 */ 139 OpenLayers.Projection.addTransform = function(from, to, method) { 140 if(!OpenLayers.Projection.transforms[from]) { 141 OpenLayers.Projection.transforms[from] = {}; 142 } 143 OpenLayers.Projection.transforms[from][to] = method; 144 }; 145 146 /** 105 147 * APIMethod: transform 106 * Read data from a string, and return an object whose type depends on the107 * subclass.148 * Transform a point coordinate from one projection to another. Note that 149 * the input point is transformed in place. 108 150 * 109 151 * Parameters: 110 * point - {object} input horizontal coodinate 111 * sourceProj - {OpenLayers.Projection} source map coordinate system 112 * destProj - {OpenLayers.Projection} destination map coordinate system 152 * point - {{OpenLayers.Geometry.Point> | Object} An object with x and y 153 * properties representing coordinates in those dimensions. 154 * sourceProj - {OpenLayers.Projection} Source map coordinate system 155 * destProj - {OpenLayers.Projection} Destination map coordinate system 113 156 * 114 157 * Returns: 115 * point - {object} trasnformed coordinate158 * point - {object} A transformed coordinate. The original point is modified. 116 159 */ 117 160 OpenLayers.Projection.transform = function(point, source, dest) { 118 161 if (source.proj && dest.proj) { 119 162 point = Proj4js.transform(source.proj, dest.proj, point); 163 } else if (source && dest && 164 OpenLayers.Projection.transforms[source.getCode()] && 165 OpenLayers.Projection.transforms[source.getCode()][dest.getCode()]) { 166 OpenLayers.Projection.transforms[source.getCode()][dest.getCode()](point); 120 167 } 121 168 return point; 122 169 }; -
lib/OpenLayers/Layer/SphericalMercator.js
old new 1 1 /** @requires OpenLayers/Layer.js 2 * @requires OpenLayers/Projection.js 2 3 * 3 4 * Class: OpenLayers.Layer.SphericalMercator 4 5 * A mixin for layers that wraps up the pieces neccesary to have a coordinate … … 101 102 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); 102 103 103 104 return new OpenLayers.LonLat(lon, lat); 105 }, 106 107 /** 108 * Method: projectForward 109 * Given an object with x and y properties in EPSG:4326, modify the x,y 110 * properties on the object to be the Spherical Mercator projected 111 * coordinates. 112 * 113 * Parameters: 114 * point - {Object} An object with x and y properties. 115 * 116 * Returns: 117 * {Object} The point, with the x and y properties transformed to spherical 118 * mercator. 119 */ 120 projectForward: function(point) { 121 var lonlat = OpenLayers.Layer.SphericalMercator.forwardMercator(point.x, point.y); 122 point.x = lonlat.lon; 123 point.y = lonlat.lat; 124 return point; 125 }, 126 127 /** 128 * Method: projectForward 129 * Given an object with x and y properties in Spherical Mercator, modify 130 * the x,y properties on the object to be the unprojected coordinates. 131 * 132 * Parameters: 133 * point - {Object} An object with x and y properties. 134 * 135 * Returns: 136 * {Object} The point, with the x and y properties transformed from 137 * spherical mercator to unprojected coordinates.. 138 */ 139 projectInverse: function(point) { 140 var lonlat = OpenLayers.Layer.SphericalMercator.inverseMercator(point.x, point.y); 141 point.x = lonlat.lon; 142 point.y = lonlat.lat; 143 return point; 104 144 } 105 145 106 146 }; 147 148 /** 149 * Note: Two transforms declared 150 * Transforms from EPSG:4326 to EPSG:900913 and from EPSG:900913 to EPSG:4326 151 * are set by this class. 152 */ 153 OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:900913", 154 OpenLayers.Layer.SphericalMercator.projectForward); 155 OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:4326", 156 OpenLayers.Layer.SphericalMercator.projectInverse); -
lib/OpenLayers.js
old new 78 78 "Rico/Color.js", 79 79 "OpenLayers/Ajax.js", 80 80 "OpenLayers/Events.js", 81 "OpenLayers/Projection.js", 81 82 "OpenLayers/Map.js", 82 83 "OpenLayers/Layer.js", 83 84 "OpenLayers/Icon.js", … … 175 176 "OpenLayers/Layer/WFS.js", 176 177 "OpenLayers/Control/MouseToolbar.js", 177 178 "OpenLayers/Control/NavToolbar.js", 178 "OpenLayers/Control/EditingToolbar.js", 179 "OpenLayers/Projection.js" 179 "OpenLayers/Control/EditingToolbar.js" 180 180 ); // etc. 181 181 182 182
