Browse Source

包装器实例化 数据优化

上海一张图
赵旭 4 years ago
parent
commit
0de69ff2bf
  1. 24
      src/app/ui/collection-tools-plan/collection-tools.component.ts
  2. 20
      src/modules/map/declare/factory.ts
  3. 30
      src/modules/map/declare/gaode-map.ts
  4. 23
      src/modules/map/declare/keda-map.ts
  5. 20
      src/modules/map/declare/map.d.ts

24
src/app/ui/collection-tools-plan/collection-tools.component.ts

@ -18,7 +18,7 @@ import { MaskLayerService } from 'src/app/mask-layer.service';
import * as ObjectID from 'bson-objectid';
import { AxMessageSystem } from 'src/app/working-area/model/axMessageSystem';
import { MapFactory } from 'src/modules/map/declare/factory';
import { IMap } from 'src/modules/map/declare/map';
import { IMap, IMarker, IMarkOptions } from 'src/modules/map/declare/map';
declare var AMap: any
declare global {
@ -1418,9 +1418,9 @@ export class CollectionToolsPlanComponent implements OnInit {
console.log(666666, this.selectingSitePlan)
this.map = MapFactory.MapInstance("planContainer", {
viewMode: '2D', // 默认使用 2D 模式,如果希望使用带有俯仰角的 3D 模式,请设置 viewMode: '3D',
zoom: 11, //初始化地图层级
}).self;
viewMode: '2D', // 默认使用 2D 模式,如果希望使用带有俯仰角的 3D 模式,请设置 viewMode: '3D',
zoom: 11, //初始化地图层级
}).self;
if (this.selectingSitePlan.defaultCenter) {
this.map.setZoom(this.selectingSitePlan.zoomLevel); //设置地图层级
this.map.setCenter([this.selectingSitePlan.defaultCenter.x, this.selectingSitePlan.defaultCenter.y])
@ -1452,14 +1452,14 @@ export class CollectionToolsPlanComponent implements OnInit {
// 将 icon 传入 marker
let startMarker = MapFactory.MarkerInstance({
position: new AMap.LngLat(element.Point.x, element.Point.y),
position: MapFactory.LngLatInstance(element.Point.x, element.Point.y),
// 将 html 传给 content
content: markerContent,
// 以 icon 的 [center bottom] 为原点
//offset: MapFactory.PixelInstance(-13,-30).self,
offset: MapFactory.PixelInstance(-13, 30).self,
//offset: MapFactory.PixelInstance(-13,-30,
offset: MapFactory.PixelInstance(-13, 30),
draggable: editable == '1' ? true : false,
}).self
} as IMarkOptions)
startMarker.id = element.Id
startMarker.on('click', (e) => {
@ -2239,14 +2239,14 @@ export class CollectionToolsPlanComponent implements OnInit {
'</div>';
// 将 icon 传入 marker
let startMarker = MapFactory.MarkerInstance({
position: new AMap.LngLat(e.lnglat.lng, e.lnglat.lat),
let startMarker: IMarker = MapFactory.MarkerInstance({
position: MapFactory.LngLatInstance(e.lnglat.lng, e.lnglat.lat),
// 将 html 传给 content
content: markerContent,
// 以 icon 的 [center bottom] 为原点
offset: MapFactory.PixelInstance(-13, -30).self,
offset: MapFactory.PixelInstance(-13, -30),
draggable: true,
}).self;
} as IMarkOptions);
startMarker.id = id
startMarker.on('click', (e) => {

20
src/modules/map/declare/factory.ts

@ -1,8 +1,8 @@
const mapSupplier: number = 1;//1:高德
import { IMap, IMapOptions, IMarker, IPixel } from './map'
import { GaoDeMap, GaoDeMarker, GaoDePixel } from './gaode-map'
import { KeDaMap, KeDaMarker, KeDaPixel } from './keda-map';
import { IMap, IMapOptions, IMarker, IPixel, IMarkOptions, ILngLat } from './map'
import { GaoDeLngLat, GaoDeMap, GaoDeMarker, GaoDePixel } from './gaode-map'
import { KeDaLngLat, KeDaMap, KeDaMarker, KeDaPixel } from './keda-map';
export class MapFactory {
@ -21,11 +21,21 @@ export class MapFactory {
default: return null;
}
}
public static MarkerInstance(options:any): IMarker {
public static MarkerInstance(options: IMarkOptions): IMarker {
switch (mapSupplier) {
case 1: return new GaoDeMarker(options);
case 2: return new KeDaMarker(options);
default: return null;
}
}
}
public static LngLatInstance(x: number, y: number): ILngLat {
switch (mapSupplier) {
case 1: return new GaoDeLngLat(x, y);
case 2: return new KeDaLngLat(x, y);
default: return null;
}
}
}

30
src/modules/map/declare/gaode-map.ts

@ -1,4 +1,5 @@
import { IMap, IMapOptions, IMarker, IPixel } from './map'
import { ILngLat, IMap, IMapOptions, IMarker, IMarkOptions, IPixel } from './map'
import MapTools from './map-tools';
declare var AMap: any;
export class GaoDeMap implements IMap {
@ -6,6 +7,7 @@ export class GaoDeMap implements IMap {
constructor(container: string, options: IMapOptions) {
this.self = new AMap.Map(container, options);
}
discriminator: 'ISelf';
add(obj: any) {
return this.self.add(obj)
}
@ -18,8 +20,8 @@ export class GaoDeMap implements IMap {
setZoom(zoom) {
return this.self.setZoom(zoom)
}
setCenter([x,y]) {
return this.self.setCenter([x,y])
setCenter([x, y]) {
return this.self.setCenter([x, y])
}
getCenter() {
return this.self.getCenter();
@ -37,11 +39,31 @@ export class GaoDePixel implements IPixel {
constructor(x: number, y: number) {
this.self = new AMap.Pixel(x, y);
}
discriminator: 'ISelf';
}
export class GaoDeMarker implements IMarker {
self: any;
constructor(options: any) {
constructor(options: IMarkOptions) {
let conf = MapTools.InstanceConvert(options);
this.self = new AMap.Marker(options);
}
get id(): string {
return this.self
}
set id(str: string) {
this.self.id = str;
}
on(eventName: string, callback: Function): void {
this.self.on(eventName, callback);
}
discriminator: 'ISelf';
}
export class GaoDeLngLat implements ILngLat {
self: any;
constructor(x: number, y: number) {
this.self = new AMap.LngLat(x, y);
}
discriminator: 'ISelf';
}

23
src/modules/map/declare/keda-map.ts

@ -1,4 +1,4 @@
import { IMap, IMapOptions, IMarker, IPixel } from './map'
import { ILngLat, IMap, IMapOptions, IMarker, IPixel } from './map'
declare var KMap: any;
export class KeDaMap implements IMap {
@ -8,6 +8,7 @@ export class KeDaMap implements IMap {
opt.configUrl = "";
this.self = new KMap(opt);
}
discriminator: 'ISelf';
add(obj: any) {
throw new Error('Method not implemented.');
}
@ -20,7 +21,7 @@ export class KeDaMap implements IMap {
setZoom(zoom) {
throw new Error('Method not implemented.');
}
setCenter([x,y]) {
setCenter([x, y]) {
throw new Error('Method not implemented.');
}
getZoom() {
@ -47,6 +48,7 @@ export class KeDaPixel implements IPixel {
constructor(x: number, y: number) {
this.self = [x, y];
}
discriminator: 'ISelf';
}
export class KeDaMarker implements IMarker {
@ -58,4 +60,21 @@ export class KeDaMarker implements IMarker {
};
this.self = d;
}
get id(): string {
throw new Error('Method not implemented.');
}
set id(str: string) {
throw new Error('Method not implemented.');
}
on(eventName: string, callback: Function): void {
throw new Error('Method not implemented.');
}
discriminator: 'ISelf';
}
export class KeDaLngLat implements ILngLat {
self: any;
constructor(x: number, y: number) {
this.self = new KMap.LngLat(x, y);
}
discriminator: 'ISelf';
}

20
src/modules/map/declare/map.d.ts vendored

@ -6,16 +6,17 @@
export interface ISelf {
self: any;
readonly discriminator: "ISelf";
}
export interface IMap extends ISelf {
on(eventName: string, callback: Function): void;
add(obj:any): any;
remove(obj:any): any;
setCity(city:string): any;
on(eventName: string, callback: Function);
add(obj: any): any;
remove(obj: any): any;
setCity(city: string): any;
setZoom(zoom: number): any;
getZoom(): any;
setCenter(x:number[]): any;
setCenter(x: number[]): any;
getCenter(): any;
}
@ -25,9 +26,18 @@ export interface IMapOptions {
}
export interface IMarker extends ISelf {
get id(): string;
set id(str: string);
on(eventName: string, callback: Function);
}
export class IMarkOptions {
position?: ILngLat;
content?: string;
offset?: IPixel;
}
export interface IPixel extends ISelf {
}

Loading…
Cancel
Save