2

I search a lot about this problem but I don't find a solution, so... I'm using a projection and the scaleLine display the value 100.000 greater than the real value, How can I solve this problem?

Here my OpenLayers 4 code:

Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs";

var projection = new ol.proj.Projection({
code: 'EPSG:27700',
units: 'm'
});

controls: ol.control.defaults({
  attributionOptions: ({
  collapsible: false
  })
}).extend([
  // add the actual scale in "m"
  new ol.control.ScaleLine({units:'metric', target: 
document.getElementById('map_extras')})
]),
layers: [layers, orders],
target: 'mapdiv',
view: new ol.View({
projection: projection,
    center: ol.proj.fromLonLat([parseInt(setPos[0]), parseInt(setPos[1])], projection),
resolution: 2.8,
resolutions: [2.8, 1.4, 0.7, 0.28, 0.14, 0.07],
})

Also, something that I saw is when you move the map in x y axis the scaleLine sometimes changes without modifying the actual zoom, is this also a common problem when you are using a projection?

4

Solution direct from the owner of OL4.

All you have to do is configure the projection with a custom getPointResolution function:

var projection = new ol.proj.Projection({ code: 'EPSG:27700', getPointResolution: function(r) { return r; }, units: 'm' });

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.