Browse Source

科达对接封装组件

上海一张图
陈鹏飞 4 years ago
parent
commit
dc6abd98b9
  1. 30
      src/app/searchComponent.service.ts
  2. 2
      src/modules/map/declare/factory.ts
  3. 4
      src/modules/map/declare/keda-map.ts

30
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();
}
}

2
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'

4
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 })
}

Loading…
Cancel
Save