diff --git a/src/modules/map/declare/factory.ts b/src/modules/map/declare/factory.ts index 6ab2536..5e76edf 100644 --- a/src/modules/map/declare/factory.ts +++ b/src/modules/map/declare/factory.ts @@ -7,7 +7,7 @@ import MapTools from './map-tools'; export class MapFactory { public static MapInstance(container: string, options: IMapOptions | any): IMap { - let config = MapTools.InstanceConvert(options); + let config = MapTools.ExplicitConvert(options); switch (mapSupplier) { case 1: return new GaoDeMap(container, config); case 2: return new KeDaMap(container, config); @@ -54,7 +54,7 @@ export class MapFactory { public static SizeInstance(x: number, y: number): ISize { switch (mapSupplier) { - case 1: return new GaodeSize(x,y); + case 1: return new GaodeSize(x, y); default: return null; } } @@ -80,7 +80,7 @@ export class MapFactory { } } - public static AutocompleteInstance(city:Object): IAutocomplete { + public static AutocompleteInstance(city: Object): IAutocomplete { switch (mapSupplier) { case 1: return new GaodeAutocomplete(city); default: return null; @@ -94,7 +94,7 @@ export class MapFactory { } } - public static MouseToolInstance(map:IMap): IMouseTool { + public static MouseToolInstance(map: IMap): IMouseTool { switch (mapSupplier) { case 1: return new GaodeMouseTool(map); default: return null; diff --git a/src/modules/map/declare/gaode-map.ts b/src/modules/map/declare/gaode-map.ts index be9a487..982023b 100644 --- a/src/modules/map/declare/gaode-map.ts +++ b/src/modules/map/declare/gaode-map.ts @@ -39,7 +39,7 @@ export class GaoDeMap extends GaodeBasic implements IMap { getBounds() { return this.self.getBounds() } - add(obj: IMarker|any) { + add(obj: IMarker | any) { return this.self.add(obj.self) } remove(obj: any) { @@ -75,7 +75,7 @@ export class GaoDePixel extends GaodeBasic implements IPixel { export class GaoDeMarker extends GaodeBasic implements IMarker { constructor(options: IMarkOptions) { super(); - let conf = MapTools.InstanceConvert(options); + let conf = MapTools.ExplicitConvert(options); this.self = new AMap.Marker(conf); this._position = this.self._position; } @@ -103,13 +103,13 @@ export class GaoDeMarker extends GaodeBasic implements IMarker { export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster { constructor(map: IMap, list: Object[], options: any) { super(); - let conf = MapTools.InstanceConvert(options); + let conf = MapTools.ExplicitConvert(options); this.self = new AMap.MarkerCluster(map.self, list, conf) } on(eventName: string, callback: Function): void { this.self.on(eventName, callback); } - setData(list:any[]) { + setData(list: any[]) { this.self.setData(list) } } @@ -141,9 +141,9 @@ export class GaodeIcon extends GaodeBasic implements IIcon { } export class GaodeSize extends GaodeBasic implements ISize { - constructor(x:number, y:number) { + constructor(x: number, y: number) { super(); - this.self = new AMap.Size(x,y); + this.self = new AMap.Size(x, y); } } @@ -170,21 +170,21 @@ export class GaodeDriving extends GaodeBasic implements IDriving { clear() { this.self.clear() } - search(x:any, y:any, callback:Function) { - this.self.search(x.self,y.self,callback) + search(x: any, y: any, callback: Function) { + this.self.search(x.self, y.self, callback) } } export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete { - constructor(city:Object) { + constructor(city: Object) { super(); this.self = new AMap.Autocomplete(city) } on(eventName: string, callback: Function) { - this.self.on(eventName,callback) + this.self.on(eventName, callback) } search(address: string, callback: Function) { - this.self.search(address,callback) + this.self.search(address, callback) } } @@ -204,7 +204,7 @@ export class GaodeMouseTool extends GaodeBasic implements IMouseTool { this.self = new AMap.MouseTool(map.self); } rule(options: any) { - let conf = MapTools.InstanceConvert(options); + let conf = MapTools.ExplicitConvert(options); return this.self.rule(conf) } measureArea(options: any) { @@ -225,7 +225,7 @@ export class GaodeInfoWindow extends GaodeBasic implements IInfoWindow { return this.self.open(map.self) } listen(html: any, event: string, callback: Function) { - return this.self.listen(html,event,callback) + return this.self.listen(html, event, callback) } } diff --git a/src/modules/map/declare/map-tools.ts b/src/modules/map/declare/map-tools.ts index 3293790..5b19fcb 100644 --- a/src/modules/map/declare/map-tools.ts +++ b/src/modules/map/declare/map-tools.ts @@ -1,12 +1,13 @@ export default class MapTools { - public static InstanceConvert(data: any): any { + //显式转换 + public static ExplicitConvert(data: any): any { if (data == null) { return } let obj = Object.assign({}, data); let convert = (obj: any, data: string) => { - if(!obj[data])return; + if (!obj[data]) return; if (obj[data].discriminator === "ISelf") { obj[data] = obj[data].self; } else if (obj[data].discriminator === "ISelfCombine") { @@ -14,27 +15,27 @@ export default class MapTools { } } - let process = (obj: any,deep:number=0) => { - try{ - deep++; - if(deep>=4)return; - if (obj == undefined) return; - if (!(obj instanceof Object)) return; - for (var name in obj) { - if (obj[name] instanceof Array) { - for (var j in obj[name]) { - convert(obj[name],j); - process(obj[name][j],deep); + let process = (obj: any, deep: number = 0) => { + try { + deep++; + if (deep >= 4) return; + if (obj == undefined) return; + if (!(obj instanceof Object)) return; + for (var name in obj) { + if (obj[name] instanceof Array) { + for (var j in obj[name]) { + convert(obj[name], j); + process(obj[name][j], deep); + } + continue; } - continue; + convert(obj, name); + process(obj[name], deep); } - convert(obj, name); - process(obj[name],deep); + } catch (e) { + console.log(e); + debugger } - }catch(e){ - console.log(e); - debugger - } } process(obj); return obj;