-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Simplify LayersService.addLayer #74
Comments
There is just a really tiny thing I'd like to also do here: rename |
Yes you are completely right! Personally I would like to refactor the complete I also would like to make the Store more dynamic, so yo can add as much types of layers like you want. In regards to |
Awesome, thanks! I'll create a PR as soon as I can (hopefully this week). |
As @boeckMt mentioned, initially we had something like addLayer and addLayergroup... maybe it was intention to keep it in one method and use this option. In the fact we never used... i think I agree, it's already time to refactor LayerService. Maybe we could keep old methods which would probably call the new ones internally and mark them as deprecated for a while. This way we may reduce impact of breaking changes |
Ideas for Refactoring:
// layers.service.ts
private updateLayerOrGroupInStore(layerOrGroup: Layer | LayerGroup) {
this.store.getValue().filter((lg, index, array) => {
+ if (lg instanceof Layer && lg.id !== layerOrGroup.id) {
+ lg.updated = false;
+ }
+ if (lg instanceof LayerGroup && lg.id !== layerOrGroup.id) {
+ lg.layers.forEach(l => l.updated = false);
+ }
// check if both from the same type then check same id
if (lg instanceof Layer && layerOrGroup instanceof Layer) {
if (lg.id === layerOrGroup.id) {
array[index] = layerOrGroup;
this.store.next(array);
}
} else if (lg instanceof LayerGroup && layerOrGroup instanceof LayerGroup) {
if (lg.id === layerOrGroup.id) {
array[index] = layerOrGroup;
this.store.next(array);
}
}
});
+ // Do this afterwards, because referenced objects will be changed.
+ if (layerOrGroup instanceof Layer) {
+ layerOrGroup.updated = true;
+ }
+ if (layerOrGroup instanceof LayerGroup) {
+ layerOrGroup.layers.forEach(l => l.updated = true);
+ }
} // Layers.ts
export class Layer implements ILayerOptions {
...
+ updated: boolean = false;
...
} // layers.service.ts
+ public change = new Subject<'attribute' | 'order' | 'length'>()
+ // trigger change in add/Update/remove/set
constructor() {
}
+ private getLengthChange(items: Array<Layer | LayerGroup>) {
+ const oldItemsLength = this.getLayerGroupsCount();
+ // TODO: layers in group changed?
+ if (oldItemsLength !== items.length) {
+ return true;
+ } else {
+ const oldItemsFlatLength = this.getBaseLayersCount() + this.getLayersCount() + this.getOverlaysCount();
+ const newItemsFlat = this.flattenDeepArray(items);
+ if (oldItemsFlatLength !== newItemsFlat.length) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ private setStore(items: Array<Layer | LayerGroup>) {
+ const changeLength = this.getLengthChange(items);
+ if (changeLength) {
+ this.change.next('length');
+ }
+ this.store.next(items);
+ }
- this.store.next(...);
+ this.setStore(...);
public setLayerGroups(items: Array<Layer | LayerGroup>, filtertype?: TFiltertypes): Observable<Array<Layer | LayerGroup>> {
if (items.length > 0) {
...
+ const changeLength = this.getLengthChange(items);
+ if(!changeLength){
+ this.change.next('order');
+ }
if (!filtertype) {
... // layers.service.ts
public addLayerGroup(layergroup: LayerGroup, filtertype?: TFiltertypes) {
...
- // update to set visible -> do we need this really
- this.updateLayerGroup(layergroup);
}
}
|
Maybe we can check if some Observer utilities could help to synchronize updates to layers. |
Description
We're close to issuing a ukis-version 8.0. To this occasion, maybe cleaning up some places in the code could be useful.
Last time we did that, there were just too many changes coming together at once, so here I'll try to handle things on a small-issue basis, so that things don't go out of hand.
Concretely, here is a potential chance for some cleaning up: in the method
LayersService.addLayer
, to we still need thetoGroup
parameter?I don't really understand
toGroup
anyway. I don't think that this method does anything whentoGroup
is given!toGroups
in the libraries and couldn't find any. Neither was it used in any ukis-project that I've ever worked on. I'm almost positive that this option is no longer used.Relevant Package
This feature request is for @dlr-eoc/services-layers
The text was updated successfully, but these errors were encountered: