Comments (7)
apply()
was meant to be simple, and was designed to return an OpenLayers map instance. If we'd return a promise, when should it be resolved? When all layers have been added to the OpenLayers map? When all layers have sources? When all layers have loaded source metadata? When the map has completed rendering all data for the first time? There does not seem to be a straightforward answer.
What would be your use case, or when would you consider a promise returned by apply()
resolved?
from ol-mapbox-style.
I would consider the apply()
promise resolved when all promises created by the package are resolved. To me, it seems straightforward that the package would expose all promises created by it.
From what I can tell so far, this would mean resolution when all layers have sources by any means, which yes, would mean that the promise may block until the user manually adds sources. Maybe this would cause too many support issues with users not understanding the possibility of blocking?
I'm trying to use OpenLayers 5 with React. Reconciling two different event management paths is tricky, or at least annoying. When I add ol-mapbox-style to the mix, using apply()
on an existing map, there's no hook for me to tell React to re-render, and a promise returned from apply()
seemed an obvious solution.
What about an intermediate function like applyToExistingMap()
which could return a promise, and then apply()
could call it and just not return the promise, to preserve the existing API. According to StackOverflow, if there's no reference to the promise, it'll get garbage collected, even if still pending.
BTW, ol-mapbox-style is awesome, and exactly what I need. Thank you! I'm hoping to be able to contribute back any enhancements I end up needing to make, so I am happy to take direction.
from ol-mapbox-style.
Your suggestion to resolve the promise when all promises created by the package are resolved makes sense. Regarding API, apply()
could have 2 flavors:
- When called with an
ol/Map
instance as 1st argument, it returns a promise. - When called with a
string
orHTMLElement
for a map container as 1st argument, it returns theol/Map
instance it created.
This would still be a breaking change, but not sacrifice simplicity for users that call apply()
with a map container reference.
If you're willing to work in that direction, that would be a welcome improvement.
from ol-mapbox-style.
I'm starting to write more specific tests for applyStyle()
to get a better feel for the codebase. The onChange()
method in applyStyle()
is written to only apply styles to VectorLayer
and VectorTileLayer
or fail silently. It's odd because the style
variable is declared undefined, and checked in onChange()
, but there's nothing else in the function, or anywhere in index.js
that sets it other then inside onChange()
. If I reject instead of silently ignore, tests for handling raster sources and layers start failing.
Is this an oversight or intentional? Is there a reason it should silently fail, like it doesn't matter for some reason, and isn't really an error? I have basically no experience with map stuff and the geologist I'm doing this with is in another timezone with 3 kids, and information transfer between us isn't very good, so apologies if this is a map-related rank amateur question.
var spriteScale, spriteData, spriteImageUrl, style;
function onChange() {
if (!style && (!glStyle.sprite || spriteData)) {
if (layer instanceof VectorLayer || layer instanceof VectorTileLayer) {
style = applyStyleFunction(layer, glStyle, source, resolutions, spriteData, spriteImageUrl, getFonts);
}
resolve();
} else if (style) {
layer.setStyle(style);
}
}
from ol-mapbox-style.
Thanks for digging into this. The confusion comes from the fact that the applyStyle
function is only meant to be used with Vector
and VectorTile
layers (as stated in the documentation).
The promise should be immediately rejected (right at the beginning of the function) when applyStyle
is called with a layer that is not Vector
or VectorTile
.
from ol-mapbox-style.
Ok. Adding that makes these existing tests fail:
https://github.com/boundlessgeo/ol-mapbox-style/blob/a6ddc765b0415d212966c00cae8490378d5b981c/__tests__/test.js#L71
https://github.com/boundlessgeo/ol-mapbox-style/blob/a6ddc765b0415d212966c00cae8490378d5b981c/__tests__/test.js#L136
https://github.com/boundlessgeo/ol-mapbox-style/blob/a6ddc765b0415d212966c00cae8490378d5b981c/__tests__/test.js#L186
I'll operate on the assumption that applyStyle()
just shouldn't be called for raster layers in the first place, since they don't take styles anyway.
from ol-mapbox-style.
I'll operate on the assumption that
applyStyle()
just shouldn't be called for raster layers in the first place, since they don't take styles anyway.
Correct. Thanks!
from ol-mapbox-style.
Related Issues (20)
- Requests to third-party server for fonts HOT 8
- issue with standalone example using recent versions of olms (METERS_PER_UNIT error) HOT 1
- applyBackground issue HOT 3
- line-pattern webgl HOT 3
- Provide a default URL template for fonts when 'ol:webfonts' not available HOT 1
- Issue rendering fill layers above symbol layers HOT 2
- 加载mapboxgl的样式时文本标签显示错乱 HOT 1
- Maybe a bug in stylefunction HOT 2
- Vector tile layer with MVT format clip circle style HOT 6
- color2 is null loading outdoor-v2 HOT 1
- Example of using a styled Esri vector tiles basemap (but not as the whole map) HOT 1
- Text-Allow-Overlap and Declutter issues. HOT 6
- Incorrect Tiles being requested for projections other than Web Mercator (EPSG:3857) HOT 2
- render vector tiles offline, or render vector tiles to raster for later offline use? HOT 3
- Applying style to VectorTile layer HOT 2
- Displaying symbols from sprites HOT 6
- fill-pattern position bug HOT 2
- Security: Remove Links to Polyfill.io HOT 1
- missing icon-text-fit property HOT 2
- Declutter of labels in vector tiles HOT 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ol-mapbox-style.