This commit is contained in:
TaricXin
2022-03-14 16:14:31 +08:00
parent 4883a55ce8
commit 8a80a1de3c
4 changed files with 41 additions and 33 deletions

View File

@ -1,8 +1,8 @@
import { Component, Input, OnChanges, OnInit, Output, SimpleChanges, EventEmitter } from '@angular/core';
import { BaseService } from 'src/app/shared/services';
import { throwError } from 'rxjs';
import AMapLoader from '@amap/amap-jsapi-loader';
import { Component, Input, OnChanges, OnInit, Output, SimpleChanges, EventEmitter, OnDestroy } from '@angular/core';
import { amapConf } from '@conf/amap.config';
import { throwError } from 'rxjs';
import { BaseService } from 'src/app/shared/services';
declare var AMap: any;
declare var AMapUI: any;
declare var Loca: any;
@ -13,7 +13,7 @@ const CONFIG = amapConf;
templateUrl: './amap-path-simplifier.component.html',
styleUrls: ['./amap-path-simplifier.component.less']
})
export class AmapPathSimplifierComponent implements OnInit, OnChanges {
export class AmapPathSimplifierComponent implements OnInit, OnChanges, OnDestroy {
aMap: any;
pathSimplifierIns: any;
geocoder: any;
@ -32,7 +32,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
mapHeight = '500px';
@Output()
clcikPointEvent = new EventEmitter<any>();
readonly clcikPointEvent = new EventEmitter<any>();
@Input()
pois: any = [];
@ -45,7 +45,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
this.setPathIndex(this.selectedIndex);
}
if (changes?.MapList?.currentValue && this?.pathSimplifierIns && changes.MapList?.currentValue.length > 0) {
console.log(this.MapList);
// console.log(this.MapList);
this.pathList = [
{
name: '路线1',
@ -130,7 +130,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
getHoverTitle: function (pathData: any, pathIndex: any, pointIndex: any) {
if (pointIndex >= 0) {
//point
return pathData.name + '' + pathData.points[pointIndex].name;
return `${pathData.name},${pathData.points[pointIndex].name}`;
}
return '';
},
@ -147,7 +147,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
this.pathSimplifierIns.on('pointClick', (e: any, info: any) => {
this.clcikPointEvent.emit({ e, info });
console.log('Click: ' + info.pathData.points[info.pointIndex].name);
console.log(`Click: ${info.pathData.points[info.pointIndex].name}`);
});
}
@ -202,7 +202,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
});
}
setData(pathList: Array<any>) {
setData(pathList: any[]) {
this.pathSimplifierIns.setData(pathList);
}
@ -224,7 +224,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
}
/** 根据经纬度获取地址信息 */
getPoiByPositon(position: Array<string>) {
getPoiByPositon(position: string[]) {
this.geocoder.getAddress(position, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
// result中对应详细地理坐标信息
@ -239,6 +239,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
/**
* 选中标点,设置窗口信息
*
* @param location
*/
selectedPOI(location: any) {
@ -250,6 +251,7 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
/**
* 增加标记点
*
* @param poi
*/
setPOI(poi: POI) {
@ -278,5 +280,5 @@ export class AmapPathSimplifierComponent implements OnInit, OnChanges {
export interface POI {
markerLabel: string;
color: string;
position: Array<string>;
position: string[];
}