Browse Source

包装器实例化 数据优化

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

18
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 * as ObjectID from 'bson-objectid';
import { AxMessageSystem } from 'src/app/working-area/model/axMessageSystem'; import { AxMessageSystem } from 'src/app/working-area/model/axMessageSystem';
import { MapFactory } from 'src/modules/map/declare/factory'; 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 var AMap: any
declare global { declare global {
@ -1452,14 +1452,14 @@ export class CollectionToolsPlanComponent implements OnInit {
// 将 icon 传入 marker // 将 icon 传入 marker
let startMarker = MapFactory.MarkerInstance({ 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 // 将 html 传给 content
content: markerContent, content: markerContent,
// 以 icon 的 [center bottom] 为原点 // 以 icon 的 [center bottom] 为原点
//offset: MapFactory.PixelInstance(-13,-30).self, //offset: MapFactory.PixelInstance(-13,-30,
offset: MapFactory.PixelInstance(-13, 30).self, offset: MapFactory.PixelInstance(-13, 30),
draggable: editable == '1' ? true : false, draggable: editable == '1' ? true : false,
}).self } as IMarkOptions)
startMarker.id = element.Id startMarker.id = element.Id
startMarker.on('click', (e) => { startMarker.on('click', (e) => {
@ -2239,14 +2239,14 @@ export class CollectionToolsPlanComponent implements OnInit {
'</div>'; '</div>';
// 将 icon 传入 marker // 将 icon 传入 marker
let startMarker = MapFactory.MarkerInstance({ let startMarker: IMarker = MapFactory.MarkerInstance({
position: new AMap.LngLat(e.lnglat.lng, e.lnglat.lat), position: MapFactory.LngLatInstance(e.lnglat.lng, e.lnglat.lat),
// 将 html 传给 content // 将 html 传给 content
content: markerContent, content: markerContent,
// 以 icon 的 [center bottom] 为原点 // 以 icon 的 [center bottom] 为原点
offset: MapFactory.PixelInstance(-13, -30).self, offset: MapFactory.PixelInstance(-13, -30),
draggable: true, draggable: true,
}).self; } as IMarkOptions);
startMarker.id = id startMarker.id = id
startMarker.on('click', (e) => { startMarker.on('click', (e) => {

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

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

26
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; declare var AMap: any;
export class GaoDeMap implements IMap { export class GaoDeMap implements IMap {
@ -6,6 +7,7 @@ export class GaoDeMap implements IMap {
constructor(container: string, options: IMapOptions) { constructor(container: string, options: IMapOptions) {
this.self = new AMap.Map(container, options); this.self = new AMap.Map(container, options);
} }
discriminator: 'ISelf';
add(obj: any) { add(obj: any) {
return this.self.add(obj) return this.self.add(obj)
} }
@ -37,11 +39,31 @@ export class GaoDePixel implements IPixel {
constructor(x: number, y: number) { constructor(x: number, y: number) {
this.self = new AMap.Pixel(x, y); this.self = new AMap.Pixel(x, y);
} }
discriminator: 'ISelf';
} }
export class GaoDeMarker implements IMarker { export class GaoDeMarker implements IMarker {
self: any; self: any;
constructor(options: any) { constructor(options: IMarkOptions) {
let conf = MapTools.InstanceConvert(options);
this.self = new AMap.Marker(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';
} }

21
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; declare var KMap: any;
export class KeDaMap implements IMap { export class KeDaMap implements IMap {
@ -8,6 +8,7 @@ export class KeDaMap implements IMap {
opt.configUrl = ""; opt.configUrl = "";
this.self = new KMap(opt); this.self = new KMap(opt);
} }
discriminator: 'ISelf';
add(obj: any) { add(obj: any) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -47,6 +48,7 @@ export class KeDaPixel implements IPixel {
constructor(x: number, y: number) { constructor(x: number, y: number) {
this.self = [x, y]; this.self = [x, y];
} }
discriminator: 'ISelf';
} }
export class KeDaMarker implements IMarker { export class KeDaMarker implements IMarker {
@ -58,4 +60,21 @@ export class KeDaMarker implements IMarker {
}; };
this.self = d; 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';
} }

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

@ -6,10 +6,11 @@
export interface ISelf { export interface ISelf {
self: any; self: any;
readonly discriminator: "ISelf";
} }
export interface IMap extends ISelf { export interface IMap extends ISelf {
on(eventName: string, callback: Function): void; on(eventName: string, callback: Function);
add(obj: any): any; add(obj: any): any;
remove(obj: any): any; remove(obj: any): any;
setCity(city: string): any; setCity(city: string): any;
@ -25,9 +26,18 @@ export interface IMapOptions {
} }
export interface IMarker extends ISelf { 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 { export interface IPixel extends ISelf {
} }

Loading…
Cancel
Save