0
votes

I asked the same question 2 days ago but still I'm struggling with it. 1.I have a shapefile in RT90. 2.I reprojected it in ArcMap to WGS_1984_Web_Mercator_Auxiliary_Sphere(epsg3857) 3.In GeoServer, Native SRS is blank(not even shown Unknown) and Declared SRS is set to 3857, since 4326 does't work for some reason (no image in Layer Preview). The WMS layer in GeoSever is like this: enter image description here

And it is distorted in browser: enter image description here

This is my code:

    <script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js"></script>
    <script defer="defer" type="text/javascript">
        var lon = 13.2;
        var lat = 55.7;
        var zoom = 10;

        var bounds = new OpenLayers.Bounds(
                1460205.410400961, 7494354.925820643,
                1476383.1814075545, 7510328.218502053
            );

        var options = {
                controls: [],
                maxExtent: bounds,
                maxResolution: 63.194417994505784,
                projection: "EPSG:3857",
                units: 'm'
                };


       var map, vectors, controls; 

       function init(){

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


        var build1_wms = new OpenLayers.Layer.WMS( "Building",
                "http://localhost:8090/geoserver/wms/wsNYCRoad", {
                layers: 'bygg_lant_p',
                styles: '',      
                transparent:true,
                tiled: 'ture',
                tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
            },
            {
                buffer: 0,
                displayOutsideMaxExtent: true,
                isBaseLayer: true,
                yx : {'EPSG:3857' : false}
            });

            map.addLayers([build1_wms]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.addControl(new OpenLayers.Control.MousePosition());

I also tried to add this, but it didn't help:

var EPSG4326 = new OpenLayers.Projection("EPSG:4326");
var EPSG3857 = new OpenLayers.Projection("EPSG:3857 ");

Please help me to figure it out how to fix the problem!

1

1 Answers

0
votes

I fixed the problem:

     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);