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:
- loaded the latest proj4j Version with
and
- 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");
- 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/
- 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?
Answer
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.
No comments:
Post a Comment