Openlayers: ol.control.ScaleLine regression with EPSG:4326

Created on 11 Jan 2018  路  4Comments  路  Source: openlayers/openlayers

I have a map with projection: 'EPSG:4326'. In v4.5.0, ol.control.ScaleLine seems to work. this codepen with v4.5.0 shows the initial value of the scale line = 5,000 km. At maximal zoom, I see the scale line reports 50mm ~(although this seems to be reported at max zoom regardless of latitude)~.

A fork of that codepen using v4.6.0 shows the initial value of the scale line = 500,000,000km. At maximal zoom, I see the scale line reports 5km (regardless of latitude). I also see the same behavior when using v4.6.4.

v4.6.4 seems to work as expected if I comment out these lines from #7462:

 if (units != ol.control.ScaleLineUnits.DEGREES) {
    pointResolution *= projection.getMetersPerUnit();
  }
pull request accepted

Most helpful comment

Such a change would make sense to me. Can you create a pull request please?

All 4 comments

A little history I found:

  1. #7087 added variable scale depending on latitude for EPSG:4326
  2. It seems #7087 introduced a regression for some users. See #7309, where scaleLine values were wrong for certain projections (such as EPSG:27700, which is reported in meters)
  3. #7462 attempted to fix this, but introduced a regression for maps having projection: 'EPSG:4326' (aka this issue)

Should the conditional on src/ol/control/ScaleLine.js#180 be more complex, something like the following?

  if (projection.units == ol.proj.Units.METERS && units == ol.control.ScaleLineUnits.METRIC) {
    pointResolution *= projection.getMetersPerUnit();
  }

Such a change would make sense to me. Can you create a pull request please?

For people wanting to fix this in v4.6.5 you can't follow this PR. Unfortunatly its for v5.* so you can't just copy paste it.

This should replace the condition used on line 180 in scaleline.js

The exact fix is :
```js
if (projection.getUnits() != _ol_control_ScaleLineUnits_.DEGREES &&
units == ol_control_ScaleLineUnits_.METRIC)
pointResolution *= projection.getMetersPerUnit();

Was this page helpful?
0 / 5 - 0 ratings