|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
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 { 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, AutocompleteSearch } from './map' |
|
|
|
|
import MapTools from './map-tools'; |
|
|
|
|
import * as global from 'globals'; |
|
|
|
|
import { SearchService } from '@src/app/searchComponent.service'; |
|
|
|
|
import { SearchDownList } from './component/SearchDownListPlugins/SearchDownList'; |
|
|
|
|
declare var AMap: any; |
|
|
|
|
declare var AMapUI: any; |
|
|
|
|
|
|
|
|
@ -10,13 +13,13 @@ class GaodeBasic implements ISelf {
|
|
|
|
|
|
|
|
|
|
export class GaoDeMap extends GaodeBasic implements IMap { |
|
|
|
|
/// plugins:同步加载插件
|
|
|
|
|
constructor(container: string, options: IMapOptions,plugins?:string[]) { |
|
|
|
|
constructor(container: string, options: IMapOptions, plugins?: string[]) { |
|
|
|
|
super(); |
|
|
|
|
this.self = new AMap.Map(container, options); |
|
|
|
|
if(!!plugins && plugins.length){ |
|
|
|
|
for(var i in plugins){ |
|
|
|
|
if (!!plugins && plugins.length) { |
|
|
|
|
for (var i in plugins) { |
|
|
|
|
let name = plugins[i]; |
|
|
|
|
if(name.indexOf('AMap.')==-1)continue; |
|
|
|
|
if (name.indexOf('AMap.') == -1) continue; |
|
|
|
|
let pObj = eval(`new ${plugins[i]}()`); |
|
|
|
|
this.self.plugin(pObj); |
|
|
|
|
} |
|
|
|
@ -38,7 +41,7 @@ export class GaoDeMap extends GaodeBasic implements IMap {
|
|
|
|
|
return this.self.setZoomAndCenter(zoom, pos) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
getBounds() { |
|
|
|
@ -59,9 +62,9 @@ export class GaoDeMap extends GaodeBasic implements IMap {
|
|
|
|
|
setCenter(pos: any) { |
|
|
|
|
return this.self.setCenter(pos) |
|
|
|
|
} |
|
|
|
|
getCenter():ILngLat { |
|
|
|
|
getCenter(): ILngLat { |
|
|
|
|
let d = this.self.getCenter(); |
|
|
|
|
return new GaoDeLngLat(0,0,d); |
|
|
|
|
return new GaoDeLngLat(0, 0, d); |
|
|
|
|
} |
|
|
|
|
getZoom() { |
|
|
|
|
return this.self.getZoom(); |
|
|
|
@ -238,7 +241,7 @@ export class GaoDePixel extends GaodeBasic implements IPixel {
|
|
|
|
|
this.self = new AMap.Pixel(x, y); |
|
|
|
|
} |
|
|
|
|
getArray(): number[] { |
|
|
|
|
return [this.x,this.y]; |
|
|
|
|
return [this.x, this.y]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
x: number; |
|
|
|
@ -255,8 +258,8 @@ export class GaoDeMarker extends GaodeBasic implements IMarker {
|
|
|
|
|
setContent(html: string) { |
|
|
|
|
return this.self.setContent(html) |
|
|
|
|
} |
|
|
|
|
setPosition(x: ILngLat|number[]) { |
|
|
|
|
x = (x as ILngLat).getArray == undefined ? x:(x as ILngLat).getArray(); |
|
|
|
|
setPosition(x: ILngLat | number[]) { |
|
|
|
|
x = (x as ILngLat).getArray == undefined ? x : (x as ILngLat).getArray(); |
|
|
|
|
return this.self.setPosition(x) |
|
|
|
|
} |
|
|
|
|
_position: number[] |
|
|
|
@ -279,7 +282,7 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster {
|
|
|
|
|
super(); |
|
|
|
|
let conf = MapTools.ExplicitConvert(options); |
|
|
|
|
|
|
|
|
|
AMap.plugin('AMap.MarkerClusterer',()=>{ |
|
|
|
|
AMap.plugin('AMap.MarkerClusterer', () => { |
|
|
|
|
this.self = new AMap.MarkerCluster(map.self, list, conf) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
@ -292,23 +295,23 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class GaoDeLngLat extends GaodeBasic implements ILngLat { |
|
|
|
|
constructor(x: number, y: number,me?:any) { |
|
|
|
|
constructor(x: number, y: number, me?: any) { |
|
|
|
|
super(); |
|
|
|
|
if(me==undefined) |
|
|
|
|
if (me == undefined) |
|
|
|
|
this.self = new AMap.LngLat(x, y); |
|
|
|
|
else |
|
|
|
|
this.self = me; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typeName="LngLat"; |
|
|
|
|
get KL():number{ |
|
|
|
|
typeName = "LngLat"; |
|
|
|
|
get KL(): number { |
|
|
|
|
return this.lng; |
|
|
|
|
} |
|
|
|
|
get kT():number{ |
|
|
|
|
get kT(): number { |
|
|
|
|
return this.lat; |
|
|
|
|
} |
|
|
|
|
getArray(): number[] { |
|
|
|
|
return [this.lng,this.lat]; |
|
|
|
|
return [this.lng, this.lat]; |
|
|
|
|
} |
|
|
|
|
get lng(): number { |
|
|
|
|
return this.self.lng; |
|
|
|
@ -316,7 +319,7 @@ export class GaoDeLngLat extends GaodeBasic implements ILngLat {
|
|
|
|
|
get lat(): number { |
|
|
|
|
return this.self.lat; |
|
|
|
|
} |
|
|
|
|
offset(x: number, y: number):ILngLat { |
|
|
|
|
offset(x: number, y: number): ILngLat { |
|
|
|
|
return this.self.offset(x, y) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -362,12 +365,12 @@ export class GaodeDriving extends GaodeBasic implements IDriving {
|
|
|
|
|
constructor(options: IDrivingOptions) { |
|
|
|
|
super(); |
|
|
|
|
options.map = options.map.self |
|
|
|
|
AMap.plugin('AMap.Driving',()=>{ |
|
|
|
|
AMap.plugin('AMap.Driving', () => { |
|
|
|
|
this.self = new AMap.Driving(options) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
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() { |
|
|
|
|
return this.self.clear() |
|
|
|
@ -375,38 +378,54 @@ export class GaodeDriving extends GaodeBasic implements IDriving {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete { |
|
|
|
|
private component:any |
|
|
|
|
constructor(options: any,component: any) { |
|
|
|
|
private component: any |
|
|
|
|
private searchDownList: SearchDownList |
|
|
|
|
constructor(options: any, component: any) { |
|
|
|
|
super(); |
|
|
|
|
this.component = component |
|
|
|
|
AMap.plugin('AMap.AutoComplete',()=>{ |
|
|
|
|
AMap.plugin('AMap.AutoComplete', () => { |
|
|
|
|
this.self = new AMap.Autocomplete(options) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.searchDownList = global.injector.get<SearchService>(SearchService).appendComponentToBody(SearchDownList).instance; |
|
|
|
|
this.searchDownList.init(options.input); |
|
|
|
|
|
|
|
|
|
this.self.on('complete', (e) => { |
|
|
|
|
console.log('search complete', e); |
|
|
|
|
this.searchDownList.searchList = e.tips || []; |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
on(eventName: string, callback: AutocompleteSelectCallback) { |
|
|
|
|
return this.self.on(eventName, (event)=>{ |
|
|
|
|
callback.call(this.component,event) |
|
|
|
|
}) |
|
|
|
|
this.searchDownList.setClickHander(e => { |
|
|
|
|
alert(e.name); |
|
|
|
|
callback(e); |
|
|
|
|
}); |
|
|
|
|
//$().addEventListener
|
|
|
|
|
// return this.self.on(eventName, (event) => {
|
|
|
|
|
// console.log('on event', event)
|
|
|
|
|
// callback.call(this.component, event)
|
|
|
|
|
// })
|
|
|
|
|
} |
|
|
|
|
search(address: string, callback: AutocompleteSearchCallback) { |
|
|
|
|
return this.self.search(address,(status,result)=>{ |
|
|
|
|
callback.call(this.component,status,result) |
|
|
|
|
return this.self.search(address, (status, result: AutocompleteSearch) => { |
|
|
|
|
this.searchDownList.searchList = result.tips || []; |
|
|
|
|
callback.call(this.component, status, result) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch { |
|
|
|
|
private component:any |
|
|
|
|
private component: any |
|
|
|
|
constructor(component: any) { |
|
|
|
|
super(); |
|
|
|
|
this.component = component |
|
|
|
|
AMap.plugin('AMap.PlaceSearch',()=>{ |
|
|
|
|
AMap.plugin('AMap.PlaceSearch', () => { |
|
|
|
|
this.self = new AMap.PlaceSearch() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
search(text: string, callback: PlaceSearchCallback) { |
|
|
|
|
return this.self.search(text,(status,result)=>{ |
|
|
|
|
callback.call(this.component,status,result) |
|
|
|
|
return this.self.search(text, (status, result) => { |
|
|
|
|
callback.call(this.component, status, result) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -414,7 +433,7 @@ export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch {
|
|
|
|
|
export class GaodeMouseTool extends GaodeBasic implements IMouseTool { |
|
|
|
|
constructor(map: IMap) { |
|
|
|
|
super(); |
|
|
|
|
AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"],()=>{ |
|
|
|
|
AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"], () => { |
|
|
|
|
this.self = new AMap.MouseTool(map.self); |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|