简体   繁体   中英

Openlayers map scale line same zoom rate repeated twice in metric even-though the zoom differs

Openlayers Map scale line in Metric unit has a particular zoom rate repeated twice on zoom eventhough the actually zoom-in resolution differs in map.

https://openlayers.org/en/latest/examples/scale-line.html As you can see in the link the zoom rates 5km and 5m are repeated twice for two different zoom levels

How i declared my zoom rates in view.

var viewLayer = new ol.View({
            center: [0, 0],
            zoom: 10,
            minZoom: 15,
            maxZoom: 24,
            resolution: 0.2,
            minResolution: 0.0125,
            maxResolution: 6.4
        });

Scale line control declaration as

var scaleLineControl = new ol.control.ScaleLine({
            minWidth: 100,
            units: 'metric'
        });

With the above declaration ranging from 1000m to 1m - 5m is repeated twice in metric unit

To avoid duplicates you must use a resolutions array to match the scale line intervals

The scale line intervals are fixed like this

5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5, 2, 1

If you don't use a resolutions array OpenLayers fixes the rsolutions at even intervals between the min and max, for example

4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1

so (in that case) you would have two resolutions which fit between 2000 and 5000 on the scale line

You can give resolutions array to your view . Note that, as said in the documentation :

If set the maxResolution, minResolution, minZoom, maxZoom, and zoomFactor options are ignored

But this is not really clean since you will need to give resolutions with large step in order to avoid scaleline values to be the same on zoom.

Actually this is intended to work like this for readability reasons. Values are the same but scale line width isn't, so it's not really a probleme right ?

Also a mix between resolutions passed to the view and minWidth for the scaleline should do the job, but again, it will be just home made hacks, theis is no kind of parameters in OpenLayers-5 to achieve exactly what you want to do !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM