Skip to content

Commit

Permalink
Add back function to set timeExtent to all layers in map
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasstein committed May 13, 2024
1 parent d31c532 commit 79446f7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/js/bundles/dn_timeslider/TimeSliderWidgetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class TimeSliderWidgetController {
private timeSliderWidget: any = undefined;
private initialTimeExtent: any = undefined;
private labelFormatFunction: any = undefined;
private timeExtentWatcher: any = undefined;
private _mapWidgetModel: InjectedReference<MapWidgetModel>;

public activate(): void {
Expand All @@ -52,14 +53,20 @@ export default class TimeSliderWidgetController {
public onToolActivated(): void {
this.getView().then((view: __esri.View) => {
view.timeExtent = this.timeSliderWidget.timeExtent;
this.changeAllLayerTimeExtents(view.timeExtent);
if (this._properties.playOnStartup) {
this.timeSliderWidget.play();
}
this.timeExtentWatcher = this.timeSliderWidget.watch("timeExtent", (value: __esri.TimeExtent) => {
this.changeAllLayerTimeExtents(value);
});
});
}

public onToolDeactivated(): void {
this.timeSliderWidget.stop();
this.timeExtentWatcher.remove();
this.resetAllLayerTimeExtents();
this.resetTimeExtent();
}

Expand Down Expand Up @@ -268,6 +275,35 @@ export default class TimeSliderWidgetController {
return stops;
}

private changeAllLayerTimeExtents(timeExtent: __esri.TimeExtent) {
const mapWidgetModel = this._mapWidgetModel;
const map = mapWidgetModel.map;
const layers = map.layers;
const flattenLayers = this.getFlattenLayers(layers);
flattenLayers.forEach((layer) => {
if (layer.useViewTime) {
if (layer.timeExtent && !layer._initialTimeExtent) {
layer._initialTimeExtent = layer.timeExtent;
}
layer.timeExtent = timeExtent;
}
});
}

private resetAllLayerTimeExtents() {
const mapWidgetModel = this._mapWidgetModel;
const map = mapWidgetModel.map;
const layers = map.layers;
const flattenLayers = this.getFlattenLayers(layers);
flattenLayers.forEach((layer) => {
layer.timeExtent = layer._initialTimeExtent;
});
}

private getFlattenLayers(layers: __esri.Collection<__esri.Layer>) {
return layers.flatten(item => item.layers || item.sublayers);
}

private getView(): Promise<__esri.View> {
const mapWidgetModel = this._mapWidgetModel;
return new Promise((resolve) => {
Expand Down

0 comments on commit 79446f7

Please sign in to comment.