Skip to content

Instantly share code, notes, and snippets.

@ThomasG77

ThomasG77/index.html

Last active Aug 29, 2015
Embed
What would you like to do?
Proj4js classic demo based on OpenLayers 2.x and Proj4js 1.1. Open the brower console to see the result
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
<script type="text/javascript">
//Correct datum for potsdam (altough already corrected with changes in towgs84 in the projection declaration)
// Only useful if you use the outdated spatialreference.org proj4js definition whereas epsg.io is right...
Proj4js.Datum["potsdam"] = {towgs84: "598.1,73.7,418.2,0.202,0.045,-2.455,6.7", ellipse: "bessel", datumName: "Potsdam Rauenberg 1950 DHDN"};
// Declare projection
Proj4js.defs["EPSG:31466"] = "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 +units=m +no_defs";
console.log(Proj4js.defs["EPSG:31466"]);
var proj_wgs84 = new OpenLayers.Projection("EPSG:4326");
var proj_31466 = new OpenLayers.Projection("EPSG:31466");
// Center for projection EPSG:31466
var point = new OpenLayers.LonLat(2769212.70, 5678724.61);
var new_point= point.clone().transform(proj_31466, proj_wgs84);
console.log(new_point.lat, new_point.lon);
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.