Auto view
See original GitHub issueI’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:
- Created 2 years ago
- Reactions:4
- Comments:11 (9 by maintainers)
Top GitHub Comments
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:
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.
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’sview
option now accepts a promise for view properties. Andmap.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:
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:
The COG examples have been updated to use this new functionality.