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

279
Views
OpenLayers source.getExtent() / view.fit() does not show entire feature

Using OL 6.5.0, the following snippet produces a map where the feature goes outside of the bounds of the map, rather than being completely contained (with a 20px margin) within the bounds of the map.

const extent = layer.getSource().getExtent();

view.fit(extent, {
  size: map.getSize(),
  padding: [20, 20, 20, 20],
});

I tried setting nearest to true / false but the result is the same.

Result (ignore the fuzz):

out of bounds

I expect the entire feature to be within the border of the map, but it is not. Am I missing something?

Expected (or close to it -- again, ignore the fuzz):

in bounds

Here's how I'm instantiating the map:

const map = this.map = maps[mapTargetId] = new ol.Map({
  target: mapTargetId,
  overlays: [overlay],
  layers: await this.getBaseLayers(),
  view: new ol.View({
    projection,
    center: [0, 0],
    zoomFactor: 2,
    zoom: defaultZoom,
    minZoom: 1,
    maxZoom: 12,
  })
});
about 4 years ago · Juan Pablo Isaza
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!