Open MichaelLangbein opened 2 years ago
Creating instances and Shallow-cloning objets is a different thing which should not be mistaken.
But yes we could check this on add Layer, and give hint like ... is not an instance of Layer
Also in my VS Code I get the hint
Argument of type '{ type: TRasterLayertype; url: string; subdomains?: string[]; params?: IRasterLayerParams; tileSize?: number; name: string; id: string; opacity: number; visible: boolean; ... 20 more ...; cssClass?: string; }' is not assignable to parameter of type 'Layer'. Property 'time' is missing in type '{ type: TRasterLayertype; url: string; subdomains?: string[]; params?: IRasterLayerParams; tileSize?: number; name: string; id: string; opacity: number; visible: boolean; ... 20 more ...; cssClass?: string; }' but required in type 'Layer'.
So I can't add the layer.
Feel free to do a PR :)
This could be somewhere in isInLayergroups
because this function is called before add Layer or Group.
public isInLayergroups(layergroup: Layer | LayerGroup | string, groups?: Array<Layer | LayerGroup>): boolean{
...
if (layergroup instanceof Layer || layergroup instanceof LayerGroup) {
id = layergroup.id;
} else {
id = layergroup;
}
...
}
I can't remember why we allowed to add strings here... If we remove it we could use the else for this check.
We could also use this opportunity to do https://github.com/dlr-eoc/ukis-frontend-libraries/issues/74
FYI @voinSR @Stef-Firestone @lucas-angermann
Description
Consider this case:
This causes an error:
This error is thrown because
updateLayer
callsisInLayergroups
which checks if the passed layer is an instance of LayerSince
layer2
was created using object-spread, it does not pass this test.addLayer
is actually an instance ofLayer
addLayer
and not just atupdateLayer
, delivers more immediate feedback to the user that the passed data does not contain all the information that Ukis requires.Relevant Package
This feature request is for @dlr-eoc/services-layers
Describe alternatives you've considered
Layer
objects into actual instances ofLayer
in the background. But that would make Ukis harder to understand and encourage passing badly formatted data.instanceof
but rather ducktyping by only checking if the immediately required attributes are present. But that would either lead to yet more checks or to more runtime-errors.