Browse Source

[新增]路径规划

TDT天地图
邵佳豪 1 year ago
parent
commit
7e183c7b4f
  1. 16
      src/app/home/basic-info/unit-details/unit-details.component.html
  2. 40
      src/app/home/basic-info/unit-details/unit-details.component.scss
  3. 492
      src/app/home/basic-info/unit-details/unit-details.component.ts
  4. 34
      src/app/home/home.module.ts
  5. BIN
      src/assets/images/tdt/end.png
  6. BIN
      src/assets/images/tdt/start.png

16
src/app/home/basic-info/unit-details/unit-details.component.html

@ -74,7 +74,7 @@
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired [nzSpan]="8">法人/消防负责人<br/>联系方式</nz-form-label>
<nz-form-label nzRequired [nzSpan]="8">法人/消防负责人<br />联系方式</nz-form-label>
<nz-form-control [nzSpan]="12">
<nz-input-group>
<input nz-input type="text" formControlName="legalPersonPhone" placeholder="请输入联系方式" />
@ -106,7 +106,7 @@
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzRequired [nzSpan]="8" style="height: 40px!important">消防安全管理人<br/>联系方式</nz-form-label>
<nz-form-label nzRequired [nzSpan]="8" style="height: 40px!important">消防安全管理人<br />联系方式</nz-form-label>
<nz-form-control [nzSpan]="12">
<nz-input-group>
<input nz-input type="text" formControlName="adminPhone" placeholder="请输入联系方式" />
@ -168,8 +168,16 @@
<div class="gistopbox hidden" [ngClass]="{'show': isGisTopBoxTwo}">
<div class="inputBox">
<span>位置: </span>
<input name="position" [(ngModel)]="searchTitle" id="tipinput" class="positionInput" type="text"
autocomplete="off">
<div class="example-input">
<input placeholder="请输入位置" nz-input [(ngModel)]="inputValue" (input)="onInput($event)"
[nzAutocomplete]="auto" />
<nz-autocomplete #auto>
<nz-auto-option *ngFor="let item of options" [nzValue]="item.name"
[nzLabel]="item.name">
{{ item.name }}
</nz-auto-option>
</nz-autocomplete>
</div>
</div>
<div class="setPosition" (click)="search()">
搜索

40
src/app/home/basic-info/unit-details/unit-details.component.scss

@ -1,5 +1,5 @@
.bule {
color: #2196F3;
color: #2196f3;
}
.detailsbox {
@ -52,7 +52,7 @@
.title {
color: #000;
margin: 20px 15px;
background: #EFF1F5;
background: #eff1f5;
height: 35px;
line-height: 35px;
border-radius: 3px;
@ -73,7 +73,7 @@
}
.selected {
color: #2196F3;
color: #2196f3;
}
}
}
@ -172,11 +172,11 @@
top: 10px;
width: 90%;
height: 46px;
background: #FFFFFF;
background: #ffffff;
display: flex;
justify-content: space-around;
align-items: center;
z-index: 999;
.positionItem {
width: 35%;
height: 35px;
@ -184,7 +184,7 @@
align-items: center;
.itemNum {
background: #F2F2F2;
background: #f2f2f2;
box-sizing: border-box;
padding-left: 10px;
width: 80%;
@ -199,7 +199,7 @@
cursor: pointer;
width: 15%;
height: 32px;
background: #2196F3;
background: #2196f3;
color: #fff;
border-radius: 4px;
display: flex;
@ -211,19 +211,19 @@
width: 63%;
display: flex;
align-items: center;
.positionInput {
border: 0;
border-radius: 6px;
width: 90%;
height: 34px;
background: #F2F2F2;
margin-left: 8px;
box-sizing: border-box;
padding-left: 10px;
.example-input {
flex: 1;
input {
border: 0;
border-radius: 6px;
height: 34px;
background: #f2f2f2;
margin-left: 8px;
box-sizing: border-box;
padding-left: 10px;
}
}
}
}
.hidden {
@ -233,7 +233,7 @@
.show {
opacity: 1;
z-index: 1;
z-index: 1000;
}
}
}
@ -249,4 +249,4 @@
top: 50px;
}
}
}
}

492
src/app/home/basic-info/unit-details/unit-details.component.ts

@ -532,13 +532,273 @@ export class UnitDetailsComponent implements OnInit {
this.getBuildingTypes();
}
Tmap: any; //天地图实例
Tzoom = 12;
map: any; //天地图实例
zoom = 12;
localsearch; //创建搜索对象 -- 提示列表
geocoder;
labelGisBgT() {
this.Tmap = new T.Map('container', {
projection: 'EPSG:4326',
this.map = new T.Map('container', {
// projection: 'EPSG:4326',
});
this.map.centerAndZoom(new T.LngLat(116.40769, 39.89945), this.zoom);
this.localsearch = new T.LocalSearch(this.map, {
pageCapacity: 10,
onSearchComplete: (res) => {
this.localSearchResult(res);
},
});
this.geocoder = new T.Geocoder();
this.createDrivingRoute();
}
//驾车规划
drivingRoute;
createDrivingRoute() {
var startIcon = '../../../../assets/images/tdt/start.png'; //起点图标
var endIcon = '../../../../assets/images/tdt/end.png'; //终点图标
let that = this;
this.drivingRoute = new T.DrivingRoute(this.map, {
policy: 0, //驾车策略
onSearchComplete: (res) => {
searchResult(res);
},
});
searchDrivingRoute();
function searchDrivingRoute() {
that.map.clearOverLays();
let startLngLat = new T.LngLat(116.26762, 39.8001);
let endLngLat = new T.LngLat(116.60889, 40.02656);
//驾车路线搜索
that.drivingRoute.search(startLngLat, endLngLat);
}
function searchResult(result) {
console.log('驾车规划结果', result);
//添加起始点
createStartMarker(result);
// obj = result;
// var resultList = document.createElement('div');
// //获取方案个数
//获得单条驾车方案结果对象
let plan = result.getPlan(0);
console.log('单条驾车方案结果对象', plan);
//显示方案内容
var describeStr =
'<strong>总时间:' +
plan.getDuration() +
'秒,总距离:' +
Math.round(plan.getDistance()) +
'公里</strong>';
describeStr +=
"<div><img src='" +
startIcon +
"'/>" +
'116.267620,39.800100' +
'</div>';
console.log('describeStr', describeStr);
//显示该方案每段的描述信息
var numRoutes = plan.getNumRoutes();
console.log('numRoutes', numRoutes);
// for (var m = 0; m < numRoutes; m++) {
// var route = plan.getRoute(m);
// describeStr +=
// m + 1 + '.<span>' + route.getDescription() + '</span><br/>';
// //显示该方案每段的详细描述信息
// var numStepsStr = '';
// var numSteps = route.getNumSteps();
// for (var n = 0; n < numSteps; n++) {
// var step = route.getStep(n);
// numStepsStr +=
// '<p>' +
// (n + 1) +
// ")<a href='javascript://' onclick='showPosition(\"" +
// step.getPosition().getLng() +
// '","' +
// step.getPosition().getLat() +
// '","' +
// step.getDescription() +
// '");\'>' +
// step.getDescription() +
// '</a></p>';
// }
// describeStr += numStepsStr;
// }
// describeStr +=
// "<div><img src='" +
// endIcon +
// "'/>" +
// '116.608890,40.026560' +
// '</div>';
// div.innerHTML = describeStr;
// resultList.appendChild(div);
// //显示驾车线路
createRoute(plan.getPath(),'red');
// //显示最佳级别
that.map.setViewport(plan.getPath());
//显示公交搜索结果
// document.getElementById('driving_way').appendChild(resultList);
}
function createRoute(lnglats, lineColor?) {
//创建线对象
var line = new T.Polyline(lnglats, {
color: '#2C64A7',
weight: 5,
opacity: 0.9,
});
//向地图上添加线
that.map.addOverLay(line);
}
function createStartMarker(result) {
var startMarker = new T.Marker(result.getStart(), {
icon: new T.Icon({
iconUrl: startIcon,
iconSize: new T.Point(44, 34),
iconAnchor: new T.Point(12, 31),
}),
});
that.map.addOverLay(startMarker);
var endMarker = new T.Marker(result.getEnd(), {
icon: new T.Icon({
iconUrl: endIcon,
iconSize: new T.Point(44, 34),
iconAnchor: new T.Point(12, 31),
}),
});
that.map.addOverLay(endMarker);
}
}
//输入提示
inputValue?: string;
options: any[] = [];
onInput(event: Event): void {
const value = (event.target as HTMLInputElement).value;
this.localsearch.search(value, 4);
//
}
localSearchResult(result) {
this.clearAll();
// this.localsearch.clearResults()
console.log('结果列表', result);
console.log('结果类型', result.getResultType());
// console.log('666', result.suggests[0].getPois());
this.options = result.suggests || [];
//清空地图及搜索列表
}
//解析点数据结果
// pois(obj) {
// if (obj) {
// //显示搜索列表
// var divMarker = document.createElement('div');
// //坐标数组,设置最佳比例尺时会用到
// var zoomArr = [];
// for (var i = 0; i < obj.length; i++) {
// //闭包
// (function (i) {
// //名称
// var name = obj[i].name;
// //地址
// var address = obj[i].address;
// //坐标
// var lnglatArr = obj[i].lonlat.split(',');
// var lnglat = new T.LngLat(lnglatArr[0], lnglatArr[1]);
// var winHtml = '名称:' + name + '<br/>地址:' + address;
// //创建标注对象
// var marker = new T.Marker(lnglat);
// //地图上添加标注点
// map.addOverLay(marker);
// //注册标注点的点击事件
// var markerInfoWin = new T.InfoWindow(winHtml, { autoPan: true });
// marker.addEventListener('click', function () {
// marker.openInfoWindow(markerInfoWin);
// });
// zoomArr.push(lnglat);
// //在页面上显示搜索的列表
// var a = document.createElement('a');
// a.href = 'javascript://';
// a.innerHTML = name;
// a.onclick = function () {
// showPosition(marker, winHtml);
// };
// divMarker.appendChild(document.createTextNode(i + 1 + '.'));
// divMarker.appendChild(a);
// divMarker.appendChild(document.createElement('br'));
// })(i);
// }
// //显示地图的最佳级别
// map.setViewport(zoomArr);
// //显示搜索结果
// divMarker.appendChild(
// document.createTextNode(
// '共' +
// localsearch.getCountNumber() +
// '条记录,分' +
// localsearch.getCountPage() +
// '页,当前第' +
// localsearch.getPageIndex() +
// '页'
// )
// );
// document.getElementById('searchDiv').appendChild(divMarker);
// document.getElementById('resultDiv').style.display = 'block';
// }
// }
//清空地图及搜索列表
clearAll() {
this.map.clearOverLays();
}
//点击位置按钮
setPosition() {
console.log('点击位置');
if (this.disableds) {
return;
}
this.isGisTopBox = false;
this.isGisTopBoxTwo = true;
}
search() {
console.log(this.inputValue);
if (!this.inputValue) {
return;
}
// this.localsearch.search(this.inputValue, 1);
// console.log(this.localsearch.getResultType())
// this.http
// .get(
// `/geocoder?ds={"keyWord":"北京市延庆区延庆镇莲花池村前街50夕阳红养老院"}&tk=3027d4c8ed89bd8a185a9b73dbf3dcad`
// )
// .subscribe((data) => {
// console.log(data);
// });
this.geocoder.getPoint(this.inputValue, (res) => {
console.log(888, res);
this.map.centerAndZoom(
new T.LngLat(res.location.lon, res.location.lat),
16
);
});
this.Tmap.centerAndZoom(new T.LngLat(116.40769, 39.89945), this.Tzoom);
}
imageUrl = ''; //单位照片
@ -612,7 +872,6 @@ export class UnitDetailsComponent implements OnInit {
isMapLabel: boolean;
//地图标注位置
markerPosition: any = { x: 0, y: 0 }; //单位坐标
map: any; //地图实例
isGisTopBox: boolean = false; //点击位置按钮
isGisTopBoxTwo: boolean = false; //点击位置按钮
oldPositionMarker: any; //旧位置marker实例
@ -636,227 +895,6 @@ export class UnitDetailsComponent implements OnInit {
//初始化地图
searchTitle: any; //搜索内容
placeSearch: any; //地址搜索类
search() {
this.placeSearch.search(this.searchTitle, (status, result) => {
// 搜索成功时,result即是对应的匹配数据
if (result.info == 'OK') {
this.newPositionMarker.setPosition([
result.poiList.pois[0].location.lng,
result.poiList.pois[0].location.lat,
]);
this.markerPosition2 = {
x: result.poiList.pois[0].location.lng,
y: result.poiList.pois[0].location.lat,
};
this.map.setCenter([
result.poiList.pois[0].location.lng,
result.poiList.pois[0].location.lat,
]); //设置地图中心点
} else {
alert('查询不到输入地址信息');
}
});
}
//初始化地图
markerPosition2;
labelGis() {
this.map = new AMap.Map('container', {
zoom: 12,
});
this.map.on('complete', () => {
this.isGisTopBox = true;
});
//输入提示
var autoOptions = {
input: 'tipinput',
};
AMap.plugin(['AMap.PlaceSearch', 'AMap.AutoComplete'], () => {
var auto = new AMap.AutoComplete(autoOptions);
this.placeSearch = new AMap.PlaceSearch(); //构造地点查询类
auto.on('select', (e) => {
this.newPositionMarker.setPosition([
e.poi.location.lng,
e.poi.location.lat,
]);
this.markerPosition2 = { x: e.poi.location.lng, y: e.poi.location.lat };
this.map.setCenter([e.poi.location.lng, e.poi.location.lat]); //设置地图中心点
}); //注册监听,当选中某条记录时会触发
});
if (this.isMapLabel) {
//如果已经标注单位坐标
console.log('已标注单位位置');
this.map.setCenter([this.olddata.location.x, this.olddata.location.y]);
this.oldPositionMarker = new AMap.Marker({
position: [this.olddata.location.x, this.olddata.location.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-34, -36),
});
// 将 markers 添加到地图
this.map.add(this.oldPositionMarker);
} else {
// console.log('未标注单位位置')
this.map.setCity('济南');
}
}
//点击位置按钮
setPosition() {
if (this.disableds) {
return;
}
this.isGisTopBox = false;
this.isGisTopBoxTwo = true;
if (this.isMapLabel) {
//如果已经标注单位坐标
// console.log('已标注单位位置')
if (this.oldPositionMarker) {
this.oldPositionMarker.setContent(this.oldPositionMarkerContent);
}
if (this.newPositionMarker) {
this.newPositionMarker.setContent(this.oldPositionMarkerContent);
}
this.newPositionMarker = new AMap.Marker({
draggable: true,
position: [this.markerPosition.x, this.markerPosition.y],
content: this.newPositionMarkerContentBtn,
offset: new AMap.Pixel(-34, -36),
});
this.map.add(this.newPositionMarker);
if (this.markerPosition.x && this.markerPosition.x != 0) {
this.markerPosition2 = {
x: this.markerPosition.x,
y: this.markerPosition.y,
};
} else {
this.markerPosition2 = {
x: this.map.getCenter().lng,
y: this.map.getCenter().lat,
}; //获取当前地图中心位置
}
this.newPositionMarker.on('dragend', (e) => {
let lnglat = this.map.containerToLngLat(e.pixel);
this.markerPosition2 = { x: lnglat.KL, y: lnglat.kT };
});
this.newPositionMarker.on('dragging', (e) => {
let lnglat = this.map.containerToLngLat(e.pixel);
this.newPositionMarker.setPosition(lnglat);
});
//点击确定
this.renderer2.listen(
this.elementRef.nativeElement.querySelector('#setPositionOk'),
'click',
(event) => {
this.map.clearMap();
this.isGisTopBox = true;
this.isGisTopBoxTwo = false;
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition2.x, this.markerPosition2.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-34, -36),
});
this.markerPosition = this.markerPosition2;
this.map.add(this.newPositionMarker);
}
);
//点击取消
this.renderer2.listen(
this.elementRef.nativeElement.querySelector('#setPositionClose'),
'click',
(event) => {
this.isGisTopBox = true;
this.isGisTopBoxTwo = false;
this.map.clearMap();
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x, this.markerPosition.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-34, -36),
});
this.map.setCenter([this.markerPosition.x, this.markerPosition.y]); //设置地图中心点
this.map.add(this.newPositionMarker);
}
);
} else {
// console.log('未标注单位位置')
if (this.newPositionMarker) {
this.newPositionMarker.setContent(this.oldPositionMarkerContent);
}
let center;
//this.markerPosition---单位坐标
if (this.markerPosition.x && this.markerPosition.x != 0) {
center = [this.markerPosition.x, this.markerPosition.y];
} else {
center = this.map.getCenter(); //获取当前地图中心位置
// console.log('获取当前地图中心位置', center)
this.map.setCenter(center);
}
this.newPositionMarker = new AMap.Marker({
draggable: true,
position: center,
content: this.newPositionMarkerContentBtn,
offset: new AMap.Pixel(-34, -36),
});
this.map.add(this.newPositionMarker);
if (this.markerPosition.x && this.markerPosition.x != 0) {
this.markerPosition2 = {
x: this.markerPosition.x,
y: this.markerPosition.y,
};
} else {
this.markerPosition2 = {
x: this.map.getCenter().lng,
y: this.map.getCenter().lat,
}; //获取当前地图中心位置
}
this.newPositionMarker.on('dragend', (e) => {
let lnglat = this.map.containerToLngLat(e.pixel);
this.markerPosition2 = { x: lnglat.KL, y: lnglat.kT };
});
this.newPositionMarker.on('dragging', (e) => {
let lnglat = this.map.containerToLngLat(e.pixel);
this.newPositionMarker.setPosition(lnglat);
});
//点击确定
this.renderer2.listen(
this.elementRef.nativeElement.querySelector('#setPositionOk'),
'click',
(event) => {
this.isGisTopBox = true;
this.isGisTopBoxTwo = false;
this.markerPosition = this.markerPosition2;
this.map.clearMap();
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x, this.markerPosition.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-34, -36),
});
this.newPositionMarker.setMap(this.map);
}
);
this.renderer2.listen(
this.elementRef.nativeElement.querySelector('#setPositionClose'),
'click',
(event) => {
this.map.clearMap();
this.isGisTopBox = true;
this.isGisTopBoxTwo = false;
if (this.markerPosition.x && this.markerPosition.x != 0) {
//说明之前标过点
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x, this.markerPosition.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-34, -36),
});
this.map.setCenter([this.markerPosition.x, this.markerPosition.y]); //设置地图中心点
this.map.add(this.newPositionMarker);
}
}
); //取消
}
}
listOfData: any[] = [];
listOfData2: any[] = [];

34
src/app/home/home.module.ts

@ -77,11 +77,12 @@ import { chineseNumbers, fileName, absoluteValue } from '../pipe/pipe';
import { TaskDetailsPagesComponent } from './task/station-task-execution/task-details/task-details.component';
import { NzTabsModule } from 'ng-zorro-antd/tabs';
import { CheckagainComponent } from './task/da-oneself-plan/checkagain/checkagain.component';
import { TaskListComponent } from './statistic-analysis/home/task-list/task-list.component';
import { FormComponent } from './statistic-analysis/form/form.component';
import { ExamineComponent } from './statistic-analysis/form/examine/examine.component';
import { ReviewComponent } from './statistic-analysis/form/review/review.component';
import { TaskListComponent } from './statistic-analysis/home/task-list/task-list.component';
import { FormComponent } from './statistic-analysis/form/form.component';
import { ExamineComponent } from './statistic-analysis/form/examine/examine.component';
import { ReviewComponent } from './statistic-analysis/form/review/review.component';
import { UnitListComponent } from './statistic-analysis/home/unit-list/unit-list.component';
import { NzAutocompleteModule } from 'ng-zorro-antd/auto-complete';
@NgModule({
declarations: [
NavComponent,
@ -132,7 +133,7 @@ import { UnitListComponent } from './statistic-analysis/home/unit-list/unit-list
FormComponent,
ExamineComponent,
ReviewComponent,
UnitListComponent
UnitListComponent,
],
imports: [
CommonModule,
@ -171,9 +172,26 @@ import { UnitListComponent } from './statistic-analysis/home/unit-list/unit-list
NzListModule,
NzDividerModule,
AngularDraggableModule,
NzTabsModule
NzTabsModule,
NzAutocompleteModule,
],
providers: [StationTaskExecutionComponent, StationWeeklyPlanComponent],
entryComponents: [AddroleComponent, EditroleComponent, AdduserComponent, EdituserComponent, AddorComponent, EditorComponent, ApplyComponent, ApplyLookComponent, LookTaskComponent, AllotPersonComponent, EditOrComponent, CreateTaskComponent, UploadComponent, CheckagainComponent,TaskListComponent]
entryComponents: [
AddroleComponent,
EditroleComponent,
AdduserComponent,
EdituserComponent,
AddorComponent,
EditorComponent,
ApplyComponent,
ApplyLookComponent,
LookTaskComponent,
AllotPersonComponent,
EditOrComponent,
CreateTaskComponent,
UploadComponent,
CheckagainComponent,
TaskListComponent,
],
})
export class HomeModule { }
export class HomeModule {}

BIN
src/assets/images/tdt/end.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
src/assets/images/tdt/start.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Loading…
Cancel
Save