4

I want to use EPSG:25832 as the default projection for all my layers. The projection is not working correctly because the Position (center point) should be in Germany but I end up in France. When I want to pan to Germany I get an "InvalidStateError". I did the following:

  1. loaded the latest proj4j Version with

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4-src.js"></script>

and

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4.js"></script>
  1. defined the projection (parameter from http://spatialreference.org/ref/epsg/etrs89-utm-zone-32n/):
 var myProjectionName = 'EPSG:25832'; proj4.defs(myProjectionName,
  "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs");
  1. created the projection:
var myProjection = new ol.proj.Projection({
    code: myProjectionName,
    extent: [265948.8191, 6421521.2254, 677786.3629, 7288831.7014],
    units: 'm'
});
ol.proj.addProjection(myProjection);

I got the extent parameter also from http://spatialreference.org/ref/epsg/etrs89-utm-zone-32n/

  1. created the map:
var map = new ol.Map({
  layers: layers,
  target: 'map',
  view: new ol.View({
  projection: myProjection, // Is this necessary?
  center: ol.proj.transform([7.20,51.67], 'EPSG:4326', myProjectionName),
  zoom: 10
  })
});

I saw different approaches on how the map was created (with and without the projection parameter). Is the projection needed or is it sufficient to add the "ol.proj.transform" at the Center parameter?

Before I used

center: ol.proj.transform([7.20,51.67], 'EPSG:4326', 'EPSG:3857'),

which worked fine for displaying the data. Now I am working with a WFS-T and it is necessary to use EPSG:25832. What is wrong with my projection?

1 Answer 1

4

step 3 is not needed .... and maybe will cause you probs. this is enough to declare your projection var myProjectionName = 'EPSG:25832'; proj4.defs(myProjectionName, "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs");

then you may call var myProjection = ol.proj.get(myProjectionName) to get your projection as a proper ol projection object. Now if you want to pass it to the map, view, layers etc use myProjection variable.

For your center use: center: ol.proj.transform([7.20,51.67], 'EPSG:4326', 'EPSG:25832')

For your question concerning if it is necessary to be passed on view initialasation depends on what you want to do. Do you want to use this as your default projection? If yes then you have to pass it. Better make a fiddle to show us your case. The confusion make come from the layers you load and the way you declare them.

5
  • Thanks for the answer but that did not Change anything.
    – Lars
    Commented Nov 30, 2015 at 8:41
  • I think the projection is not properly recognized because the center of my map is in France (Clermond-Ferrand) and the coordinates are approximately 3.13, 45.74 instead of 7.20, 51.67. I am using 3 layers: OSM-layer (new ol.layer.Tile using new ol.source.MapQuest({layer: 'osm'}) as source), Geoserver-vectorlayer (new ol.layer.Vector) and a layer to draw new geometries (new ol.layer.Vector). My geometries are stored in an Oracle DB using EPSG:25832.
    – Lars
    Commented Nov 30, 2015 at 9:02
  • 2
    OSM tile layer is projected is EPSG:3857 and can not be reprojected on client. As long as you want to use as base map one of the public tile services you have to switch your map to EPSG:3857 and then reproject any vectors to this. A fiddle would help though.
    – pavlos
    Commented Nov 30, 2015 at 9:39
  • Works perfectly! I changed my center back to: center: ol.proj.transform([7.20,51.67], 'EPSG:4326', 'EPSG:3857') Before sending a new geometry to my WFS-T I just had to add feature.getGeometry().transform('EPSG:3857', myProjectionName); Thanks a lot!
    – Lars
    Commented Nov 30, 2015 at 10:15
  • no probms . glad to help
    – pavlos
    Commented Nov 30, 2015 at 11:30

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.