Commit 40afa7a5 authored by 张启明's avatar 张启明

test: 添加通视分析和天际线

parent c3f6fb51
#container {
position: relative;
}
.widgets {
position: absolute;
display: flex;
flex-direction: column;
}
<h1>Ng smart3d</h1>
<div id="container">
<app-measure-handler></app-measure-handler>
<div class="widgets">
<app-measure-handler></app-measure-handler>
<app-sight-line></app-sight-line>
<app-skyline></app-skyline>
<app-layer-manager></app-layer-manager>
</div>
</div>
......@@ -18,7 +18,8 @@ export class AppComponent implements OnInit {
this.viewer = this.viewerService.initViewer('container', {
sceneMode: smart3d.SceneMode.SCENE3D,
scene3DOnly: true,
terrainProvider: smart3d.TerrainManager.createWorldTerrain()
terrainProvider: smart3d.TerrainManager.createWorldTerrain(),
helper: false,
});
}
}
......@@ -2,14 +2,20 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { MeasureHandlerComponent } from './components';
import { SightLineComponent } from './components/sight-line/sight-line.component';
import {
MeasureHandlerComponent,
SightLineComponent,
LayerManagerComponent,
SkylineComponent,
} from './components';
@NgModule({
declarations: [
AppComponent,
MeasureHandlerComponent,
SightLineComponent,
LayerManagerComponent,
SkylineComponent,
],
imports: [
BrowserModule
......
export * from './measure-handler';
export * from './sight-line';
export * from './layer-manager';
export * from './skyline';
export * from './layer-manager.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LayerManagerComponent } from './layer-manager.component';
describe('LayerManagerComponent', () => {
let component: LayerManagerComponent;
let fixture: ComponentFixture<LayerManagerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LayerManagerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LayerManagerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-layer-manager',
templateUrl: './layer-manager.component.html',
styleUrls: ['./layer-manager.component.css']
})
export class LayerManagerComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
......@@ -8,10 +8,7 @@ import { ViewerService } from 'src/app/services';
})
export class MeasureHandlerComponent implements OnInit {
public handleMeasure: (measureMode: number, options?: {
isGround: boolean;
showLabel: boolean;
}) => any;
public handleMeasure: (measureMode: number, isGround: boolean, showLabel: boolean) => any;
public measureMode = smart3d.MeasureMode;
constructor(
......
.buttons {
position: absolute;
top: 20px;
left: 20px;
}
\ No newline at end of file
<div class="buttons">
<div>
<button (click)="handleMeasure(measureMode.Distance)">不贴地距离测量</button>
<button (click)="handleMeasure(measureMode.Distance, {
isGround: true
})">贴地距离测量</button>
<button (click)="handleMeasure(measureMode.Distance, true)">贴地距离测量</button>
<button (click)="handleMeasure(measureMode.Area)">不贴地面积测量</button>
<button (click)="handleMeasure(measureMode.Area, {
isGround: true
})">贴地面积测量</button>
<button (click)="handleMeasure(measureMode.Area, true)">贴地面积测量</button>
<button (click)="handleMeasure(measureMode.Angle)">角度测量</button>
<button (click)="handleMeasure(measureMode.DVH )">空间距离,水平距离,垂直距离模式测量</button>
</div>
\ No newline at end of file
<p>sight-line works!</p>
<div>
<button (click)="handleSightLine()">通视分析</button>
</div>
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { ViewerService } from 'src/app/services';
@Component({
selector: 'app-sight-line',
......@@ -7,9 +8,25 @@ import { Component, OnInit } from '@angular/core';
})
export class SightLineComponent implements OnInit {
constructor() { }
constructor(
private viewerService: ViewerService,
) { }
ngOnInit() {
}
handleSightLine() {
const viewer = this.viewerService.viewer;
const drawHandler = new smart3d.DrawHandler(viewer, smart3d.DrawMode.Line);
const positions = [];
drawHandler.anchorEvent.addEventListener(position => {
if (positions.push(position) >= 2) {
const sightLine = new smart3d.SightLine(viewer.scene, positions[0], positions[1]);
drawHandler.clear();
drawHandler.destroy();
sightLine.build();
}
});
drawHandler.activate();
}
}
export * from './skyline.component';
<div>
<button (click)="toggleSkyline()">{{ showSkyline ? '关闭' : '开启' }}天际线</button>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SkylineComponent } from './skyline.component';
describe('SkylineComponent', () => {
let component: SkylineComponent;
let fixture: ComponentFixture<SkylineComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SkylineComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SkylineComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { ViewerService } from 'src/app/services';
@Component({
selector: 'app-skyline',
templateUrl: './skyline.component.html',
styleUrls: ['./skyline.component.css']
})
export class SkylineComponent implements OnInit {
public showSkyline = false;
private skyline;
private oldDepthTestAgainstTerrainValue: boolean;
constructor(
private viewerService: ViewerService,
) { }
ngOnInit() {
}
toggleSkyline() {
this.showSkyline = !this.showSkyline;
const viewer = this.viewerService.viewer;
if (this.showSkyline) {
// 需要开启 depthTestAgainstTerrain,天际线才会围住地形,否则会围住 globe
this.oldDepthTestAgainstTerrainValue = viewer.scene.globe.depthTestAgainstTerrain;
viewer.scene.globe.depthTestAgainstTerrain = true;
this.skyline = new smart3d.SkyLine(viewer, {
// width: 10,
// lineColor: Cesium.Color.GREEN,
// strokeDis: 1e9,
});
} else {
this.skyline.destroy();
viewer.scene.globe.depthTestAgainstTerrain = this.oldDepthTestAgainstTerrainValue;
}
}
}
export * from './viewer';
export * from './layer-manager';
export * from './layer-manager.service';
import { TestBed } from '@angular/core/testing';
import { LayerManagerService } from './layer-manager.service';
describe('LayerManagerService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: LayerManagerService = TestBed.get(LayerManagerService);
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { ViewerService } from '../viewer';
@Injectable({
providedIn: 'root'
})
export class LayerManagerService {
private layerManager;
constructor(
private viewerService: ViewerService
) {
console.log(this.viewerService.viewer);
}
}
......@@ -7,6 +7,7 @@ export class ViewerService {
// tslint:disable-next-line: variable-name
private _viewer;
private layerManager;
private measureHandler;
constructor() {
......@@ -21,14 +22,23 @@ export class ViewerService {
initViewer(container: string | Element, options?: object): object {
if (!this._viewer) {
this._viewer = new smart3d.Viewer(container, options || {});
this.layerManager = new smart3d.LayerManager(this._viewer);
// tslint:disable-next-line: no-string-literal
window['viewer'] = this._viewer;
}
return this._viewer;
}
handleMeasure(measureMode: number, options?: {
isGround: boolean;
showLabel: boolean;
}) {
addLayer(layer) {
this.layerManager.addLayer(layer);
}
flyToLayer(layer) {
this.layerManager.flyTo(layer);
}
handleMeasure(measureMode: number, isGround?: boolean, showLabel?: boolean) {
if (
measureMode !== smart3d.MeasureMode.Distance &&
measureMode !== smart3d.MeasureMode.Angle &&
......@@ -38,8 +48,11 @@ export class ViewerService {
throw new Cesium.DeveloperError('measure mode must be one of smart3d.MeasureMode');
}
isGround = undefined === isGround ? false : isGround;
showLabel = undefined === showLabel ? true : showLabel;
if (this._viewer) {
this.measureHandler = new smart3d.MeasureHandler(this.viewer, measureMode, options && options);
this.measureHandler = new smart3d.MeasureHandler(this.viewer, measureMode, isGround, showLabel);
this.measureHandler.activate();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment