Comments (11)
Thanks @KyllianGautier, you are right. In #15843 I made it so the options and the layer have the same generics again - both the FeatureType
, no longer SourceType<FeatureType>
.
from openlayers.
@ahocevar thanks for this fix. I still have issue with typing in typescript :'(
I am able to give a TileLayer<TileSource>
as a Layer<Source, Renderer>
.
But I can't give a VectorLayer<FeatureLike>
as a Layer<Source, Renderer>
.
I'm sorry to disturbing you, but I don't find solution, and I don't know how to get the info to understand if I'm doing something wrong.
You can test a simple example of the typing problem in Typescript:
from openlayers.
@KyllianGautier You're still using the old type signature for the options. This should now be:
import { Feature as OLFeature } from 'ol';
import OLVectorLayer, { Options as OLVectorLayerOptions } from 'ol/layer/Vector.js';
import OLVectorSource from 'ol/source/Vector.js';
const options: OLVectorLayerOptions<OLFeature> = {
source: new OLVectorSource<OLFeature>()
};
export const layer = new OLVectorLayer(options);
from openlayers.
In #15869, the source type is added back as 2nd type parameter to vector and vectortile layers.
from openlayers.
@KyllianGautier The type of the Options has to include the source, because the options are used for several BaseVector layer subclasses. For the VectorLayer, the source type is determined and does not require generics for the source. Does this cause a real-life problem?
from openlayers.
@ahocevar Ok, I understand. I tryed to adapt, but I still have some very strange problems with the typing :
Here I created a factory to instantiate a VectorLayer:
(I prefix all Openlayers object by "OL" in my imports, I hope you can understand easily)
from openlayers.
Maybe you got some of the imports wrong? This works fine for me:
import { FeatureLike as OLFeatureLike } from 'ol/Feature.js';
import { Options as OLBaseVectorLayerOptions } from 'ol/layer/BaseVector.js';
import OLVectorLayer from 'ol/layer/Vector.js';
import OLVectorSource from 'ol/source/Vector.js';
export const vectorLayer = <F extends OLFeatureLike>(options?: OLBaseVectorLayerOptions<OLVectorSource<F>>) => new OLVectorLayer<F>(options);
from openlayers.
@ahocevar Unfortunately, I have errors in typescript trying your solution:
But this works fine in javascript indeed
from openlayers.
I am able to give a TileLayer as a Layer<Source, Renderer>.
Yes, but you don't need to specify the Renderer
type. And other than the Vector and VectorTile sources, TypeScript needs to distinguish between the different ol/layer/Tile
subclasses here, because subclasses have additional API methods.
But I can't give a VectorLayer as a Layer<Source, Renderer>.
Correct, that's no longer the type signature.
You can test a simple example of the typing problem in Typescript:
export const vectorLayer: OLVectorLayer<OLFeatureLike> = new OLVectorLayer<OLFeature>();
That's also expected. There is no inheritance relationship between the allowed types of FeatureLike
. Feature
and RenderFeature
only have a small subset of a common API. So in TypeScript, you have to decide when you declare the variable what you're going to store there. When using JavaScript, the correct type will be inferred. The following will work in TypeScript:
export const vectorLayer: OLVectorLayer<OLFeature> = new OLVectorLayer<OLFeature>();
from openlayers.
Thanks for the details. I tried what you proposed, and I still have issues in Typescript:
And I tried to change the type of for options and source:
from openlayers.
@ahocevar Ok, problem solved, thanks for the support.
I have an additional question about the Layer.getSource() method. How can we type the source returned by a VectorLayer ?
If I use a Custer source for example, I instantiate a VectorLayer with this Cluster source, and i'm not able to use the Cluster source specific methods such as setDistance() or setMinDistance():
Other side effect, it seems that a VectorLayer with an other source than a Vector source is not assiciable with a Layer ?
from openlayers.
Related Issues (20)
- Draw lines rendered with WebGL中使用stroke-pattern-offset属性
- After interpolate is set to true, there are still curved teeth when loading cogtif HOT 1
- Bug HOT 1
- Stroke and Fill style does not declutter when used with Circle style. HOT 7
- COG Data Problem on High Resolution HOT 1
- @mike-000 你好 我按照上述方法 添加了个 额外的 baiduG 的坐标系,并且在初始化 view的时候 使用的是BD09G, 现在遇到一个问题 我们在缩放或者移动地图的时候 会出现 空白区域,且我看了network下瓦片请求没有出现404或者异常的情况。但当我们将view下使用的坐标系改成 BD09 则不会有此问题 。我观察了 BD09与BD09G的差异 就在与 global 配置。 请问出现这种情况 有合适的解决方案嘛 ? HOT 1
- SourceInfo parameters are applied to converted image (not source) when using `convertToRGB` in `GeoTIFF`
- the overlay dom z-index can not be bigger than a common dom outside openlayer HOT 1
- Feature collection disordered after having drawn a specifing number of features or vertices HOT 3
- VectorImage type declaration errors HOT 5
- Map Not Loading in Grafana Panel Edit Mode
- Use SVG transitions in Icons HOT 2
- webgl memory leak HOT 1
- Examples don't display correctly OOTB in a web browser
- layerState is undefined in inView function HOT 1
- Idea: Make clustering more configurable HOT 4
- Small improvement in ol.interaction.DragAndDrop HOT 1
- OpenLayers unable to render Float32 GeoTiff HOT 4
- tileGrid key is not an available option in OGCVectorTile HOT 1
- WFS#writeTransaction() fails for undefined properties
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 openlayers.