|
|
|
import { HtmlRender, ICircle, IIcon, IIconOptions, ILayer, ILngLat, IMap, IMapOptions, IMarker, IMarkerCluster, IMarkOptions, IMouseTool, IInfoWindow, IPixel, IRenderClusterMarker, ISelf, ISize, PixelRender, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch } 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);
|
|
|
|
}
|
|
|
|
setBounds(zoom?: any, x?: any, y?: any, is?: boolean) {
|
|
|
|
this.self.setBounds(zoom,x,y,is)
|
|
|
|
}
|
|
|
|
setFitView(options: any) {
|
|
|
|
this.self.setFitView(options)
|
|
|
|
}
|
|
|
|
containerToLngLat(e: any) {
|
|
|
|
this.self.containerToLngLat(e)
|
|
|
|
}
|
|
|
|
clearMap() {
|
|
|
|
this.self.clearMap();
|
|
|
|
}
|
|
|
|
distance(a: number[], b: number[]) {
|
|
|
|
return AMap.GeometryUtil.distance(a, b);
|
|
|
|
}
|
|
|
|
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 | any) {
|
|
|
|
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.ExplicitConvert(options);
|
|
|
|
this.self = new AMap.Marker(conf);
|
|
|
|
this._position = this.self._position;
|
|
|
|
}
|
|
|
|
setContent(html: string) {
|
|
|
|
this.self.setContent(html)
|
|
|
|
}
|
|
|
|
setPosition(x: number[]) {
|
|
|
|
this.self.setPosition(x)
|
|
|
|
}
|
|
|
|
_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.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[]) {
|
|
|
|
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 GaodeIcon extends GaodeBasic implements IIcon {
|
|
|
|
constructor(options: IIconOptions) {
|
|
|
|
super();
|
|
|
|
options.size = options.size.self
|
|
|
|
options.imageSize = options.imageSize.self
|
|
|
|
this.self = new AMap.Icon(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeSize extends GaodeBasic implements ISize {
|
|
|
|
constructor(x: number, y: number) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.Size(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeTileLayer extends GaodeBasic implements ITileLayer {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
Satellite() {
|
|
|
|
this.self = new AMap.TileLayer.Satellite()
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
RoadNet() {
|
|
|
|
this.self = new AMap.TileLayer.RoadNet()
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeDriving extends GaodeBasic implements IDriving {
|
|
|
|
constructor(options: IDrivingOptions) {
|
|
|
|
super();
|
|
|
|
options.map = options.map.self
|
|
|
|
this.self = new AMap.Driving(options)
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.self.clear()
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.Autocomplete(city)
|
|
|
|
}
|
|
|
|
on(eventName: string, callback: Function) {
|
|
|
|
this.self.on(eventName, callback)
|
|
|
|
}
|
|
|
|
search(address: string, callback: Function) {
|
|
|
|
this.self.search(address, callback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.PlaceSearch()
|
|
|
|
}
|
|
|
|
search(text: string, callback: Function) {
|
|
|
|
return this.self.search(text,callback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeMouseTool extends GaodeBasic implements IMouseTool {
|
|
|
|
constructor(map: IMap) {
|
|
|
|
super();
|
|
|
|
this.self = new AMap.MouseTool(map.self);
|
|
|
|
}
|
|
|
|
rule(options: any) {
|
|
|
|
let conf = MapTools.ExplicitConvert(options);
|
|
|
|
return this.self.rule(conf)
|
|
|
|
}
|
|
|
|
measureArea(options: any) {
|
|
|
|
return this.self.measureArea(options)
|
|
|
|
}
|
|
|
|
close(isTrue: boolean) {
|
|
|
|
return this.self.close(isTrue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GaodeInfoWindow extends GaodeBasic implements IInfoWindow {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|