From f25b1565db36a1b36b2a2fecc2a1b2094439191c Mon Sep 17 00:00:00 2001 From: anxinCPF <1105965053@qq.com> Date: Fri, 25 Jun 2021 20:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.component.ts | 6 ++++-- src/app/pages/login/login.component.ts | 9 +++++++-- src/global.d.ts | 5 +++++ .../SearchDownListPlugins/SearchDownList.html | 1 + .../SearchDownListPlugins/SearchDownList.ts | 18 ++++++++++++------ src/modules/map/declare/keda-map.ts | 13 ++++++++++++- 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 src/global.d.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 3a08e63..f2c071e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, Inject, Injector } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Data } from './interface' import { Router,ActivatedRoute } from '@angular/router' @@ -14,7 +14,9 @@ import { MaskLayerService } from './mask-layer.service'; }) export class AppComponent { - constructor(private maskLayerService:MaskLayerService,private http:HttpClient,private router:Router,public token:CacheTokenService) { } + constructor(private maskLayerService:MaskLayerService,private http:HttpClient,private router:Router,public token:CacheTokenService,private injector:Injector) { + window.injector = injector; + } isMaskLayerShow:boolean = false diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index c138d87..96ca249 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -1,10 +1,12 @@ -import { Component, OnInit } from '@angular/core'; +import { ApplicationRef, Component, ComponentFactoryResolver, Injector, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Data } from '../../interface' import { Router,ActivatedRoute } from '@angular/router' import {CacheTokenService} from '../../http-interceptors/cache-token.service'//引入服务 import { MatSnackBar,MatSnackBarConfig } from '@angular/material/snack-bar'; import { MatDialog,MatDialogRef } from '@angular/material/dialog'; +import { SearchService } from '@src/app/searchComponent.service'; +import { SearchDownList } from '@src/modules/map/declare/component/SearchDownListPlugins/SearchDownList'; @@ -15,7 +17,10 @@ import { MatDialog,MatDialogRef } from '@angular/material/dialog'; }) export class LoginComponent implements OnInit { - constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public snackBar: MatSnackBar, public dialog: MatDialog) { } + constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public snackBar: MatSnackBar, public dialog: MatDialog) { + + window.injector.get(SearchService).appendComponentToBody(SearchDownList); + } ngOnInit() { this.automaticLogin() diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..420e434 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,5 @@ +import { Injector } from "@angular/core"; + +export declare interface Window { + injector: Injector + } \ No newline at end of file diff --git a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.html b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.html index 3af98ee..a6c08c4 100644 --- a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.html +++ b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.html @@ -1,3 +1,4 @@
+

I'm loaded

{{item.name}}
\ No newline at end of file diff --git a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts index af60ff0..815b30d 100644 --- a/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts +++ b/src/modules/map/declare/component/SearchDownListPlugins/SearchDownList.ts @@ -2,6 +2,8 @@ import { Component, OnInit, Inject } from '@angular/core'; import { AutocompleteSelect } from '../../map'; +type ClickHandler = (data:AutocompleteSelect)=>void; + @Component({ selector: 'SearchDownList', templateUrl: './SearchDownList.html', @@ -9,28 +11,32 @@ import { AutocompleteSelect } from '../../map'; }) export class SearchDownList implements OnInit { private $input; - constructor(inputListenId: string) { - this.$input = document.getElementById(inputListenId); + constructor() { } public searchList: AutocompleteSelect[] = []; //list public leftCss: string = '0px'; public topCss: string = '0px'; public minWidthCss: string = '0px'; - + private clickHandler:ClickHandler; ngOnInit(): void { } + init(elementId:string,clickCallback:ClickHandler):void{ + this.$input = document.getElementById(elementId); + this.clickHandler = clickCallback; + //this.addDOMEvent(); + } // input 添加监听事件 addDOMEvent() { - let input = document.getElementById(id) - let DOM = input.getBoundingClientRect() + // this.left = DOM.left // this.top = DOM.top + DOM.height + 2 // this.minWidth = DOM.width } select(e) { - console.log(e) + this.clickHandler(e); + this.searchList = []; } watch() { diff --git a/src/modules/map/declare/keda-map.ts b/src/modules/map/declare/keda-map.ts index 1c4b918..f642293 100644 --- a/src/modules/map/declare/keda-map.ts +++ b/src/modules/map/declare/keda-map.ts @@ -1,5 +1,8 @@ import { AutocompleteSearchCallback, AutocompleteSelectCallback, HtmlRender, IAutocomplete, ICircle, IDriving, IInfoWindow, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IPixel, IPlaceSearch, IRenderClusterMarker, ISelf, ITileLayer, PixelRender, PlaceSearchCallback } from './map' import * as ObjectID from 'bson-objectid'; +import { SearchDownList } from './component/SearchDownListPlugins/SearchDownList'; +import { ApplicationRef, ComponentFactoryResolver, Injector, ReflectiveInjector } from '@angular/core'; +import { SearchService } from '@src/app/searchComponent.service'; declare var KMap: any; class KedaBasic implements ISelf { @@ -314,12 +317,20 @@ export class KedaAutocomplete extends KedaBasic implements IAutocomplete { //Aut constructor(options: any, component: any) { super(); this.component = component + const injector = Injector.create({ + providers: + [{provide: SearchService, deps: [ComponentFactoryResolver,ApplicationRef,Injector]}] + }); + injector.get(SearchService).appendComponentToBody(SearchDownList); if (options && options.input != undefined) { //绑定input框搜索事件 - //KedaSearchComponent.instance.addDOMEvent(options.input) + this.inputListen(options.input); } } on(eventName: string, callback: AutocompleteSelectCallback) { + } + inputListen(elementId:string){ + } search(address: string, callback: AutocompleteSearchCallback) { (this.component.map as KeDaMap).self.queryInfoByType({