2

I have a map with some layers in Projection EPSG:25832. This works well with OpenLayers 5.3.3. But when I change to OpenLayers 6.4.3 (or all others down to 6.0.1) then there is an error in the Definition of my projection. I am using proj4js in the version 2.6.2 (also tried older versions).

Error thrown from Proj4js: Uncaught TypeError: coordinates must be finite numbers .... proj4-2.6.2.js:1:4846

Sourcecode in Openlayers-5 and Openlayers-6

var oBoundsGesamt = [ 456700,5200500,773480,5835251 ];

proj4.defs(sEpsgNummer, "+proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs ");
ol.proj.proj4.register(proj4);

var oOlProjection = ol.proj.get('EPSG:25832');
oOlProjection.setExtent( oBoundsGesamt  );

var oMapObj = new ol.Map({
   target: 'ebMapObj',
   layers: [ ... ], 
   view: new ol.View({
        projection : oOlProjection,
        extent: oBoundsGesamt,

Can somebody help me with this? The error is thrown at the end when I try to zoom to an Extent:

  • ol.control.ZoomToExtent({ extent: oBoundsGesamt }) or
  • oMapObj.getView().fit(oBoundsStart, oMapObj.getSize());
4
  • 1
    proj4 will only be used if one of your layers uses a different projection. It would be useful to see more of your code and the full call stack for the error. – Mike Sep 24 '20 at 9:17
  • Thanks for the hint - at the beginning I tried without proj4 but as this didn't help, i included this. I will try without and then update the question with more source code. – leole Sep 24 '20 at 10:46
  • Thanks. It seemed to be a problem with the extent in my ol.View ... When I remove the proj4 lib/projection and reduce the Projection to var oOlProjection = new ol.proj.Projection({ code: sEpsgNummer, units: 'm' }); then the map is white but no errors any more with Openlayers 6. When I scroll in after two steps the maps appears :-) – leole Sep 24 '20 at 11:56
  • Now i have removed the extent from every layer and added it only to the definition of the Projection (var oOlProjection = new ol.proj.Projection({ code: sEpsgNummer, units: 'm', extent: oBoundsEtrs25832Ganz }); ). After that the map shows up. The ol.View only has a projection, center, zoom level. It seems that the extent/Bounds were to small because OpenLayers startet with this extent but as the map asks for more (default: 1.0 ratio) the extent might have been to small and therefore the white map – leole Sep 24 '20 at 12:14
1

Thank you @Mike for helping me to get off the wrong track. Now it works fine with OpenLayers 6

The problem in my case was that I could remove the proj4 library which made life easier. I started with the OSM Example Map with EPSG:3587 and added my own WMS Server with EPSG:25832. Therefore I initially neeeded a reprojection. But as all my layers in my final result are in EPSG:25832 I could remove the proj4 without any need for reprojection.

Then there was only the problem left, that the map was white and didn't show anything on start - but when I zoomed in the map appeared. This was resolved by changing the zoom level of the ol.View and removing the extent from the ol.view (now only: projection zoom and center Attributes in the ol.View). After the experiences in my current map with OpenLayers 2 I couldn't imagine that a Map with layers could be build/constructed completely without an extent - only a center-Coordinate is needed.

Here the (reducced) source

var oBoundsEtrs25832Ganz = [ 265948.8191, 6421521.2254, 677786.3629, 7288831.7014 ]; //Bounds from: https://epsg.io 
var oOlProjection = new ol.proj.Projection({ code:'EPSG:25832', units: 'm', extent: oBoundsEtrs25832Ganz });
...
var sMapservUrlUndMapfileMs = 'http://localhost/cgi-bin/mapserv.exe?map=C:/webapps/anwendungsname/dynamisch.map';
...
var oWmsSourceMapserverStrassen = new ol.source.ImageWMS({
    url: sMapservUrlUndMapfileMs,
    params: {'LAYERS': 'openlayers_hintergrund', 'VERSION':'1.1.1' },
    serverType:  'mapserver'
});
var oLayerStrassennetz = new ol.layer.Image({ 
    source: oWmsSourceMapserverStrassen, 
    opacity: 0.6,
    zIndex: 2
}); 
...
var oMapObj = new ol.Map({
  target: 'ebMapObj',
  layers: [oLayerStrassennetz],
  view: new ol.View({
      projection : oOlProjection,
      center: [ 734565, 5306769 ],
      zoom: 6
  })
});     

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.