diff --git a/src/app/searchComponent.service.ts b/src/app/searchComponent.service.ts new file mode 100644 index 0000000..6c00787 --- /dev/null +++ b/src/app/searchComponent.service.ts @@ -0,0 +1,30 @@ +import { ApplicationRef, ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, Injectable, Injector } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class SearchService { + constructor(private componentFactoryResolver: ComponentFactoryResolver,private applicationRef: ApplicationRef,private injector: Injector,) {} + + //angular 动态组件 + appendComponentToBody(component: any) { + //create a component reference + const componentRef = this.componentFactoryResolver.resolveComponentFactory(component).create(this.injector); + + // attach component to the appRef so that so that it will be dirty checked. + this.applicationRef.attachView(componentRef.hostView); + + // get DOM element from component + const domElem = (componentRef.hostView as EmbeddedViewRef < any > ).rootNodes[0] as HTMLElement; + + document.body.appendChild(domElem); + + return componentRef; + } + + removeComponentFromBody(componentRef: ComponentRef < any > ) { + this.applicationRef.detachView(componentRef.hostView); + componentRef.destroy(); + } + +} \ No newline at end of file diff --git a/src/modules/map/declare/factory.ts b/src/modules/map/declare/factory.ts index d0b103c..909f25a 100644 --- a/src/modules/map/declare/factory.ts +++ b/src/modules/map/declare/factory.ts @@ -1,4 +1,4 @@ -const mapSupplier: number = 2; // 1:高德, 2:科达 +const mapSupplier: number = 1; // 1:高德, 2:科达 import { IMap, IMapOptions, IMarker, IPixel, IMarkOptions, ILngLat, ILayer, ICircle, IMarkerCluster, IRenderClusterMarker, IInfoWindow, IMouseTool, IIcon, ISize, IIconOptions, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch } from './map' import { GaodeCircle, GaodeIcon, GaodeInfoWindow, GaodeLayer, GaoDeLngLat, GaoDeMap, GaoDeMarker, GaoDeMarkerCluster, GaodeMouseTool, GaoDePixel, GaoDeRenderClusterMarker, GaodeTileLayer, GaodeSize, GaodeDriving, GaodeAutocomplete, GaodePlaceSearch } from './gaode-map' diff --git a/src/modules/map/declare/keda-map.ts b/src/modules/map/declare/keda-map.ts index 92783a5..e5dcaa9 100644 --- a/src/modules/map/declare/keda-map.ts +++ b/src/modules/map/declare/keda-map.ts @@ -29,7 +29,7 @@ export class KeDaMap extends KedaBasic implements IMap { type: 'Feature', geometry: { type: 'Point', - coordinates: [121.495126354, 31.241993148] + coordinates: cityPosition }, properties: { height: 30 } } @@ -138,7 +138,7 @@ export class KeDaMap extends KedaBasic implements IMap { if (pos instanceof Array) { position = pos } else { - position = [pos.lng, pos.lat]; + position = pos.getArray(); } this.self.flyTo({ point: position }) }