From db0055fe62f290ba6bfb99a719e2b30b1f74da63 Mon Sep 17 00:00:00 2001 From: anxinCPF <1105965053@qq.com> Date: Sat, 26 Jun 2021 18:52:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E7=A7=91=E8=BE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fire-force/fire-force.component.ts | 2 +- .../linkage-forces.component.ts | 2 +- .../water-collection.component.ts | 2 +- .../key-unit/basicinfo/basicinfo.component.ts | 8 ++--- .../collection-tools.component.ts | 10 +++--- src/modules/map/declare/keda-map.ts | 32 ++++++++++++++----- src/modules/map/declare/map.d.ts | 12 +++++-- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/app/data-collection/fire-force/fire-force.component.ts b/src/app/data-collection/fire-force/fire-force.component.ts index a9247fc..8536a72 100644 --- a/src/app/data-collection/fire-force/fire-force.component.ts +++ b/src/app/data-collection/fire-force/fire-force.component.ts @@ -860,7 +860,7 @@ export class FireForceComponent implements OnInit { this.isMapLabel = true this.newPositionMarker.on('dragend', (e)=>{ this.positionLngLat = {x: e.lnglat.lng, y: e.lnglat.lat} - }) + },this) //点击确定 this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'),'click',(event)=>{ this.isGisTopBox = false diff --git a/src/app/data-collection/linkage-forces/linkage-forces.component.ts b/src/app/data-collection/linkage-forces/linkage-forces.component.ts index f9282f9..b8d75cb 100644 --- a/src/app/data-collection/linkage-forces/linkage-forces.component.ts +++ b/src/app/data-collection/linkage-forces/linkage-forces.component.ts @@ -581,7 +581,7 @@ export class LinkageForcesComponent implements OnInit { this.isMapLabel = true this.newPositionMarker.on('dragend', (e)=>{ this.positionLngLat = {x: e.lnglat.lng, y: e.lnglat.lat} - }) + },this) //点击确定 this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'),'click',(event)=>{ this.isGisTopBox = false diff --git a/src/app/data-collection/water-collection/water-collection.component.ts b/src/app/data-collection/water-collection/water-collection.component.ts index 3fe5cf9..ef65695 100644 --- a/src/app/data-collection/water-collection/water-collection.component.ts +++ b/src/app/data-collection/water-collection/water-collection.component.ts @@ -588,7 +588,7 @@ export class WaterCollectionComponent implements OnInit { this.isMapLabel = true this.newPositionMarker.on('dragend', (e)=>{ this.positionLngLat = {x: e.lnglat.lng, y: e.lnglat.lat} - }) + },this) //点击确定 this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'),'click',(event)=>{ this.isGisTopBox = false diff --git a/src/app/key-unit/basicinfo/basicinfo.component.ts b/src/app/key-unit/basicinfo/basicinfo.component.ts index 31b79fb..cc44716 100644 --- a/src/app/key-unit/basicinfo/basicinfo.component.ts +++ b/src/app/key-unit/basicinfo/basicinfo.component.ts @@ -231,12 +231,12 @@ export class BasicinfoComponent implements OnInit { let lnglat = this.map.containerToLngLat(e.pixel) this.markerPosition2 = { x: lnglat.KL, y: lnglat.kT } // console.log(`${lnglat.KL},${lnglat.kT}`); - }) + },this) this.newPositionMarker.on('dragging', (e) => { //console.log('dragging',e) let lnglat = this.map.containerToLngLat(e.pixel) this.newPositionMarker.setPosition(lnglat); - }) + },this) //点击确定 this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'), 'click', (event) => { this.map.clearMap(); @@ -320,12 +320,12 @@ export class BasicinfoComponent implements OnInit { let lnglat = this.map.containerToLngLat(e.pixel) this.markerPosition2 = { x: lnglat.KL, y: lnglat.kT } // console.log(`${lnglat.KL},${lnglat.kT}`); - }) + },this) this.newPositionMarker.on('dragging', (e) => { //console.log('dragging',e) let lnglat = this.map.containerToLngLat(e.pixel) this.newPositionMarker.setPosition(lnglat); - }) + },this) //点击确定 this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'), 'click', (event) => { this.isGisTopBox = true diff --git a/src/app/ui/collection-tools-plan/collection-tools.component.ts b/src/app/ui/collection-tools-plan/collection-tools.component.ts index 06ba24f..dc9e69c 100644 --- a/src/app/ui/collection-tools-plan/collection-tools.component.ts +++ b/src/app/ui/collection-tools-plan/collection-tools.component.ts @@ -1429,7 +1429,7 @@ export class CollectionToolsPlanComponent implements OnInit { this.map.on('click', (e) => { this.showInfoClick(e) - }); + },this); this.map.on("complete", () => { for (const key in this.canvasData.originaleveryStoreyData.data) { if (Object.prototype.hasOwnProperty.call(this.canvasData.originaleveryStoreyData.data, key)) { @@ -1465,13 +1465,13 @@ export class CollectionToolsPlanComponent implements OnInit { console.log(e) this.clickId = e.target.id this.setAssetsProperty(this.canvasData.originaleveryStoreyData.data[e.target.id]) - }); + },this); startMarker.on('dragend', (e) => { // console.log('拖拽完成', e) this.canvasData.isChange = true this.clickId = e.target.id this.canvasData.originaleveryStoreyData.data[e.target.id].Point = { x: e.lnglat.lng, y: e.lnglat.lat } - }); + },this); this.planDataMarkers.push(startMarker) this.map.add(startMarker); } @@ -2252,13 +2252,13 @@ export class CollectionToolsPlanComponent implements OnInit { startMarker.on('click', (e) => { this.clickId = e.target.id this.setAssetsProperty(this.canvasData.originaleveryStoreyData.data[e.target.id]) - }); + },this); startMarker.on('dragend', (e) => { // console.log('拖拽完成', e) this.canvasData.isChange = true this.clickId = e.target.id this.canvasData.originaleveryStoreyData.data[e.target.id].Point = { x: e.lnglat.lng, y: e.lnglat.lat } - }); + },this); //将图标数据添加 let itemData = JSON.parse(JSON.stringify(this.selectImage)) diff --git a/src/modules/map/declare/keda-map.ts b/src/modules/map/declare/keda-map.ts index 8106d02..9896917 100644 --- a/src/modules/map/declare/keda-map.ts +++ b/src/modules/map/declare/keda-map.ts @@ -1,4 +1,4 @@ -import { AutocompleteSearchCallback, AutocompleteSelectCallback, DrivingSearchCallback, HtmlRender, IAutocomplete, ICircle, IDriving, IInfoWindow, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IPixel, IPlaceSearch, IRenderClusterMarker, ISelf, ITileLayer, PixelRender, PlaceSearchCallback } from './map' +import { AutocompleteSearchCallback, AutocompleteSelectCallback, ClickOptions, DrivingSearchCallback, EventCallback, HtmlRender, IAutocomplete, ICircle, IDriving, IInfoWindow, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IPixel, IPlaceSearch, IRenderClusterMarker, ISelf, ITileLayer, PixelRender, PlaceSearchCallback } from './map' import { SearchDownList } from './component/SearchDownListPlugins/SearchDownList'; import { SearchService } from '@src/app/searchComponent.service'; import * as ObjectID from 'bson-objectid'; @@ -154,16 +154,26 @@ export class KeDaMap extends KedaBasic implements IMap { }); return center } - on(eventName: string, callback: Function): void { + on(eventName: string, callback: EventCallback, component?: any) { let eventMapProfile = { complete: "load", click: "click", rightclick: "contextmenu" }; - this.self.addEventOnMap({ - event: eventMapProfile[eventName], - handler: callback - }); + if (eventName == "click") { + this.self.addEventOnMap({event: "click", + handler: (res)=>{ + console.log(res,'地图点击') + var d:ClickOptions = res.data.map(); + callback.call(component,d); + } + }); + } else { + this.self.addEventOnMap({ + event: eventMapProfile[eventName], + handler: callback + }); + } } } @@ -237,10 +247,11 @@ export class KeDaMarker extends KedaBasic implements IMarker { this.self.id = str } public bindObj = []; // event - on(eventName: string, callback: Function): void { + on(eventName: string, callback: EventCallback, component?: any) { this.bindObj.push({ eventName: eventName, callback: callback, + component: component, }); this.startBindEvent(); } @@ -250,7 +261,12 @@ export class KeDaMarker extends KedaBasic implements IMarker { this.map.self.addEventOnMarkers({ selector: `.${this.id}`, event: item.eventName, - handler: item.callback, + handler: (res) =>{ + console.log(res,'marker点击') + var d:ClickOptions = res.data.map(); + d.target.id = this.self.id + item.callback.call(item.component,d) + } }); }) this.bindObj = []; diff --git a/src/modules/map/declare/map.d.ts b/src/modules/map/declare/map.d.ts index fcd0440..c7c5c2b 100644 --- a/src/modules/map/declare/map.d.ts +++ b/src/modules/map/declare/map.d.ts @@ -3,8 +3,16 @@ export interface ISelf { discriminator: string; } +export class ClickOptions { + lnglat: ILngLat + pixel: IPixel + type: string + target: { id:string } +} + +type EventCallback = (event?:ClickOptions)=>void; export interface IMap extends ISelf { - on(eventName: string, callback: Function); + on(eventName: string, callback: EventCallback, component?: any); add(obj: IMarker|ITileLayer|any); remove(obj: IMarker|ITileLayer|any); clearMap(); @@ -29,7 +37,7 @@ export interface IMapOptions { export interface IMarker extends ISelf { id: string; _position:number[]; - on(eventName: string, callback: Function); + on(eventName: string, callback: EventCallback, component?: any); setPosition(x:ILngLat|number[]) setContent(html:string) setMap();