|
|
@ -1,4 +1,4 @@ |
|
|
|
import { HtmlRender, ICircle, IIcon, IIconOptions, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IInfoWindow, IPixel, IRenderClusterMarker, ISelf, ISize, PixelRender, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch, AutoCompleteSearchCallback, AutoCompleteSearchResultDto } from './map' |
|
|
|
import { HtmlRender, ICircle, IIcon, IIconOptions, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IInfoWindow, IPixel, IRenderClusterMarker, ISelf, ISize, PixelRender, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch, AutocompleteSearchCallback, AutocompleteSelectCallback, PlaceSearchCallback } from './map' |
|
|
|
import MapTools from './map-tools'; |
|
|
|
import MapTools from './map-tools'; |
|
|
|
declare var AMap: any; |
|
|
|
declare var AMap: any; |
|
|
|
declare var AMapUI: any; |
|
|
|
declare var AMapUI: any; |
|
|
@ -10,13 +10,13 @@ class GaodeBasic implements ISelf { |
|
|
|
|
|
|
|
|
|
|
|
export class GaoDeMap extends GaodeBasic implements IMap { |
|
|
|
export class GaoDeMap extends GaodeBasic implements IMap { |
|
|
|
/// plugins:同步加载插件
|
|
|
|
/// plugins:同步加载插件
|
|
|
|
constructor(container: string, options: IMapOptions, plugins?: string[]) { |
|
|
|
constructor(container: string, options: IMapOptions,plugins?:string[]) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
this.self = new AMap.Map(container, options); |
|
|
|
this.self = new AMap.Map(container, options); |
|
|
|
if (!!plugins && plugins.length) { |
|
|
|
if(!!plugins && plugins.length){ |
|
|
|
for (var i in plugins) { |
|
|
|
for(var i in plugins){ |
|
|
|
let name = plugins[i]; |
|
|
|
let name = plugins[i]; |
|
|
|
if (name.indexOf('AMap.') == -1) continue; |
|
|
|
if(name.indexOf('AMap.')==-1)continue; |
|
|
|
let pObj = eval(`new ${plugins[i]}()`); |
|
|
|
let pObj = eval(`new ${plugins[i]}()`); |
|
|
|
this.self.plugin(pObj); |
|
|
|
this.self.plugin(pObj); |
|
|
|
} |
|
|
|
} |
|
|
@ -38,7 +38,7 @@ export class GaoDeMap extends GaodeBasic implements IMap { |
|
|
|
return this.self.setZoomAndCenter(zoom, pos) |
|
|
|
return this.self.setZoomAndCenter(zoom, pos) |
|
|
|
} |
|
|
|
} |
|
|
|
plugin(pluginNames: string[], callback: Function) { |
|
|
|
plugin(pluginNames: string[], callback: Function) { |
|
|
|
let names = pluginNames.filter(s => s.indexOf("AMap.") == 0); |
|
|
|
let names = pluginNames.filter(s=>s.indexOf("AMap.")==0); |
|
|
|
return this.self.plugin(names, callback) |
|
|
|
return this.self.plugin(names, callback) |
|
|
|
} |
|
|
|
} |
|
|
|
getBounds() { |
|
|
|
getBounds() { |
|
|
@ -59,9 +59,9 @@ export class GaoDeMap extends GaodeBasic implements IMap { |
|
|
|
setCenter(pos: any) { |
|
|
|
setCenter(pos: any) { |
|
|
|
return this.self.setCenter(pos) |
|
|
|
return this.self.setCenter(pos) |
|
|
|
} |
|
|
|
} |
|
|
|
getCenter(): ILngLat { |
|
|
|
getCenter():ILngLat { |
|
|
|
let d = this.self.getCenter(); |
|
|
|
let d = this.self.getCenter(); |
|
|
|
return new GaoDeLngLat(0, 0, d); |
|
|
|
return new GaoDeLngLat(0,0,d); |
|
|
|
} |
|
|
|
} |
|
|
|
getZoom() { |
|
|
|
getZoom() { |
|
|
|
return this.self.getZoom(); |
|
|
|
return this.self.getZoom(); |
|
|
@ -238,7 +238,7 @@ export class GaoDePixel extends GaodeBasic implements IPixel { |
|
|
|
this.self = new AMap.Pixel(x, y); |
|
|
|
this.self = new AMap.Pixel(x, y); |
|
|
|
} |
|
|
|
} |
|
|
|
getArray(): number[] { |
|
|
|
getArray(): number[] { |
|
|
|
return [this.x, this.y]; |
|
|
|
return [this.x,this.y]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
x: number; |
|
|
|
x: number; |
|
|
@ -255,8 +255,8 @@ export class GaoDeMarker extends GaodeBasic implements IMarker { |
|
|
|
setContent(html: string) { |
|
|
|
setContent(html: string) { |
|
|
|
return this.self.setContent(html) |
|
|
|
return this.self.setContent(html) |
|
|
|
} |
|
|
|
} |
|
|
|
setPosition(x: ILngLat | number[]) { |
|
|
|
setPosition(x: ILngLat|number[]) { |
|
|
|
x = (x as ILngLat).getArray == undefined ? x : (x as ILngLat).getArray(); |
|
|
|
x = (x as ILngLat).getArray == undefined ? x:(x as ILngLat).getArray(); |
|
|
|
return this.self.setPosition(x) |
|
|
|
return this.self.setPosition(x) |
|
|
|
} |
|
|
|
} |
|
|
|
_position: number[] |
|
|
|
_position: number[] |
|
|
@ -279,7 +279,7 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
let conf = MapTools.ExplicitConvert(options); |
|
|
|
let conf = MapTools.ExplicitConvert(options); |
|
|
|
|
|
|
|
|
|
|
|
AMap.plugin('AMap.MarkerClusterer', () => { |
|
|
|
AMap.plugin('AMap.MarkerClusterer',()=>{ |
|
|
|
this.self = new AMap.MarkerCluster(map.self, list, conf) |
|
|
|
this.self = new AMap.MarkerCluster(map.self, list, conf) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -292,23 +292,23 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class GaoDeLngLat extends GaodeBasic implements ILngLat { |
|
|
|
export class GaoDeLngLat extends GaodeBasic implements ILngLat { |
|
|
|
constructor(x: number, y: number, me?: any) { |
|
|
|
constructor(x: number, y: number,me?:any) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
if (me == undefined) |
|
|
|
if(me==undefined) |
|
|
|
this.self = new AMap.LngLat(x, y); |
|
|
|
this.self = new AMap.LngLat(x, y); |
|
|
|
else |
|
|
|
else |
|
|
|
this.self = me; |
|
|
|
this.self = me; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
typeName = "LngLat"; |
|
|
|
typeName="LngLat"; |
|
|
|
get KL(): number { |
|
|
|
get KL():number{ |
|
|
|
return this.lng; |
|
|
|
return this.lng; |
|
|
|
} |
|
|
|
} |
|
|
|
get kT(): number { |
|
|
|
get kT():number{ |
|
|
|
return this.lat; |
|
|
|
return this.lat; |
|
|
|
} |
|
|
|
} |
|
|
|
getArray(): number[] { |
|
|
|
getArray(): number[] { |
|
|
|
return [this.lng, this.lat]; |
|
|
|
return [this.lng,this.lat]; |
|
|
|
} |
|
|
|
} |
|
|
|
get lng(): number { |
|
|
|
get lng(): number { |
|
|
|
return this.self.lng; |
|
|
|
return this.self.lng; |
|
|
@ -316,7 +316,7 @@ export class GaoDeLngLat extends GaodeBasic implements ILngLat { |
|
|
|
get lat(): number { |
|
|
|
get lat(): number { |
|
|
|
return this.self.lat; |
|
|
|
return this.self.lat; |
|
|
|
} |
|
|
|
} |
|
|
|
offset(x: number, y: number): ILngLat { |
|
|
|
offset(x: number, y: number):ILngLat { |
|
|
|
return this.self.offset(x, y) |
|
|
|
return this.self.offset(x, y) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -362,53 +362,59 @@ export class GaodeDriving extends GaodeBasic implements IDriving { |
|
|
|
constructor(options: IDrivingOptions) { |
|
|
|
constructor(options: IDrivingOptions) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
options.map = options.map.self |
|
|
|
options.map = options.map.self |
|
|
|
AMap.plugin('AMap.Driving', () => { |
|
|
|
AMap.plugin('AMap.Driving',()=>{ |
|
|
|
this.self = new AMap.Driving(options) |
|
|
|
this.self = new AMap.Driving(options) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
search(posStart?: ILngLat, posEnd?: ILngLat, callback?: Function) { |
|
|
|
search(posStart?: ILngLat, posEnd?: ILngLat, callback?: Function) { |
|
|
|
return this.self.search(posStart.getArray(), posEnd.getArray(), callback) |
|
|
|
return this.self.search(posStart.getArray(),posEnd.getArray(),callback) |
|
|
|
} |
|
|
|
} |
|
|
|
clear() { |
|
|
|
clear() { |
|
|
|
return this.self.clear() |
|
|
|
return this.self.clear() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete { |
|
|
|
export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete { |
|
|
|
constructor(city: Object) { |
|
|
|
private component:any |
|
|
|
|
|
|
|
constructor(options: any,component: any) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
AMap.plugin('AMap.AutoComplete', () => { |
|
|
|
this.component = component |
|
|
|
this.self = new AMap.Autocomplete(city) |
|
|
|
AMap.plugin('AMap.AutoComplete',()=>{ |
|
|
|
|
|
|
|
this.self = new AMap.Autocomplete(options) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
search(address: string, callback: AutoCompleteSearchCallback) { |
|
|
|
on(eventName: string, callback: AutocompleteSelectCallback) { |
|
|
|
return this.self.search(address, (status, result) => { |
|
|
|
return this.self.on(eventName, (event)=>{ |
|
|
|
callback(result.tips as AutoCompleteSearchResultDto[]); |
|
|
|
callback.call(this.component,event) |
|
|
|
}); |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
on(eventName: string, callback: Function) { |
|
|
|
search(address: string, callback: AutocompleteSearchCallback) { |
|
|
|
return this.self.on(eventName, callback) |
|
|
|
return this.self.search(address,(status,result)=>{ |
|
|
|
|
|
|
|
callback.call(this.component,status,result) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch { |
|
|
|
export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch { |
|
|
|
constructor() { |
|
|
|
private component:any |
|
|
|
|
|
|
|
constructor(component: any) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
AMap.plugin('AMap.PlaceSearch', () => { |
|
|
|
this.component = component |
|
|
|
|
|
|
|
AMap.plugin('AMap.PlaceSearch',()=>{ |
|
|
|
this.self = new AMap.PlaceSearch() |
|
|
|
this.self = new AMap.PlaceSearch() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
search(text: string, callback: Function) { |
|
|
|
search(text: string, callback: PlaceSearchCallback) { |
|
|
|
return this.self.search(text, callback) |
|
|
|
return this.self.search(text,(status,result)=>{ |
|
|
|
|
|
|
|
callback.call(this.component,status,result) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class GaodeMouseTool extends GaodeBasic implements IMouseTool { |
|
|
|
export class GaodeMouseTool extends GaodeBasic implements IMouseTool { |
|
|
|
constructor(map: IMap) { |
|
|
|
constructor(map: IMap) { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"], () => { |
|
|
|
AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"],()=>{ |
|
|
|
this.self = new AMap.MouseTool(map.self); |
|
|
|
this.self = new AMap.MouseTool(map.self); |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|