From 2e55b5a70e7c03a338dd71acc415be461ecf0f71 Mon Sep 17 00:00:00 2001 From: Peter Bastiani Date: Mon, 28 Apr 2025 10:20:19 +0200 Subject: [PATCH] AW-3101 vnd.farmmaps.itemtype.shape.processed download as shape (zip) --- .../selected-item-geotiff.component.ts | 12 ++++-- .../selected-item-shape.component.html | 37 ++++++++++--------- .../selected-item-shape.component.ts | 33 ++++++++++++----- .../selected-item-temporal.component.ts | 27 ++++++++------ 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.ts b/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.ts index 26fa44a..f8efe38 100644 --- a/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.ts +++ b/projects/common-map/src/fm-map/components/selected-item-geotiff/selected-item-geotiff.component.ts @@ -1,8 +1,9 @@ import { Location } from '@angular/common'; -import { Component, Injectable } from '@angular/core'; +import { Component, Injectable, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; import { commonReducers, FolderService, IItem, IItemLinkType, ItemService, ItemTypeService, IUrlType } from '@farmmaps/common'; import { Store } from '@ngrx/store'; +import { Subscription } from 'rxjs'; import * as mapActions from '../../actions/map.actions'; import * as mapReducers from '../../reducers/map.reducer'; import { ForItemType } from '../for-item/for-itemtype.decorator'; @@ -16,12 +17,17 @@ import { AbstractSelectedItemComponent } from '../selected-item/selected-item.co templateUrl: './selected-item-geotiff.component.html', styleUrls: ['./selected-item-geotiff.component.scss'] }) -export class SelectedItemGeotiffComponent extends AbstractSelectedItemComponent { +export class SelectedItemGeotiffComponent extends AbstractSelectedItemComponent implements OnDestroy { + sub: Subscription; constructor(store: Store, public itemService: ItemService, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService) { super(store, itemTypeService,location,router); } + ngOnDestroy(): void { + if (this.sub) this.sub.unsubscribe(); + } + onLayerChanged(layerIndex: number) { this.store.dispatch(new mapActions.SetLayerIndex(layerIndex)); } @@ -34,7 +40,7 @@ export class SelectedItemGeotiffComponent extends AbstractSelectedItemComponent event.stopPropagation(); event.preventDefault(); const itemLink : IItemLinkType = {itemcode:item.code,query:`layer=${this.layer(layers,layerIndex).name}`,pathsuffix:"download", validminutes:10} - const foo = this.itemService.getItemLink(itemLink).subscribe((itemLinkUrl:IUrlType) => { + this.sub = this.itemService.getItemLink(itemLink).subscribe((itemLinkUrl:IUrlType) => { window.location.href = itemLinkUrl.url; }) } diff --git a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html index 6475704..da0eec1 100644 --- a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html +++ b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.html @@ -7,25 +7,28 @@

{{parentItem.name}}

{{item.name}}

-
-
diff --git a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.ts b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.ts index bed1cf7..2a94c2f 100644 --- a/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.ts +++ b/projects/common-map/src/fm-map/components/selected-item-shape/selected-item-shape.component.ts @@ -1,14 +1,13 @@ -import { Component, Input, Injectable, OnInit } from '@angular/core'; import { Location } from '@angular/common'; -import { Feature } from 'ol'; +import { Component, Injectable, OnDestroy } from '@angular/core'; +import { Router } from '@angular/router'; +import { commonReducers, FolderService, IItem, IItemLinkType, ItemService, ItemTypeService, IUrlType } from '@farmmaps/common'; import { Store } from '@ngrx/store'; -import * as mapReducers from '../../reducers/map.reducer'; -import { commonReducers, ItemTypeService, IItem, Item, ItemService, FolderService, IListItem} from '@farmmaps/common'; import * as mapActions from '../../actions/map.actions'; -import { Router, ActivatedRoute, ParamMap, Event } from '@angular/router'; +import * as mapReducers from '../../reducers/map.reducer'; import { ForItemType } from '../for-item/for-itemtype.decorator'; import { AbstractSelectedItemComponent } from '../selected-item/selected-item.component'; -import { Observable } from 'rxjs'; +import { Subscription } from 'rxjs'; @ForItemType("vnd.farmmaps.itemtype.shape.processed") @@ -18,13 +17,18 @@ import { Observable } from 'rxjs'; templateUrl: './selected-item-shape.component.html', styleUrls: ['./selected-item-shape.component.scss'] }) -export class SelectedItemShapeComponent extends AbstractSelectedItemComponent { +export class SelectedItemShapeComponent extends AbstractSelectedItemComponent implements OnDestroy { + public selectedLayer = 0; + sub: Subscription; - constructor(store: Store, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService) { + constructor(store: Store, public itemService: ItemService, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService) { super(store, itemTypeService,location,router); } - public selectedLayer = 0; - + + ngOnDestroy(): void { + if (this.sub) this.sub.unsubscribe(); + } + onLayerChanged(layerIndex: number) { this.store.dispatch(new mapActions.SetLayerIndex(layerIndex)); } @@ -32,4 +36,13 @@ export class SelectedItemShapeComponent extends AbstractSelectedItemComponent { layer(layers:any,layerIndex:number) { return layers.find(l => l.index == layerIndex); } + + download(event:MouseEvent,item:IItem,layers:any,layerIndex:number) { + event.stopPropagation(); + event.preventDefault(); + const itemLink : IItemLinkType = {itemcode:item.code,query:`layer=${this.layer(layers,layerIndex).name}`,pathsuffix:"download", validminutes:10} + this.sub = this.itemService.getItemLink(itemLink).subscribe((itemLinkUrl:IUrlType) => { + window.location.href = itemLinkUrl.url; + }) + } } diff --git a/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.ts b/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.ts index 9179f22..3bdceaf 100644 --- a/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.ts +++ b/projects/common-map/src/fm-map/components/selected-item-temporal/selected-item-temporal.component.ts @@ -1,15 +1,15 @@ -import { Component, Injectable } from '@angular/core'; import { Location } from '@angular/common'; -import { Store } from '@ngrx/store'; -import * as mapReducers from '../../reducers/map.reducer'; -import { commonReducers, ItemTypeService, IItem, ItemService, IItemLinkType, IUrlType } from '@farmmaps/common'; +import { Component, Injectable, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; +import { commonReducers, IItem, IItemLinkType, ItemService, ItemTypeService, IUrlType } from '@farmmaps/common'; +import { Store } from '@ngrx/store'; +import { Subscription } from 'rxjs'; +import * as mapActions from '../../actions/map.actions'; +import { IItemLayer, ITemporalItemLayer } from '../../models/item.layer'; +import * as mapReducers from '../../reducers/map.reducer'; +import { TemporalService } from '../../services/temporal.service'; import { ForItemType } from '../for-item/for-itemtype.decorator'; import { AbstractSelectedItemComponent } from '../selected-item/selected-item.component'; -import { ITemporalItemLayer} from '../../models/item.layer'; -import * as mapActions from '../../actions/map.actions'; -import { IItemLayer } from '../../models/item.layer'; -import {TemporalService} from '../../services/temporal.service'; @ForItemType("vnd.farmmaps.itemtype.temporal") @Injectable() @@ -18,11 +18,16 @@ import {TemporalService} from '../../services/temporal.service'; templateUrl: './selected-item-temporal.component.html', styleUrls: ['./selected-item-temporal.component.scss'] }) -export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent { +export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent implements OnDestroy { + sub: Subscription; constructor(store: Store, public itemService: ItemService, itemTypeService: ItemTypeService, location: Location, router: Router,public temporalService:TemporalService) { super(store, itemTypeService,location,router); } + + ngOnDestroy(): void { + if (this.sub) this.sub.unsubscribe(); + } onLayerChanged(layerIndex: number) { this.store.dispatch(new mapActions.SetLayerIndex(layerIndex)); @@ -32,8 +37,6 @@ export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent return (this.itemLayer as ITemporalItemLayer)?.selectedItemLayer } - - handleNextTemporal(event:MouseEvent) { this.store.dispatch(new mapActions.NextTemporal()); event.preventDefault(); @@ -65,7 +68,7 @@ export class SelectedItemTemporalComponent extends AbstractSelectedItemComponent event.stopPropagation(); event.preventDefault(); const itemLink : IItemLinkType = {itemcode:item.code,query:`layer=${this.layer(layers,layerIndex).name}`,pathsuffix:"download", validminutes:10} - const foo = this.itemService.getItemLink(itemLink).subscribe((itemLinkUrl:IUrlType) => { + this.sub = this.itemService.getItemLink(itemLink).subscribe((itemLinkUrl:IUrlType) => { window.location.href = itemLinkUrl.url; }) }