Refactor to fm-map-feature-thumbnail
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
<div *ngIf="feature;let feature" class="d-flex m-0">
|
||||
<div *ngIf="feature;let feature" class="d-flex m-0">
|
||||
<div class="p-2">
|
||||
<div #container class="thumbnail">
|
||||
<canvas #canvas ></canvas>
|
||||
</div>
|
||||
<div class="thumbnail">
|
||||
<fm-map-feature-thumbnail [feature]="feature"></fm-map-feature-thumbnail>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-grow p-2 overflow-hidden">
|
||||
<h1 class="card-title" title="{{feature.get('name')}}">{{feature.get('name')}}</h1>
|
||||
<div class="card-text"><span>{{areaInHa(feature)| number:'1.2-2'}} ha</span> <span>{{feature.get('cropTypeName')}}</span> </div>
|
||||
<div class="card-text"><span>{{feature.get('datadate')|date}}</span> - <span>{{feature.get('dataenddate')|date}}</span> </div>
|
||||
<div class="card-text"><span>{{areaInHa(feature)| number:'1.2-2'}}
|
||||
ha</span> <span>{{feature.get('cropTypeName')}}</span> </div>
|
||||
<div class="card-text"><span>{{feature.get('datadate')|date}}</span> -
|
||||
<span>{{feature.get('dataenddate')|date}}</span> </div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@@ -1,14 +1,12 @@
|
||||
import { Component, Injectable,ViewChild,AfterViewInit} from '@angular/core';
|
||||
import { Feature } from 'ol';
|
||||
import * as extent from 'ol/extent';
|
||||
import * as render from 'ol/render';
|
||||
import { Store } from '@ngrx/store';
|
||||
import * as mapReducers from '../../reducers/map.reducer';
|
||||
import { commonReducers,ItemTypeService,AppConfig } from '@farmmaps/common';
|
||||
import { AbstractFeatureListFeatureComponent } from '../feature-list-feature/feature-list-feature.component';
|
||||
import { ForItemType } from '../for-item/for-itemtype.decorator';
|
||||
import {getArea} from 'ol/sphere';
|
||||
import * as style from 'ol/style';
|
||||
|
||||
|
||||
|
||||
@ForItemType("vnd.farmmaps.itemtype.cropfield")
|
||||
@@ -18,10 +16,8 @@ import * as style from 'ol/style';
|
||||
templateUrl: './feature-list-feature-cropfield.component.html',
|
||||
styleUrls: ['./feature-list-feature-cropfield.component.scss']
|
||||
})
|
||||
export class FeatureListFeatureCropfieldComponent extends AbstractFeatureListFeatureComponent implements AfterViewInit {
|
||||
export class FeatureListFeatureCropfieldComponent extends AbstractFeatureListFeatureComponent {
|
||||
|
||||
@ViewChild('canvas') canvas;
|
||||
@ViewChild('container') container;
|
||||
|
||||
constructor(store: Store<mapReducers.State | commonReducers.State>, itemTypeService: ItemTypeService,config:AppConfig) {
|
||||
super(store, itemTypeService,config);
|
||||
@@ -34,42 +30,4 @@ export class FeatureListFeatureCropfieldComponent extends AbstractFeatureListFea
|
||||
if(a) return a;
|
||||
return getArea(feature.getGeometry(),{projectio:"EPSG:3857"}) / 10000;
|
||||
}
|
||||
|
||||
|
||||
render(canvas,width,height,feature:Feature) {
|
||||
let renderContext = render.toContext(canvas.getContext( '2d'),{ size: [width, height] });
|
||||
|
||||
let strokeStyle = new style.Style({
|
||||
stroke: new style.Stroke({ color: 'black',width:1.5 })
|
||||
});
|
||||
|
||||
let geom = feature.getGeometry().clone(),
|
||||
line = geom.getCoordinates()[0],
|
||||
e = extent.boundingExtent( line );
|
||||
|
||||
let dxy = extent.getCenter(e),
|
||||
sxy = [
|
||||
(width - 2 ) / extent.getWidth(e),
|
||||
(height - 2 ) / extent.getHeight(e)
|
||||
];
|
||||
|
||||
let dx = dxy[0],
|
||||
dy = dxy[1],
|
||||
sx = sxy[0],
|
||||
sy = sxy[1];
|
||||
|
||||
geom.translate( -dx, -dy );
|
||||
geom.scale( Math.min(sx, sy), -Math.min(sx, sy));
|
||||
geom.translate( width / 2, height / 2 );
|
||||
|
||||
renderContext.setStyle( strokeStyle );
|
||||
renderContext.drawGeometry( geom );
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.render(this.canvas.nativeElement,
|
||||
this.container.nativeElement.offsetWidth,
|
||||
this.container.nativeElement.offsetHeight,
|
||||
this.feature);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,4 @@
|
||||
<div #container class="container">
|
||||
<canvas #canvas ></canvas>
|
||||
</div>
|
||||
|
@@ -0,0 +1,5 @@
|
||||
.container {
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { GeometryThumbnailComponent } from './feature-thumbnail.component';
|
||||
|
||||
describe('GeometryThumbnailComponent', () => {
|
||||
let component: GeometryThumbnailComponent;
|
||||
let fixture: ComponentFixture<GeometryThumbnailComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ GeometryThumbnailComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(GeometryThumbnailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@@ -0,0 +1,60 @@
|
||||
import { Component, Input, OnInit,ViewChild } from '@angular/core';
|
||||
import { Feature} from 'ol';
|
||||
import { Geometry } from 'ol/geom';
|
||||
import * as extent from 'ol/extent';
|
||||
import * as render from 'ol/render';
|
||||
import * as style from 'ol/style';
|
||||
|
||||
@Component({
|
||||
selector: 'fm-map-feature-thumbnail',
|
||||
templateUrl: './feature-thumbnail.component.html',
|
||||
styleUrls: ['./feature-thumbnail.component.scss']
|
||||
})
|
||||
export class GeometryThumbnailComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
@ViewChild('canvas') canvas;
|
||||
@ViewChild('container') container;
|
||||
@Input('feature') feature:Feature;
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
render(canvas,width,height,geometry:Geometry) {
|
||||
let renderContext = render.toContext(canvas.getContext( '2d'),{ size: [width, height] });
|
||||
|
||||
let strokeStyle = new style.Style({
|
||||
stroke: new style.Stroke({ color: 'black',width:1.5 })
|
||||
});
|
||||
|
||||
let geom = geometry.clone(),
|
||||
line = geom.getCoordinates()[0],
|
||||
e = extent.boundingExtent( line );
|
||||
|
||||
let dxy = extent.getCenter(e),
|
||||
sxy = [
|
||||
(width - 2 ) / extent.getWidth(e),
|
||||
(height - 2 ) / extent.getHeight(e)
|
||||
];
|
||||
|
||||
let dx = dxy[0],
|
||||
dy = dxy[1],
|
||||
sx = sxy[0],
|
||||
sy = sxy[1];
|
||||
|
||||
geom.translate( -dx, -dy );
|
||||
geom.scale( Math.min(sx, sy), -Math.min(sx, sy));
|
||||
geom.translate( width / 2, height / 2 );
|
||||
|
||||
renderContext.setStyle( strokeStyle );
|
||||
renderContext.drawGeometry( geom );
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.render(this.canvas.nativeElement,
|
||||
this.container.nativeElement.offsetWidth,
|
||||
this.container.nativeElement.offsetHeight,
|
||||
this.feature.getGeometry());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user