I am using the method ol.source.WMTS.optionsFromCapabilities to create a WMTS layer and when I am trying to use a projection that does not exist in OpenLayers it throws an error.

Please note that in my case the projection is not available up front.

Unfortunately, the nature of the error is very general. When using the minified version I get:

Cannot read property 'wb' of null

along with the stack trace, which is translated to the following when using the debug version:

Cannot read property getCode() of null

Is there a way to get the actual error and not one in just plain text?


No, OpenLayers only checks for and gives meaningful messages for a few specific errors https://openlayers.org/en/latest/doc/errors/ and trying to use a projection which hasn't been defined and registered in proj4 isn't one of those.

If you are using a source with unknown projections you could try obtaining the projection from the parser

  var parser = new WMTSCapabilities();
  fetch(url).then(function(response) {
    return response.text();
  }).then(function(text) {
    var result = parser.read(text);

then dynamically load the projection definition as in the OpenLayers example https://openlayers.org/en/latest/examples/reprojection-by-code.html before creating your layer

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.