2

How can openlayers 3 be told to use and work with a custom SRS-definition which has no EPSG-code?

May i don't understand it but it seems like ol3 needs an EPSG- or ESRI-code to work.

I found some examples about how to use WKT- and proj4- definitions unsing Prof4js.defs, but it didn't work for me:

Proj4: https://stackoverflow.com/questions/29027295/how-to-use-openlayers-3-with-proj4js

OpenLayers 3 transform coordinates to custom projection

https://stackoverflow.com/questions/29302770/parsing-projection-wkt-in-openlayers-3

I had several errors caused by the line with the definition (proj4.defs) saying the projection is undefined. I used a WKT and a proj4 declaration in there - both were creating the same Error.

I have a WKT- and a simple proj4-definition for the needed reference body, but i don't understand how to combine it to make it work in ol3.

The simplified js I use:

var baseLayers = new ol.layer.Group({
    title: 'Base Layers',
        openInLayerSwitcher: true,
        layers:
        [   new ol.layer.Tile({
                title: "testLayer1",
                baseLayer: true,
                source: new ol.source.OSM({                     
                    url: 'tiled_layer1/{z}/{x}/{-y}.png'
                })
            }),
            new ol.layer.Tile({
                title: "mos_final_14_02_13.map",
                baseLayer: true,
                visible: false,
                source: new ol.source.OSM({                     
                    url: 'tiled_layer2/{z}/{x}/{-y}.png'
                })
            })
        ]
    });
var overlays = new ol.layer.Group({
    title: 'moasaic single frames',
        openInLayerSwitcher: true,
        layers:
        [   new ol.layer.Tile({
                title: "overlay1",
                baseLayer: false,
                source: new ol.source.OSM({                     
                    url: 'tiled_overlay/{z}/{x}/{-y}.png'
                })
            }),
            new ol.layer.Tile({
                title: "overlay2,
                baseLayer: false,
                visible: false,
                source: new ol.source.OSM({
                    url: 'tiled_overlay2/{z}/{x}/{-y}.png'
                })
            })
        ]
    });         
    var map = new ol.Map({
        target: 'map',
        view: new ol.View({
            center: ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857'),
            zoom: 3,
            minZoom: 0,
            maxZoom: 9
        }),
        controls: ol.control.defaults().extend([
            new ol.control.LayerSwitcher()
        ]),
        layers: [baseLayers, overlays]          
    });

OpenLayers 3 Examples showing this: http://openlayers.org/en/v3.3.0/examples/wms-image-custom-proj.html

They use a JS-file telling the Definition for the Projection - but i didn't find the place where they use it - its just standing in thier souce-code.

1

for my knowledge it should work with using this in head

<script src="js/proj4.js"></script>
<script src="js/my_sphere_proj4.js"</script>

and writing this into map.js:

var projection = ol.proj.get('my_sphere');

now we should be able to use the my_sphere_proj4.js file:

proj4.defs("my_spehere","+proj=longlat +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=12345 +b=12345 +units=m +no_defs");

which can written into the js of the map or can be loaded by the 'my_sphere_proj4.js' above, wright?

the map itself is written like this:

var map = new ol.Map({
    target: 'map',
    view: new ol.View({
    center: ol.proj.transform([0,0], 'EPSG:4326', 'my_sphere'),
    zoom: 2,
    minZoom: 0,
    maxZoom: 8
}),
controls: ol.control.defaults().extend([    
    new ol.control.LayerSwitcher()
]),
layers: [ my.layer,s ]
});

All i got now is an visual Error - the map is shown like in mercator-projection but it should look like (wgs84) an equidistand projection.

If i use 'projection' with 'epsg:4326' and 'center: 0,0' its shown normal but its using the Earth. If i use it with 'my_sphere" its not showing anything and the debugging in firefox tells: "TypeError: a is null" in ol3.js 30:23, which is openlayers3.

Idk how to fix that now.

0

They use it in this file http://openlayers.org/en/v3.3.0/examples/wms-image-custom-proj.js

You have to add your custom projection

proj4.defs("EPSG:21781","+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=660.077,13.551,369.344,2.484,1.783,2.939,5.66 +units=m +no_defs");

Then use it for your view, as in wms-image-custom-proj.js

  • I tried that and had a look for this post, too: stackoverflow.com/a/29303807 I used both mentioned methods with proj4.js and wkt declarations in script and in a js-file. It took me a while to fix the errors but, the used layers aren't at thier position like they should - nothing changed. I am using several geotiffs which are tiled by gdal2tiles. The geotiffs are using the wanted projection and are shown at thier position in Arcmap. My used command-line is like: gdal2tiles -p raster -r near -z 0-9 input.tiff output/dir – me2 Feb 21 '17 at 15:40
  • it seems like gdal doesn't work with exotic projections. It wants -p PROFILE with mercator or geodetic - default 'mercator' (Google Maps compatible). Are there any hints or advises how to import an own srs to gdal??? I used -p raster which will create tiles without any srs - the result is such a tiled picture. How can i add a srs and profile to use it by "-p my_sphere" – me2 Feb 21 '17 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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