|
|
|
import { HtmlRender, ICircle, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, InfoWindow, IPixel, IRenderClusterMarker, ISelf, PixelRender } from './map'
|
|
|
|
import MapTools from './map-tools';
|
|
|
|
declare var AMap: any;
|
|
|
|
|
|
|
|
class GaodeBasic implements ISelf {
|
|
|
|
self: any;
|
|
|
|
discriminator: string = "ISelf";
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDeMap extends GaodeBasic implements IMap {
|
|
|
|
constructor(container: string, options: IMapOptions) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.Map(container, options);
|
|
|
|
}
|
|
|
|
getCity(callback: Function) {
|
|
|
|
return this.self.getCity(callback)
|
|
|
|
}
|
|
|
|
setZoomAndCenter(zoom: number, pos: number[]) {
|
|
|
|
return this.self.setZoomAndCenter(zoom, pos)
|
|
|
|
}
|
|
|
|
plugin(eventName: string[], callback: Function) {
|
|
|
|
return this.self.plugin(eventName, callback)
|
|
|
|
}
|
|
|
|
getBounds() {
|
|
|
|
return this.self.getBounds()
|
|
|
|
}
|
|
|
|
add(obj: IMarker) {
|
|
|
|
return this.self.add(obj.self)
|
|
|
|
}
|
|
|
|
remove(obj: any) {
|
|
|
|
return this.self.remove(obj.self)
|
|
|
|
}
|
|
|
|
setCity(city: string) {
|
|
|
|
return this.self.setCity(city)
|
|
|
|
}
|
|
|
|
setZoom(zoom) {
|
|
|
|
return this.self.setZoom(zoom)
|
|
|
|
}
|
|
|
|
setCenter([x, y]) {
|
|
|
|
return this.self.setCenter([x, y])
|
|
|
|
}
|
|
|
|
getCenter() {
|
|
|
|
return this.self.getCenter();
|
|
|
|
}
|
|
|
|
getZoom() {
|
|
|
|
return this.self.getZoom();
|
|
|
|
}
|
|
|
|
on(eventName: string, callback: Function): void {
|
|
|
|
this.self.on(eventName, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDePixel extends GaodeBasic implements IPixel {
|
|
|
|
constructor(x: number, y: number) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.Pixel(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDeMarker extends GaodeBasic implements IMarker {
|
|
|
|
constructor(options: IMarkOptions) {
|
|
|
|
super();
|
|
|
|
let conf = MapTools.InstanceConvert(options);
|
|
|
|
this.self = new AMap.Marker(conf);
|
|
|
|
this._position = this.self._position;
|
|
|
|
}
|
|
|
|
_position: number[]
|
|
|
|
setMap() {
|
|
|
|
this.self.setMap(null)
|
|
|
|
}
|
|
|
|
get id(): string {
|
|
|
|
return this.self.id;
|
|
|
|
}
|
|
|
|
set id(str: string) {
|
|
|
|
this.self.id = str;
|
|
|
|
}
|
|
|
|
on(eventName: string, callback: Function): void {
|
|
|
|
this.self.on(eventName, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster {
|
|
|
|
constructor(map: IMap, list: Object[], options: any) {
|
|
|
|
super();
|
|
|
|
let conf = MapTools.InstanceConvert(options);
|
|
|
|
this.self = new AMap.MarkerCluster(map.self, list, conf)
|
|
|
|
}
|
|
|
|
on(eventName: string, callback: Function): void {
|
|
|
|
this.self.on(eventName, callback);
|
|
|
|
}
|
|
|
|
setData(list:any[]) {
|
|
|
|
this.self.setData(list)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDeLngLat extends GaodeBasic implements ILngLat {
|
|
|
|
constructor(x: number, y: number) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.LngLat(x, y);
|
|
|
|
}
|
|
|
|
offset(x: number, y: number) {
|
|
|
|
return this.self.offset(x, y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeLayer extends GaodeBasic implements ILayer {
|
|
|
|
constructor(options: any) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.createDefaultLayer(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeInfoWindow extends GaodeBasic implements InfoWindow {
|
|
|
|
constructor(options: any) {
|
|
|
|
super();
|
|
|
|
options.offset = options.offset.self
|
|
|
|
this.self = new AMap.InfoWindow(options);
|
|
|
|
}
|
|
|
|
open(map: IMap) {
|
|
|
|
return this.self.open(map.self)
|
|
|
|
}
|
|
|
|
listen(html: any, event: string, callback: Function) {
|
|
|
|
return this.self.listen(html,event,callback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeCircle extends GaodeBasic implements ICircle {
|
|
|
|
constructor(options: Object) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.Circle(options);
|
|
|
|
}
|
|
|
|
setMap(map: IMap) {
|
|
|
|
return this.self.setMap(map.self)
|
|
|
|
}
|
|
|
|
setCenter(pos: number[]) {
|
|
|
|
return this.self.setCenter(pos)
|
|
|
|
}
|
|
|
|
setRadius(num: number) {
|
|
|
|
return this.self.setRadius(num)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaoDeRenderClusterMarker implements IRenderClusterMarker, ISelf {
|
|
|
|
discriminator: string = "ISelfCombine";
|
|
|
|
getFirstImages(context: any): string {
|
|
|
|
return context.data[0].image;
|
|
|
|
}
|
|
|
|
contentRender: HtmlRender;
|
|
|
|
contentNonRender: HtmlRender;
|
|
|
|
pixelRender: PixelRender;
|
|
|
|
pixelNonRender: PixelRender;
|
|
|
|
get self(): any {
|
|
|
|
return {
|
|
|
|
renderClusterMarker: (context) => {
|
|
|
|
context.marker.setContent(this.contentRender(context.count));
|
|
|
|
context.marker.setOffset(this.pixelRender(context.count).self);
|
|
|
|
},
|
|
|
|
renderMarker: (context) => {
|
|
|
|
context.marker.setContent(this.contentNonRender(this.getFirstImages(context)));
|
|
|
|
context.marker.setOffset(this.pixelNonRender(context.count).self);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|