FarmMapsLib/projects/common-map/src/fm-map/components/aol/switch2d3d/switch2d3d.component.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Component, OnInit,Input,Host } from '@angular/core';
import { MapComponent } from 'ngx-openlayers';
import OLCesium from 'ol-cesium';
2020-09-18 12:20:33 +00:00
declare var olcs: any;
@Component({
selector: 'fm-map-switch2d3d',
template: '<div (click)="handleClick($event)" class="rounded-circle twotreed">{{label}}</div>',
styles: [`.twotreed {
width:2.5em;
height:2.5em;
background-color: white;
text-align:center;
line-height:2.5em;
font-weight:bold;
cursor:default;}`]
})
export class Switch2D3DComponent {
@Input() enable:boolean;
public label: string = "3D";
private ol3d: OLCesium;
2020-09-18 12:20:33 +00:00
private synchronizers:any[];
constructor(@Host() private map: MapComponent) {
}
2020-09-18 12:20:33 +00:00
ngOnInit() {
this.ol3d = new OLCesium({ map: this.map.instance,createSynchronizers: (map,scene) => {
this.synchronizers = [
new olcs.RasterSynchronizer(map,scene),
new olcs.VectorSynchronizer(map,scene)
];
return this.synchronizers;
},stopOpenLayersEventsPropagation:true});
}
synchronize() {
this.synchronizers.forEach((synchronizer) => {
synchronizer.synchronize();
});
}
handleClick(event) {
2020-09-18 12:20:33 +00:00
this.enable = !this.enable;
if(this.enable) {
this.synchronize();
}
this.ol3d.setEnabled(this.enable);
this.label = this.enable?"2D":"3D";
}
}