1

My WMS layer(EPSG:3847) looks fine in GeoServer enter image description here However, it is distorted in browser: enter image description here I found someone hade the same problem(Openlayers and Geoserver: OSM/Google Maps and WMS Overlay)but I still couldn't solve the problem. I also tried to add code like

var geographic = new OpenLayers.Projection("EPSG:3847");
var mercator = new OpenLayers.Projection("EPSG:4326");
var lund_center = new OpenLayers.LonLat(13.2, 55.7).transform(
                geographic, mercator

and

map.setCente(lund_center, 10);

but the WMS layer is still distorted. I also tried this code but nothing's changed (EPSG3847 is not included in proj4.js, is that why the code didn't work?):

EPSG4326 = new OpenLayers.Projection("EPSG:4326");
EPSG3847  = new OpenLayers.Projection("EPSG:3847 ");

var option = {
            projection: new OpenLayers.Projection("EPSG:3847 "),
            displayProjection: new OpenLayers.Projection("EPSG:4326")
            };

How can I solve this problem? Any help please? *the code I'm trying now are as follows, still,nothing changed:

    var lon = 12.1;
    var lat = 48.4;
    var zoom = 10;
    var map, vectors, controls;      
 var options = {
        controls: [],
        projection: new OpenLayers.Projection('EPSG:3857'),
        displayProjection: new OpenLayers.Projection('EPSG:4326'),
        maxExtent: new OpenLayers.Bounds(           
        -20037508, -20037508,20037508, 20037508.34),
        //modify parameter
        maxResolution: 5000,
        //modify parameter
        //setting zoom levels
        numZoomLevels:15,
        units: 'm',

    };

 function init(){

    var map = new OpenLayers.Map({
    div: "map",
    allOverlays: true
    });



    var roads_wms = new OpenLayers.Layer.WMS( "Roads",
            "http://localhost:8090/geoserver/wms/wsNYCRoad", {
            projection: map.displayProjection,
            layers: 'vagar_alla',
            styles: '',
            srs:'EPSG:3006',                
            transparent:true,
            tiled: 'false',
            tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
        },
        {
            buffer: 0,
            displayOutsideMaxExtent: true,
            isBaseLayer: false,
            reproject: true
        });
        Proj4js.defs["EPSG:3006"] = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
        Proj4js.defs["EPSG:4326"] = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
        var src = new OpenLayers.Projection('EPSG:3006');
        var dst =  new OpenLayers.Projection('EPSG:4326');
        Proj4js.transform(src, dst, roads_wms); 
        roads_wms.projection=dst;
9
  • 1
    This is correct behaviour. Going from degrees to meters will inevitably change the shape as sadly the earth is not flat :D. Commented Dec 16, 2014 at 13:06
  • @JohnBarça Thanks for your answer.So you are saying I don't need to do any transformation? Is there anyway I can display the layer in the browser as it is displayed in GeoServer? Commented Dec 16, 2014 at 13:15
  • 1
    I'm sorry I misread that as 3857. 3847 is a Swedish projection so you will need to add proj4js I imagine. Commented Dec 16, 2014 at 13:21
  • @JohnBarça as I said 3847 is not included in proj4js, so no use to add proj4js, besides there's no format for Proj4js.defs["EPSG:3847"]="" T_T Commented Dec 16, 2014 at 13:24
  • So why are you surprised that it looks different? Commented Dec 16, 2014 at 13:25

2 Answers 2

1

I solved the problem:

First, re-project the wms layer in ArcMap to WGS_1984_Web_Mercator_Auxiliary_Sphere(epsg3857). Then use this code:

var map = new OpenLayers.Map({
            maxScale: 1/5000,
            minScale: 1/500000,
            projection: new OpenLayers.Projection("EPSG:3857"),
            displayProjection: new OpenLayers.Projection("EPSG:4326"),
            div: "map",
            allOverlays: true
    });

var proj = new OpenLayers.Projection("EPSG:4326");
var lonlat = new OpenLayers.LonLat(1468582.90048,7501836.76895);
lonlat.transform(proj, map.getProjectionObject());
map.setCenter(lonlat, 5);
0

That doesn't quite match what I see in the WKT in the link I sent... and did you try just adding (preferably with corrected lon_0, x_0, and y_0 from WKT mentioned in my comment)

# Swiss Transverse Mercator
<3847> +proj=tmerc +lat_0=0 +lon_0=15.80827777777778 +k=1 +x_0=1500000 +y_0=0 +ellps=bessel +units=m +no_defs  no_defs <>

to the epsg file?

3
  • Yes I did, but it didn't work. I also tried to reproject the wms layer in ArcMap, but still it is displayed as distorted in the browser. Commented Dec 16, 2014 at 15:03
  • and why as long as I add projection and displayProjection the layer disappeared from the browser completely? Commented Dec 16, 2014 at 15:05
  • I only know projections, not GeoServer. I have C# code written in-house that uses proj (via DLLImport) and we've handled odd projectiouns by adding them to the epsg file as described. Are you sure you edited the right file? It's in the folder referenced by the PROJ_LIB environment variable. Commented Dec 16, 2014 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.