Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
openlayers 6 map getview fit zooms out on every refresh

Im using openlayers 6, on mounted I use map().getView().fit(extent) for some reason on every refresh the zoom level is higher. any tips how to fix this?

Before using .fit(extent) I have to transformExtent to change projection from 5514 to 3857

this.map().setView(new View({
  projection: 'EPSG:3857',
  center: fromLonLat([50.075710, 14.472606]),
  zoom: 10,
  enableRotation: false
}))
extent = transformExtent(extent, 'EPSG:5514', this.map().getView().getProjection().getCode())
this.map().getView().fit(extent)

before refresh: enter image description here

after refresh: enter image description here

my problem is with map.getview.fit here is my code and here are the returned values coordinates after view.fit are a bit different

  console.log(transformedExtent)
  this.map().getView().fit(transformedExtent, this.map().getSize())
  console.log(this.map().getView().calculateExtent(this.map().getSize()))

before fit:

  1. -27186.072153485078
  2. 6701982.491006854
  3. -5136.804165771885
  4. 6724373.669054876

after fit:

  1. -27186.072153485078
  2. 6701493.775314425
  3. -5136.804165771886
  4. 6724862.384747305
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are using the same variable for the EPSG:5514 and EPSG:3857 extents so presumably corrupting the original EPSG:5514 you want to use. Using a separate variable should solve the problem.

const transformedExtent = transformExtent(extent, 'EPSG:5514', this.map().getView().getProjection().getCode())
this.map().getView().fit(transformedExtent)
about 4 years ago · Juan Pablo Isaza Report

0

Asked about this problem directly on openlayers github and it is expected behavior. https://github.com/openlayers/openlayers/issues/13503

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!