question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to fit view from extents?

See original GitHub issue

Hi, two stage problem.

  1. If I have working features and then try to wrap them in a vectorsource, the features disappear:
    // Add marker for vehicle
    vl-layer-vector
      vl-source-vector(ref="vmarkers")
        vl-feature(:id="'v_' + api" v-for="(data, api) in navSatFixData" :key="'v_' + api")
          vl-geom-point(v-if="data && 'longitude' in data" :coordinates="[data.longitude, data.latitude]")
          vl-style-box
            vl-style-circle(:radius="api == activeApi ? 6 : 4")
              vl-style-fill(:color="apis[api]['color-dark']")
              vl-style-stroke(color="#666666" :width="api == activeApi ? 2 : 1")
  1. I would then like to use the vectorsource to determine the boundaries and zoom to autofit all the markers into view:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fnoopcommented, Jan 19, 2019

Just as a followup for anyone who comes across this, the fiddle above uses a 1 second timeout to hopefully wait for the layer features to be fully created on mount but that’s not always the case, and then you get an extents error from openlayers (https://openlayers.org/en/v5.3.0/doc/errors/#25). Instead I use a watcher on my coordinates variable, and also specifically test to make sure the extent is valid:

          // Fetch extents of the vector source layer
          this.viewExtents = this.$refs.vectorSource.$source.getExtent()
          // If there is a finite extent, then fit the view
          if (!this.viewExtents.includes(Infinity)) {
            this.$refs.mapView.$view.fit(this.viewExtents, {
              size: this.$refs.map.$map.getSize(),
              duration: 1000
            })
          }

There are probably lots of ways to do this though.

1reaction
ghettovoicecommented, Jan 15, 2019

Hi @fnoop , as for the first problem I have no idea why features are disappear. Can you provide test app that reproduces this behavior?

The second issue: not all methods of the openlayers are implemented in vuelayers components, but you can use original methods from ol object instance.
For vl-source-* components:

// this.$refs.mySource.$source - ol.source.Source
this.$refs.mySource.$source.getExtent()

Take a look for this fiddle https://jsfiddle.net/ghettovoice/br84dgq2/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fit map view to a layer extent in OpenLayers5?
This was as easy as: const markerSource = new source.Vector(); //... map.getView().fit(markerSource.getExtent());.
Read more >
Customizing your map extent—ArcMap | Documentation
A map extent defines the geographic boundaries for displaying GIS information within a data frame. These boundaries contain top, bottom, left, ...
Read more >
View is automatically zoomed to extents in AutoCAD
From the UCS Manager, Settings tab, toggle the setting "Save UCS with viewport" (system variable: UCSVP).
Read more >
camera zoom extents to fit - CGTalk - CGSociety
Hi.all I have search internet about camera zoom extents. but no good answer. so ... this just let object can in center of...
Read more >
OpenLayers 4 - fit to extent of selected features - Stack Overflow
extent.extend(extent, feature.getGeometry().getExtent(); } map.getView().fit(extent ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found