|
@@ -4,18 +4,20 @@ import {
|
|
|
ViewRef
|
|
ViewRef
|
|
|
} from '@angular/core';
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
-import {EventsKey} from 'ol/events'
|
|
|
|
|
import ExtentIteraction, { ExtentEvent } from 'ol/interaction/Extent'
|
|
import ExtentIteraction, { ExtentEvent } from 'ol/interaction/Extent'
|
|
|
import { shiftKeyOnly } from 'ol/events/condition';
|
|
import { shiftKeyOnly } from 'ol/events/condition';
|
|
|
import {
|
|
import {
|
|
|
- Extent,
|
|
|
|
|
|
|
+ Extent,
|
|
|
getArea
|
|
getArea
|
|
|
} from 'ol/extent'
|
|
} from 'ol/extent'
|
|
|
|
|
|
|
|
|
|
+import checkDescription from 'iroha-helpers'
|
|
|
|
|
+
|
|
|
import {
|
|
import {
|
|
|
HsMapService,
|
|
HsMapService,
|
|
|
HsPanelComponent,
|
|
HsPanelComponent,
|
|
|
- HsLayoutService
|
|
|
|
|
|
|
+ HsLayoutService,
|
|
|
|
|
+ getAccessRights
|
|
|
} from 'hslayers-ng';
|
|
} from 'hslayers-ng';
|
|
|
|
|
|
|
|
import { BcInfoService } from './bc-info.service';
|
|
import { BcInfoService } from './bc-info.service';
|
|
@@ -28,6 +30,7 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
private extentIteraction: ExtentIteraction;
|
|
private extentIteraction: ExtentIteraction;
|
|
|
|
|
|
|
|
selectingArea: boolean = false;
|
|
selectingArea: boolean = false;
|
|
|
|
|
+ buyInProgress: boolean = false;
|
|
|
|
|
|
|
|
user: string = 'kunickyd@test';
|
|
user: string = 'kunickyd@test';
|
|
|
assetId: string = "coin#test"
|
|
assetId: string = "coin#test"
|
|
@@ -35,6 +38,8 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
userBalance: number;
|
|
userBalance: number;
|
|
|
extent: Extent;
|
|
extent: Extent;
|
|
|
price: number;
|
|
price: number;
|
|
|
|
|
+ paymentHash: string;
|
|
|
|
|
+ dataUrl: string;
|
|
|
|
|
|
|
|
viewRef: ViewRef;
|
|
viewRef: ViewRef;
|
|
|
data: any;
|
|
data: any;
|
|
@@ -46,9 +51,17 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
private hsLayoutService: HsLayoutService
|
|
private hsLayoutService: HsLayoutService
|
|
|
) {
|
|
) {
|
|
|
this.extentIteraction = new ExtentIteraction({ condition: shiftKeyOnly });
|
|
this.extentIteraction = new ExtentIteraction({ condition: shiftKeyOnly });
|
|
|
|
|
+
|
|
|
|
|
+ //bind event handlers to this scope
|
|
|
|
|
+ this.onMouseUp = this.onMouseUp.bind(this);
|
|
|
|
|
+ this.onExtentChanged = this.onExtentChanged.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit(): Promise<void> {
|
|
async ngOnInit(): Promise<void> {
|
|
|
|
|
+ await this.refreshUserBalance();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async refreshUserBalance(): Promise<void>{
|
|
|
this.userBalance = await this.bcInfoService.getUserBalance(this.user, this.userPrivateKey, this.assetId);
|
|
this.userBalance = await this.bcInfoService.getUserBalance(this.user, this.userPrivateKey, this.assetId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -61,19 +74,33 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
|
|
|
|
|
this.selectingArea = true;
|
|
this.selectingArea = true;
|
|
|
|
|
|
|
|
- map.getTargetElement().addEventListener("mouseup", this.onMouseUp.bind(this));
|
|
|
|
|
- this.extentIteraction.on("extentchanged", this.onExtentChanged.bind(this));
|
|
|
|
|
|
|
+ map.getTargetElement().addEventListener("mouseup", this.onMouseUp);
|
|
|
|
|
+ this.extentIteraction.on("extentchanged", this.onExtentChanged);
|
|
|
|
|
|
|
|
map.addInteraction(this.extentIteraction);
|
|
map.addInteraction(this.extentIteraction);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onCancel(): void{
|
|
|
|
|
|
|
+ async onBuy(): Promise<void> {
|
|
|
|
|
+ if(!confirm("You sure?")){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.buyInProgress = true;
|
|
|
|
|
+
|
|
|
|
|
+ this.paymentHash = await this.bcInfoService.transferAssets(this.user, this.userPrivateKey, this.assetId, this.extent, this.price);
|
|
|
|
|
+ this.refreshUserBalance();
|
|
|
|
|
+ this.dataUrl = "https://eo.lesprojekt.cz/produkty/S2/2020/S2A_MSIL2A_20200422T095031_N9999_R079_T33UXQ_20201127T165009_NDVI.tif" //await this.bcInfoService.requestData(this.paymentHash, this.user);
|
|
|
|
|
+
|
|
|
|
|
+ this.buyInProgress = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onCancel(): void {
|
|
|
let map = this.mapService.getMap();
|
|
let map = this.mapService.getMap();
|
|
|
|
|
|
|
|
- this.extent = this.price = null;
|
|
|
|
|
- this.extentIteraction.setExtent(null);
|
|
|
|
|
-
|
|
|
|
|
- map.getTargetElement().removeEventListener("mouseup", this.onMouseUp);
|
|
|
|
|
|
|
+ this.extent = this.price = this.paymentHash = this.dataUrl = null;
|
|
|
|
|
+ this.extentIteraction.setExtent(null);
|
|
|
|
|
+
|
|
|
|
|
+ map.getTargetElement().removeEventListener("mouseup", this.onMouseUp); //This doesnt seem to work...
|
|
|
this.extentIteraction.un("extentchanged", this.onExtentChanged);
|
|
this.extentIteraction.un("extentchanged", this.onExtentChanged);
|
|
|
|
|
|
|
|
map.removeInteraction(this.extentIteraction);
|
|
map.removeInteraction(this.extentIteraction);
|
|
@@ -81,14 +108,30 @@ export class BcInfoComponent implements HsPanelComponent, OnInit {
|
|
|
this.selectingArea = false;
|
|
this.selectingArea = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async onMouseUp(event): Promise<void>{
|
|
|
|
|
- console.log("up");
|
|
|
|
|
|
|
+ async onMouseUp(event): Promise<void> {
|
|
|
if (this.extent) {
|
|
if (this.extent) {
|
|
|
- this.price = await this.bcInfoService.getPrice(getArea(this.extent));
|
|
|
|
|
|
|
+ this.price = this.roundTwoDecimalPlaces(await this.bcInfoService.getPrice(getArea(this.extent))); //round the price => allow more decimal places in iroha?
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- onExtentChanged(event: ExtentEvent): any{
|
|
|
|
|
- this.extent = event.extent
|
|
|
|
|
|
|
+ onExtentChanged(event: ExtentEvent): any {
|
|
|
|
|
+ if(event.extent){
|
|
|
|
|
+ this.extent = this.roundExtentCoords(event.extent); //!! workaround for fixed description length to 64 chars in iroha-helpers !!
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //UTILS SECTION - should be separeted in solo file
|
|
|
|
|
+ private roundExtentCoords(extent: Extent): Extent{
|
|
|
|
|
+ let roundedExtent: number[] = new Array<number>(4);
|
|
|
|
|
+
|
|
|
|
|
+ for(let i = 0; i !== extent.length; i++ ){
|
|
|
|
|
+ roundedExtent[i] = this.roundTwoDecimalPlaces(extent[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return roundedExtent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private roundTwoDecimalPlaces(num: number): number{
|
|
|
|
|
+ return Math.round((num + Number.EPSILON) * 100) / 100;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|