<p class="MsoNormal"><span lang="EN-US">In Sweden
we are using RT90 (</span><a href="http://spatialreference.org/ref/epsg/3021/"><span lang="EN-US">http://spatialreference.org/ref/epsg/3021/</span></a><span lang="EN-US">). I’ve been working on a app that
displays EPSG:3021-coords upon Google Maps (EPSG:900913). (I got help by Erik
Hazzard, the author of the book Openalyers 2.10).</span></p>
<p class="MsoNormal"><span lang="EN-US">It’s almost
working, but there is still one thing that’s kind of odd which neither he nor I
understand.</span></p>
<p class="MsoNormal"><span lang="EN-US">See Code
below</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"><!DOCTYPE
html></span></p>
<p class="MsoNormal"><span lang="EN-US"><html></span></p>
<p class="MsoNormal"><span lang="EN-US"> <head></span></p>
<p class="MsoNormal"><span lang="EN-US"> <meta
http-equiv="Content-Type" content="text/html;
charset=utf-8"></span></p>
<p class="MsoNormal"><span lang="EN-US"> <meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0,
user-scalable=0"></span></p>
<p class="MsoNormal"><span lang="EN-US"> <meta
name="apple-mobile-web-app-capable" content="yes"></span></p>
<p class="MsoNormal"><span lang="EN-US"> <link rel="stylesheet"
href="<a href="http://openlayers.org/dev/theme/default/style.css">http://openlayers.org/dev/theme/default/style.css</a>"
type="text/css"></span></p>
<p class="MsoNormal"><span lang="EN-US"> <link rel="stylesheet"
href="<a href="http://openlayers.org/dev/examples/style.css">http://openlayers.org/dev/examples/style.css</a>" type="text/css"></span></p>
<p class="MsoNormal"><span lang="EN-US"> <style></span></p>
<p class="MsoNormal"><span lang="EN-US"> .olControlMousePosition {</span></p>
<p class="MsoNormal"><span lang="EN-US"> background:rgba(255,255,255,.9)
!important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span>border:1px solid
rgba(0,0,0,.4) !important;</p>
<p class="MsoNormal"> <span lang="EN-US">bottom:150px !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> font-size:1em !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> font-weight:bold !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> padding:2px !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> position:absolute !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> right:2px !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> width:100px !important;</span></p>
<p class="MsoNormal"><span lang="EN-US"> }</span></p>
<p class="MsoNormal"><span lang="EN-US"> </style></span></p>
<p class="MsoNormal"><span lang="EN-US"> </head></span></p>
<p class="MsoNormal"><span lang="EN-US"> <body></span></p>
<p class="MsoNormal"><span lang="EN-US"> <div id="map"
style='height:500px;width:500px;'></div></span></p>
<p class="MsoNormal"><span lang="EN-US"> <div id='point_display'></div></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"><script
src="<a href="http://openlayers.org/dev/OpenLayers.js">http://openlayers.org/dev/OpenLayers.js</a>"></script></span></p>
<p class="MsoNormal"><span lang="EN-US"> <script src='proj4js.js'></script></span></p>
<p class="MsoNormal"><span lang="EN-US"><script
src="<a href="http://maps.googleapis.com/maps/api/js?v=3.5&amp;sensor=false">http://maps.googleapis.com/maps/api/js?v=3.5&amp;sensor=false</a>"></script></span></p>
<p class="MsoNormal"><span lang="EN-US"> <script
src="EPSG3021.js"></script></span></p>
<p class="MsoNormal"><span lang="EN-US"> <script></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> var map = new OpenLayers.Map({</span></p>
<p class="MsoNormal"><span lang="EN-US"> div: "map",</span></p>
<p class="MsoNormal"><span lang="EN-US"> projection: new
OpenLayers.Projection('EPSG:900913'),</span></p>
<p class="MsoNormal"><span lang="EN-US"> displayProjection: new
OpenLayers.Projection('EPSG:3021')</span></p>
<p class="MsoNormal"><span lang="EN-US"> });</span></p>
<p class="MsoNormal"><span lang="EN-US">//********************************* </span></p>
<p class="MsoNormal"><span lang="EN-US"> var google_hybrid = new
OpenLayers.Layer.Google(</span></p>
<p class="MsoNormal"><span lang="EN-US"> "Google Hybrid",</span></p>
<p class="MsoNormal"><span lang="EN-US"> {sphericalMercator: true,type:
google.maps.MapTypeId.HYBRID, numZoomLevels: 22}</span></p>
<p class="MsoNormal"><span lang="EN-US"> );</span></p>
<p class="MsoNormal"><span lang="EN-US"> var google_physical = new
OpenLayers.Layer.Google(</span></p>
<p class="MsoNormal"><span lang="EN-US"> "Google Physical",</span></p>
<p class="MsoNormal"><span lang="EN-US"> {sphericalMercator: true,type:
google.maps.MapTypeId.TERRAIN, numZoomLevels: 22}</span></p>
<p class="MsoNormal"><span lang="EN-US"> );</span></p>
<p class="MsoNormal"><span lang="EN-US"> var google_satellite = new
OpenLayers.Layer.Google(</span></p>
<p class="MsoNormal"><span lang="EN-US"> "Google Satellite",</span></p>
<p class="MsoNormal"><span lang="EN-US"> {sphericalMercator: true,type:
google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}</span></p>
<p class="MsoNormal"><span lang="EN-US"> );</span></p>
<p class="MsoNormal"><span lang="EN-US"> var google_streets = new
OpenLayers.Layer.Google(</span></p>
<p class="MsoNormal"><span lang="EN-US"> "Google Streets",</span></p>
<p class="MsoNormal"><span lang="EN-US"> {sphericalMercator:
true,numZoomLevels: 22}</span></p>
<p class="MsoNormal"><span lang="EN-US"> ); </span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">//****************************** </span></p>
<p class="MsoNormal"><span lang="EN-US"> var
vector_layer = new OpenLayers.Layer.Vector(</span></p>
<p class="MsoNormal"><span lang="EN-US"> 'Vector Layer',</span></p>
<p class="MsoNormal"><span lang="EN-US"> {</span></p>
<p class="MsoNormal"><span lang="EN-US"> strategies: [new
OpenLayers.Strategy.Fixed()],</span></p>
<p class="MsoNormal"><span lang="EN-US"> projection: new
OpenLayers.Projection('EPSG:3021'),</span></p>
<p class="MsoNormal"><span lang="EN-US"> protocol: new
OpenLayers.Protocol.HTTP({</span></p>
<p class="MsoNormal"><span lang="EN-US"> url: "data_in_3021.json",</span></p>
<p class="MsoNormal"><span lang="EN-US"> format: new
OpenLayers.Format.GeoJSON({</span></p>
<p class="MsoNormal"><span lang="EN-US"> })</span></p>
<p class="MsoNormal"><span lang="EN-US"> })</span></p>
<p class="MsoNormal"><span lang="EN-US"> });</span></p>
<p class="MsoNormal"><span lang="EN-US">
vector_layer.events.register('featureselected', this, function(feature){</span></p>
<p class="MsoNormal"><span lang="EN-US"> var feature_html = '';</span></p>
<p class="MsoNormal"><span lang="EN-US"> var feature_copy =
feature.feature.clone();</span></p>
<p class="MsoNormal"><span lang="EN-US"> var feature_reprojected = feature_copy.geometry.transform(</span></p>
<p class="MsoNormal"><span lang="EN-US"> new
OpenLayers.Projection('EPSG:900913'),</span></p>
<p class="MsoNormal"><span lang="EN-US"> new
OpenLayers.Projection('EPSG:3021'));</span></p>
<p class="MsoNormal"><span lang="EN-US"> feature_html += "Lon: " +
feature_reprojected.x</span></p>
<p class="MsoNormal"><span lang="EN-US"> + " | Lat: " +
feature_reprojected.y;</span></p>
<p class="MsoNormal"><span lang="EN-US"> feature_html += " | Antal:
" + feature_copy.attributes.observations_count;</span></p>
<p class="MsoNormal"><span lang="EN-US"> feature_html += "<br
/>";</span></p>
<p class="MsoNormal"><span lang="EN-US"> document.getElementById('point_display').innerHTML
+= feature_html;</span></p>
<p class="MsoNormal"><span lang="EN-US"> });</span></p>
<p class="MsoNormal"><span lang="EN-US">
vector_layer.events.register('featureunselected', this,
function(feature){</span></p>
<p class="MsoNormal"><span lang="EN-US">
document.getElementById('point_display').innerHTML = '';</span></p>
<p class="MsoNormal"><span lang="EN-US"> });</span></p>
<p class="MsoNormal"><span lang="EN-US"> map.addLayers([</span></p>
<p class="MsoNormal"><span lang="EN-US"> google_hybrid, </span>google_physical, google_satellite, google_streets, vector_layer</p>
<p class="MsoNormal"><span lang="EN-US"> ]);</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> //-------------------------------</span></p>
<p class="MsoNormal"><span lang="EN-US"> //Controls</span></p>
<p class="MsoNormal"><span lang="EN-US"> //-------------------------------</span></p>
<p class="MsoNormal"><span lang="EN-US"> var overview_map = new
OpenLayers.Control.OverviewMap(</span></p>
<p class="MsoNormal"><span lang="EN-US"> {</span> autoPan: true, <span lang="EN-US">size: new
OpenLayers.Size(150,100)</span> }</p>
<p class="MsoNormal"><span lang="EN-US"> );</span></p>
<p class="MsoNormal"><span lang="EN-US"> var select_features_control = new
OpenLayers.Control.SelectFeature(</span></p>
<p class="MsoNormal"><span lang="EN-US"> vector_layer,{</span></p>
<p class="MsoNormal"><span lang="EN-US"> clickout: true,</span></p>
<p class="MsoNormal"><span lang="EN-US"> toggle: false,</span></p>
<p class="MsoNormal"><span lang="EN-US"> multiple: true,</span></p>
<p class="MsoNormal"><span lang="EN-US"> hover: false,</span></p>
<p class="MsoNormal"><span lang="EN-US"> box: true</span></p>
<p class="MsoNormal"><span lang="EN-US"> });</span></p>
<p class="MsoNormal"><span lang="EN-US"> map.addControls([</span></p>
<p class="MsoNormal"><span lang="EN-US"> new OpenLayers.Control.MousePosition(),</span></p>
<p class="MsoNormal"><span lang="EN-US"> new
OpenLayers.Control.LayerSwitcher(),</span></p>
<p class="MsoNormal"><span lang="EN-US"> overview_map,</span></p>
<p class="MsoNormal"><span lang="EN-US"> select_features_control</span></p>
<p class="MsoNormal"><span lang="EN-US"> ]);</span></p>
<p class="MsoNormal"><span lang="EN-US"> overview_map.maximizeControl();</span></p>
<p class="MsoNormal"><span lang="EN-US"> select_features_control.activate();</span></p>
<p class="MsoNormal"><span lang="EN-US"> if(!map.getCenter()){</span></p>
<p class="MsoNormal"><span lang="EN-US"> map.setCenter(</span></p>
<p class="MsoNormal"><span lang="EN-US"> new OpenLayers.LonLat(1738182,
9069017),</span></p>
<p class="MsoNormal"><span lang="EN-US"> 6);</span></p>
<p class="MsoNormal"><span lang="EN-US"> }</span></p>
<p class="MsoNormal"><span lang="EN-US"> </script></span></p>
<p class="MsoNormal"><span lang="EN-US"> </body></span></p>
<p class="MsoNormal"><span lang="EN-US"></html></span></p><p class="MsoNormal"><span lang="EN-US"><br></span></p>
<p class="MsoNormal"><span lang="EN-US">The
JSON-file contains:</span></p>
<p class="MsoNormal"><span lang="EN-US">{"type":
"FeatureCollection", "features": [</span></p>
<p class="MsoNormal"><span lang="EN-US"> {"type":"Feature",</span></p>
<p class="MsoNormal"><span lang="EN-US">
"geometry":{"type":"Point",</span></p>
<p class="MsoNormal"><span lang="EN-US"> "coordinates":[1710943,
7456832]},</span></p>
<p class="MsoNormal"><span lang="EN-US">
"properties":{"observations_count": 1 }}</span></p>
<p class="MsoNormal"><span lang="EN-US">]}</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">This
geolocation, 1710943, 7456832 is a well known roundabout in my hometown and when
the marker hits the map it’s placed some 400 m Northbound and 200 meters
Eastbound from where it should be. Looking at the map.</span></p>
<p class="MsoNormal"><span lang="EN-US">When I move
the mouse over the actual marker it displays the correct locations as above.</span></p>
<p class="MsoNormal"><span lang="EN-US">If I move
the mouse to where it should be, it displays the wrong lon-lat-coordinates.</span></p>
<p class="MsoNormal"><span lang="EN-US">I used to
work with ARC-GIS before and this gives me thoughts about the layers not being properly
rectified to each other</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">I’d
appreciate it a lot if somebody could give me a hint on where to look and what
to correct.</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">Best
regards</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">Roger Waara</span></p>
<p class="MsoNormal"><span lang="EN-US">Sweden</span></p><div><br></div>-- <br><br>=========================<br>Roger Waara<br>