|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import { ILngLat, IMap, IMapOptions, IMarker, IPixel, ISelf, ITileLayer } from './map' |
|
|
|
|
import { IInfoWindow, ILngLat, IMap, IMapOptions, IMarker, IMarkOptions, IMouseTool, IPixel, ISelf, ITileLayer } from './map' |
|
|
|
|
import * as ObjectID from 'bson-objectid'; |
|
|
|
|
declare var KMap: any; |
|
|
|
|
|
|
|
|
|
class KedaBasic implements ISelf { |
|
|
|
@ -34,6 +35,16 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
opt.onLoadMap = mapLayer |
|
|
|
|
this.self = new KMap(opt); |
|
|
|
|
} |
|
|
|
|
containerToLngLat(e: IPixel): ILngLat { |
|
|
|
|
let d = null; |
|
|
|
|
this.self.getGeoPointByPixel({ |
|
|
|
|
ePoint:e.self, |
|
|
|
|
callback:(e)=>{ |
|
|
|
|
d = new KeDaLngLat(e.data.lng,e.data.lat); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
return d; |
|
|
|
|
} |
|
|
|
|
setAdministrativeAreaStyle(conponent: any, getData?: Function, setData?: Function) { //自定义 行政区划 样式
|
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
@ -43,9 +54,7 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
setFitView(options: any) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
containerToLngLat(e: any) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
clearMap() { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
@ -56,7 +65,10 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
setZoomAndCenter(zoom: number, pos: number[]) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
this.self.flyTo({ |
|
|
|
|
zoom: zoom, |
|
|
|
|
point: pos, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
plugin(eventName: string[], callback: Function) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
@ -65,10 +77,23 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
add(obj: any) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
if(obj && obj.typeName === "KeDaMarker"){ |
|
|
|
|
let _marker = (obj as KeDaMarker); |
|
|
|
|
_marker.map = this; |
|
|
|
|
_marker.startBindEvent(); |
|
|
|
|
} |
|
|
|
|
if (obj == "卫星图层") { |
|
|
|
|
this.self.setImageLayer({ display: true }) |
|
|
|
|
} else if (obj == "路网图层") { |
|
|
|
|
this.self.setMapStyle({ solution: '8888' }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
remove(obj: any) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
if (obj == "卫星图层") { |
|
|
|
|
this.self.setImageLayer({ display: false }) |
|
|
|
|
} else if (obj == "路网图层") { |
|
|
|
|
this.self.setMapStyle({ solution: '9999' }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
setCity(city: string) { |
|
|
|
|
let that = this |
|
|
|
@ -95,8 +120,14 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
}) |
|
|
|
|
return num |
|
|
|
|
} |
|
|
|
|
setCenter(pos: number[]) { |
|
|
|
|
this.self.flyTo({point:pos}) |
|
|
|
|
setCenter(pos: number[] | ILngLat) { |
|
|
|
|
let position = [] |
|
|
|
|
if (pos instanceof Array) { |
|
|
|
|
position = pos |
|
|
|
|
} else { |
|
|
|
|
position = [pos.lng, pos.lat]; |
|
|
|
|
} |
|
|
|
|
this.self.flyTo({ point: position }) |
|
|
|
|
} |
|
|
|
|
getCenter() { |
|
|
|
|
let center |
|
|
|
@ -118,64 +149,290 @@ export class KeDaMap extends KedaBasic implements IMap {
|
|
|
|
|
handler: callback |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class KeDaPixel extends KedaBasic implements IPixel { |
|
|
|
|
constructor(x: number, y: number) { |
|
|
|
|
super(); |
|
|
|
|
this.x = x; |
|
|
|
|
this.y = y; |
|
|
|
|
this.self = [x, y]; |
|
|
|
|
} |
|
|
|
|
getArray(): number[] { |
|
|
|
|
return this. self; |
|
|
|
|
} |
|
|
|
|
x: number; |
|
|
|
|
y: number; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class KeDaMarker extends KedaBasic implements IMarker { |
|
|
|
|
constructor(options: any) { |
|
|
|
|
public map:KeDaMap; |
|
|
|
|
public typeName:string = "KeDaMarker"; |
|
|
|
|
constructor(options: IMarkOptions) { |
|
|
|
|
super(); |
|
|
|
|
let pos = [] |
|
|
|
|
if (options.position instanceof Array) { |
|
|
|
|
pos = options.position |
|
|
|
|
} else { |
|
|
|
|
pos = options.position.getArray() |
|
|
|
|
} |
|
|
|
|
let d = { |
|
|
|
|
offset: options.offset, |
|
|
|
|
element: options.content |
|
|
|
|
url: '/assets/images/dingwei.png', |
|
|
|
|
point: pos, |
|
|
|
|
offset: options.offset? options.offset.self : null, |
|
|
|
|
ended: (res) => {this.id = res.data;} |
|
|
|
|
}; |
|
|
|
|
this.self = d; |
|
|
|
|
this._position = pos |
|
|
|
|
if (options.map) { |
|
|
|
|
this.map = options.map as KeDaMap |
|
|
|
|
this.map.self.addMarker(this.self); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_position: number[]; |
|
|
|
|
setContent(html: string) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
setPosition(x: number[]) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
_position: number[]; |
|
|
|
|
setMap() { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
} |
|
|
|
|
get id(): string { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
return this.self.id |
|
|
|
|
} |
|
|
|
|
set id(str: string) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
this.self.id = str |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bindObj=[]; // event
|
|
|
|
|
on(eventName: string, callback: Function): void { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
this.bindObj.push({ |
|
|
|
|
eventName:eventName, |
|
|
|
|
callback:callback, |
|
|
|
|
}); |
|
|
|
|
this.startBindEvent(); |
|
|
|
|
} |
|
|
|
|
startBindEvent(){ |
|
|
|
|
if(this.map!==undefined){ |
|
|
|
|
this.bindObj.forEach((item,index)=>{ |
|
|
|
|
this.map.self.addEventOnMarkers({ |
|
|
|
|
selector: `#${this.id}`, |
|
|
|
|
event: item.eventName, |
|
|
|
|
handler: item.callback, |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
this.bindObj = []; |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
export class KeDaLngLat extends KedaBasic implements ILngLat { |
|
|
|
|
constructor(x: number, y: number) { |
|
|
|
|
constructor(lng: number, lat: number) { |
|
|
|
|
super(); |
|
|
|
|
this.self = new KMap.LngLat(x, y); |
|
|
|
|
this.lng = lng |
|
|
|
|
this.lat = lat |
|
|
|
|
this.self = this; |
|
|
|
|
} |
|
|
|
|
offset(x: number, y: number): ILngLat{ |
|
|
|
|
return x = 2 * Math.asin(Math.sin(Math.round(x)/12756274) / Math.cos(this.kT* Math.PI / 180)), |
|
|
|
|
x = this.KL + 180 *x / Math.PI, |
|
|
|
|
y = 2*Math.asin(Math.round(y)/12756274), |
|
|
|
|
new KeDaLngLat(x,y); |
|
|
|
|
} |
|
|
|
|
typeName="LngLat"; |
|
|
|
|
lng: number; |
|
|
|
|
lat: number; |
|
|
|
|
offset(x: number, y: number) { |
|
|
|
|
throw new Error('Method not implemented.'); |
|
|
|
|
get KL():number{ |
|
|
|
|
return this.lng; |
|
|
|
|
} |
|
|
|
|
get kT():number{ |
|
|
|
|
return this.lat; |
|
|
|
|
} |
|
|
|
|
getArray(): number[] { |
|
|
|
|
return [this.lng,this.lat]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class KedaInfoWindow extends KedaBasic implements IInfoWindow { //信息窗体
|
|
|
|
|
constructor(options) { |
|
|
|
|
super(); |
|
|
|
|
let opt = { |
|
|
|
|
htmlText: options.content, |
|
|
|
|
anchor: 'bottom', |
|
|
|
|
point: options.position, |
|
|
|
|
closeButton: true, |
|
|
|
|
} |
|
|
|
|
this.self = opt |
|
|
|
|
} |
|
|
|
|
open(map: IMap) { |
|
|
|
|
map.self.addPopup(this.self); |
|
|
|
|
} |
|
|
|
|
listen(html: any, event: string, callback: Function) { |
|
|
|
|
html.addEventListener(event,callback) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class KedaTileLayer extends KedaBasic implements ITileLayer { |
|
|
|
|
export class KedaTileLayer extends KedaBasic implements ITileLayer { //图层切换
|
|
|
|
|
constructor() { |
|
|
|
|
super(); |
|
|
|
|
} |
|
|
|
|
Satellite() { |
|
|
|
|
return this |
|
|
|
|
Satellite() { //卫星图层
|
|
|
|
|
return "卫星图层" |
|
|
|
|
} |
|
|
|
|
RoadNet() { //路网图层
|
|
|
|
|
return "路网图层" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class KedaMouseTool extends KedaBasic implements IMouseTool { //地图工具
|
|
|
|
|
constructor(map: IMap) { |
|
|
|
|
super(); |
|
|
|
|
this.self = map.self |
|
|
|
|
} |
|
|
|
|
layerIds = []; |
|
|
|
|
layerIdAreas = []; |
|
|
|
|
rule(options: any) { |
|
|
|
|
let that = this |
|
|
|
|
this.self.measureDistance({ |
|
|
|
|
units: 'kilometers', |
|
|
|
|
callback: (result) => { |
|
|
|
|
var startText, sClass = that.self.mapType === 'AG' ? 'ag-popup-tools' : 'mm-popup-tools'; |
|
|
|
|
var result = result.data; |
|
|
|
|
if (!result.isEnd) { |
|
|
|
|
if (result.isStart) { |
|
|
|
|
that.self.addTexts({ |
|
|
|
|
points: [{ |
|
|
|
|
point: result.point, |
|
|
|
|
htmlText: '起点', |
|
|
|
|
class: sClass |
|
|
|
|
}], |
|
|
|
|
anchor: 'left', |
|
|
|
|
ended: function (res) { |
|
|
|
|
console.log(res); |
|
|
|
|
that.layerIds.push(res.data); |
|
|
|
|
startText = res.data; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
that.self.addTexts({ |
|
|
|
|
points: [{ |
|
|
|
|
point: result.point, |
|
|
|
|
htmlText: result.distance.toFixed(4) + 'km', |
|
|
|
|
class: sClass |
|
|
|
|
}], |
|
|
|
|
anchor: 'left', |
|
|
|
|
ended: function (res) { |
|
|
|
|
console.log(res); |
|
|
|
|
that.layerIds.push(res.data); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (result.index >= 1) { |
|
|
|
|
if (result.isFailure) { |
|
|
|
|
that.layerIds.forEach((layerId) => { |
|
|
|
|
that.self.removeTextsByType({ |
|
|
|
|
textType: layerId |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
that.layerIds.push(result.layerId); |
|
|
|
|
if (that.self.mapType === 'BM') { |
|
|
|
|
that.self.addTexts({ |
|
|
|
|
points: [{ |
|
|
|
|
point: result.point, |
|
|
|
|
htmlText: '总距离:' + result.distance.toFixed(4) + |
|
|
|
|
'km', |
|
|
|
|
class: sClass |
|
|
|
|
}], |
|
|
|
|
anchor: 'left', |
|
|
|
|
ended: function (res) { |
|
|
|
|
console.log(res); |
|
|
|
|
that.layerIds.push(res.data); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
that.layerIds.forEach((layerId) => { |
|
|
|
|
that.self.removeTextsByType({ |
|
|
|
|
textType: layerId |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
measureArea(options: any) { |
|
|
|
|
let that = this |
|
|
|
|
this.self.measureArea({ |
|
|
|
|
units: 'meters', |
|
|
|
|
callback: (result) => { |
|
|
|
|
var sClass = that.self.mapType === 'AG' ? 'ag-popup-tools' : 'mm-popup-tools'; |
|
|
|
|
var result = result.data; |
|
|
|
|
if (!result.isEnd) { |
|
|
|
|
if (result.index >= 2) { |
|
|
|
|
that.self.addTexts({ |
|
|
|
|
points: [{ |
|
|
|
|
point: result.point, |
|
|
|
|
htmlText: result.area + '平方米', |
|
|
|
|
class: sClass |
|
|
|
|
}], |
|
|
|
|
anchor: 'left', |
|
|
|
|
ended: function (res) { |
|
|
|
|
console.log(res); |
|
|
|
|
that.layerIdAreas.push(res.data); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (result.index >= 2) { |
|
|
|
|
if (result.isFailure) { |
|
|
|
|
that.layerIdAreas.forEach((layerId) => { |
|
|
|
|
that.self.removeTextsByType({ |
|
|
|
|
textType: layerId |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
that.layerIdAreas.push(result.layerId); |
|
|
|
|
if (that.self.mapType === 'BM') { |
|
|
|
|
that.self.addTexts({ |
|
|
|
|
points: [{ |
|
|
|
|
point: result.point, |
|
|
|
|
htmlText: '总面积:' + result.area + '平方米', |
|
|
|
|
class: sClass |
|
|
|
|
}], |
|
|
|
|
anchor: 'left', |
|
|
|
|
ended: function (res) { |
|
|
|
|
console.log(res); |
|
|
|
|
that.layerIdAreas.push(res.data); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
close(isTrue: boolean) { |
|
|
|
|
if (isTrue) { |
|
|
|
|
this.self.clear(); |
|
|
|
|
for (var i in this.layerIds) { |
|
|
|
|
this.self.removeTextsByType({ |
|
|
|
|
textType: this.layerIds[i] |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
for (var i in this.layerIdAreas) { |
|
|
|
|
this.self.removeTextsByType({ |
|
|
|
|
textType: this.layerIdAreas[i] |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
this.layerIdAreas = []; |
|
|
|
|
this.layerIds = []; |
|
|
|
|
} |
|
|
|
|
RoadNet() { |
|
|
|
|
return this |
|
|
|
|
} |
|
|
|
|
} |