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.

I’m wondering if it would be a useful feature to be able to construct a map without a view and to have the view auto-generated based on layer or source information. For example, a GeoTIFF source may provide metadata on view-related properties like projection and extent.

To create a map that would show an entire GeoTIFF, we could make it possible to do this:

const layer = new TileLayer({
  source: new GeoTIFF({
    sources: [{url: 'https://example.com/cog-1.tif'}],
  }),
});

// map with no view will get one when information is available
const map = new Map({
  target: 'map',
  layers: [layer],
});

Then to later switch the view to render a different source, the application could do this:

map.setView(null);

// this will eventually provide the map with a new view
layer.setSource(
  new GeoTIFF({
    sources: [{url: 'https://example.com/cog-2.tif'}],
  })
);

Before discussing details of the implementation, it would be good to decide whether this would be a worthwhile feature. I can imagine it would be useful in situations where someone wants to build an application that lets users browse through a catalog of imagery (that would be rendered as a single layer on a map).

In terms of the implementation, I can imagine making it so that a map without a view listens (once) for a new “viewready” type event. In the example above, this event would be fired by the source and relayed through the layer to the map.

I’m curious to hear others’ thoughts.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
tschaubcommented, Sep 6, 2021

I don’t think it necessarily makes sense to add in any loading indicator/animation – we don’t do this currently for sources that are not immediately “ready.” If someone wanted to add a loading indicator, this could be handled at the application level (maybe in a listener for “rendercomplete”).

I also don’t think I’ll start with “guess” or “auto” or any other view property. Instead, I’d like to make it just work if you configure a map like this:

const map = new Map({
    target: 'map',
    layers: [layer],
});

That would generate a map that rendered the full extent of the configured layer – in cases where either the layer or its source could provide enough information to construct a view. From a newcomer’s perspective, I think this makes it easier than having to discover something like view: 'auto'.

I’ll put together an implementation of what I have in mind. We can discuss the details there.

1reaction
tschaubcommented, Sep 21, 2021

After some offline discussion, we decided to go with a promise-based approach. This is a bit more explicit and shouldn’t include any surprises.

The GeoTIFF source (and in the future others that can resolve view properties) has a new source.getView() method. This method returns a promise for view properties – not a view itself but an object that can be passed to the view constructor. The map constructor’s view option now accepts a promise for view properties. And map.setView() accepts the same.

To construct a map with a view that shows the full extent of a GeoTIFF source, you can now do this:

const source = new GeoTIFF({
  sources: [{url: 'https://example.com/cog-1.tif'}],
});

const layer = new TileLayer({source});

// when the view resolves view properties, the map view will be updated
const map = new Map({
  target: 'map',
  layers: [layer],
  view: source.getView(), // <-- this is the new part
});

Then, if you want to later update the source of the layer and have the map view updated when the source resolves view properties, you can do this:

const newSource = new GeoTIFF({
  sources: [{url: 'https://example.com/cog-2.tif'}],
});

layer.setSource(newSource);

// this will eventually provide the map with a new view
map.setView(newSource.getView());

The COG examples have been updated to use this new functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autoview
Automate your trades with TradingView alerts.
Read more >
AutoView Online
This site provides comprehensive vehicle registrations data on a monthly basis that allows a user to view detailed new and used registrations.
Read more >
AUTO VIEW: home
Auto View is a small dealership located in the heart of Stoney Creek that launched in 2019 which started off with two employees...
Read more >
Auto View LLC | Better Business Bureau® Profile
This organization is not BBB accredited. Used Car Dealers in Tampa, FL. See BBB rating, reviews, complaints, & more.
Read more >
AUTO VIEW (@autoview_) • Instagram photos and videos
Sales-Consignment- Finance-Leasing -Cars-trucks-motorcycles-boats-Trailers/RV. Want to sell your Car? Call us ! Park&Sell with Auto View. · 949...
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