Browse Source

科达地图开发测试

上海一张图
陈鹏飞 4 years ago
parent
commit
60c72961f2
  1. 4
      src/modules/map/declare/factory.ts
  2. 34
      src/modules/map/declare/gaode-map.ts
  3. 307
      src/modules/map/declare/keda-map.ts
  4. 18
      src/modules/map/declare/map.d.ts

4
src/modules/map/declare/factory.ts

@ -2,7 +2,7 @@ const mapSupplier: number = 2; // 1:高德, 2:科达
import { IMap, IMapOptions, IMarker, IPixel, IMarkOptions, ILngLat, ILayer, ICircle, IMarkerCluster, IRenderClusterMarker, IInfoWindow, IMouseTool, IIcon, ISize, IIconOptions, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch } from './map' import { IMap, IMapOptions, IMarker, IPixel, IMarkOptions, ILngLat, ILayer, ICircle, IMarkerCluster, IRenderClusterMarker, IInfoWindow, IMouseTool, IIcon, ISize, IIconOptions, ITileLayer, IDriving, IDrivingOptions, IAutocomplete, IPlaceSearch } from './map'
import { GaodeCircle, GaodeIcon, GaodeInfoWindow, GaodeLayer, GaoDeLngLat, GaoDeMap, GaoDeMarker, GaoDeMarkerCluster, GaodeMouseTool, GaoDePixel, GaoDeRenderClusterMarker, GaodeTileLayer, GaodeSize, GaodeDriving, GaodeAutocomplete, GaodePlaceSearch } from './gaode-map' import { GaodeCircle, GaodeIcon, GaodeInfoWindow, GaodeLayer, GaoDeLngLat, GaoDeMap, GaoDeMarker, GaoDeMarkerCluster, GaodeMouseTool, GaoDePixel, GaoDeRenderClusterMarker, GaodeTileLayer, GaodeSize, GaodeDriving, GaodeAutocomplete, GaodePlaceSearch } from './gaode-map'
import { KeDaLngLat, KeDaMap, KeDaMarker, KeDaPixel, KedaTileLayer } from './keda-map'; import { KedaInfoWindow, KeDaLngLat, KeDaMap, KeDaMarker, KedaMouseTool, KeDaPixel, KedaTileLayer } from './keda-map';
import MapTools from './map-tools'; import MapTools from './map-tools';
export class MapFactory { export class MapFactory {
@ -98,6 +98,7 @@ export class MapFactory {
public static MouseToolInstance(map: IMap): IMouseTool { public static MouseToolInstance(map: IMap): IMouseTool {
switch (mapSupplier) { switch (mapSupplier) {
case 1: return new GaodeMouseTool(map); case 1: return new GaodeMouseTool(map);
case 2: return new KedaMouseTool(map);
default: return null; default: return null;
} }
} }
@ -105,6 +106,7 @@ export class MapFactory {
public static InfoWindowInstance(options: any): IInfoWindow { public static InfoWindowInstance(options: any): IInfoWindow {
switch (mapSupplier) { switch (mapSupplier) {
case 1: return new GaodeInfoWindow(options); case 1: return new GaodeInfoWindow(options);
case 2: return new KedaInfoWindow(options);
default: return null; default: return null;
} }
} }

34
src/modules/map/declare/gaode-map.ts

@ -65,10 +65,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() { getCenter():ILngLat {
let d = this.self.getCenter(); let d = this.self.getCenter();
let res = new GaoDeLngLat(d.lng,d.lat); return new GaoDeLngLat(0,0,d);
return res;
} }
getZoom() { getZoom() {
return this.self.getZoom(); return this.self.getZoom();
@ -240,8 +239,16 @@ export class GaoDeMap extends GaodeBasic implements IMap {
export class GaoDePixel extends GaodeBasic implements IPixel { export class GaoDePixel extends GaodeBasic implements IPixel {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super(); super();
this.x = x;
this.y = y;
this.self = new AMap.Pixel(x, y); this.self = new AMap.Pixel(x, y);
} }
getArray(): number[] {
return [this.x,this.y];
}
x: number;
y: number;
} }
export class GaoDeMarker extends GaodeBasic implements IMarker { export class GaoDeMarker extends GaodeBasic implements IMarker {
@ -254,7 +261,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: number[]) { setPosition(x: ILngLat|number[]) {
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[]
@ -290,9 +298,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) { constructor(x: number, y: number,me?:any) {
super(); super();
if(me==undefined)
this.self = new AMap.LngLat(x, y); this.self = new AMap.LngLat(x, y);
else
this.self = me;
}
typeName="LngLat";
get KL():number{
return this.lng;
}
get kT():number{
return this.lat;
}
getArray(): number[] {
return [this.lng,this.lat];
} }
get lng(): number { get lng(): number {
return this.self.lng; return this.self.lng;
@ -300,7 +322,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) { offset(x: number, y: number):ILngLat {
return this.self.offset(x, y) return this.self.offset(x, y)
} }
} }

307
src/modules/map/declare/keda-map.ts

@ -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; declare var KMap: any;
class KedaBasic implements ISelf { class KedaBasic implements ISelf {
@ -34,6 +35,16 @@ export class KeDaMap extends KedaBasic implements IMap {
opt.onLoadMap = mapLayer opt.onLoadMap = mapLayer
this.self = new KMap(opt); 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) { //自定义 行政区划 样式 setAdministrativeAreaStyle(conponent: any, getData?: Function, setData?: Function) { //自定义 行政区划 样式
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -43,9 +54,7 @@ export class KeDaMap extends KedaBasic implements IMap {
setFitView(options: any) { setFitView(options: any) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
containerToLngLat(e: any) {
throw new Error('Method not implemented.');
}
clearMap() { clearMap() {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -56,7 +65,10 @@ export class KeDaMap extends KedaBasic implements IMap {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
setZoomAndCenter(zoom: number, pos: number[]) { setZoomAndCenter(zoom: number, pos: number[]) {
throw new Error('Method not implemented.'); this.self.flyTo({
zoom: zoom,
point: pos,
});
} }
plugin(eventName: string[], callback: Function) { plugin(eventName: string[], callback: Function) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
@ -65,10 +77,23 @@ export class KeDaMap extends KedaBasic implements IMap {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
add(obj: any) { 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) { 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) { setCity(city: string) {
let that = this let that = this
@ -95,8 +120,14 @@ export class KeDaMap extends KedaBasic implements IMap {
}) })
return num return num
} }
setCenter(pos: number[]) { setCenter(pos: number[] | ILngLat) {
this.self.flyTo({point:pos}) let position = []
if (pos instanceof Array) {
position = pos
} else {
position = [pos.lng, pos.lat];
}
this.self.flyTo({ point: position })
} }
getCenter() { getCenter() {
let center let center
@ -118,64 +149,290 @@ export class KeDaMap extends KedaBasic implements IMap {
handler: callback handler: callback
}); });
} }
} }
export class KeDaPixel extends KedaBasic implements IPixel { export class KeDaPixel extends KedaBasic implements IPixel {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super(); super();
this.x = x;
this.y = y;
this.self = [x, y]; this.self = [x, y];
} }
getArray(): number[] {
return this. self;
}
x: number;
y: number;
} }
export class KeDaMarker extends KedaBasic implements IMarker { export class KeDaMarker extends KedaBasic implements IMarker {
constructor(options: any) { public map:KeDaMap;
public typeName:string = "KeDaMarker";
constructor(options: IMarkOptions) {
super(); super();
let pos = []
if (options.position instanceof Array) {
pos = options.position
} else {
pos = options.position.getArray()
}
let d = { let d = {
offset: options.offset, url: '/assets/images/dingwei.png',
element: options.content point: pos,
offset: options.offset? options.offset.self : null,
ended: (res) => {this.id = res.data;}
}; };
this.self = d; 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) { setContent(html: string) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
setPosition(x: number[]) { setPosition(x: number[]) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
_position: number[];
setMap() { setMap() {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
get id(): string { get id(): string {
throw new Error('Method not implemented.'); return this.self.id
} }
set id(str: string) { set id(str: string) {
throw new Error('Method not implemented.'); this.self.id = str
} }
public bindObj=[]; // event
on(eventName: string, callback: Function): void { 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 { export class KeDaLngLat extends KedaBasic implements ILngLat {
constructor(x: number, y: number) { constructor(lng: number, lat: number) {
super(); 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; lng: number;
lat: number; lat: number;
offset(x: number, y: number) { get KL():number{
throw new Error('Method not implemented.'); 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() { constructor() {
super(); super();
} }
Satellite() { Satellite() { //卫星图层
return this 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
} }
} }

18
src/modules/map/declare/map.d.ts vendored

@ -8,10 +8,10 @@ export interface IMap extends ISelf {
//异步加载插件,插件完成的callback //异步加载插件,插件完成的callback
//pluginName:要加载的插件名 //pluginName:要加载的插件名
plugin(pluginName: string[], callback: Function); plugin(pluginName: string[], callback: Function);
add(obj: IMarker|any); add(obj: IMarker|ITileLayer|any);
remove(obj: any); remove(obj: IMarker|ITileLayer|any);
clearMap(); clearMap();
containerToLngLat(e:any); containerToLngLat(e:IPixel): ILngLat; //地图容器像素坐标转经纬度
setFitView(options:any); setFitView(options:any);
setBounds(zoom?:any, x?:any, y?:any, is?:boolean); setBounds(zoom?:any, x?:any, y?:any, is?:boolean);
setCity(city: string); setCity(city: string);
@ -35,7 +35,7 @@ export interface IMarker extends ISelf {
id: string; id: string;
_position:number[]; _position:number[];
on(eventName: string, callback: Function); on(eventName: string, callback: Function);
setPosition(x:number[]) setPosition(x:ILngLat|number[])
setContent(html:string) setContent(html:string)
setMap(); setMap();
} }
@ -63,13 +63,19 @@ export class IMarkOptions {
} }
export interface IPixel extends ISelf { export interface IPixel extends ISelf {
x:number
y:number
getArray():number[]
} }
export interface ILngLat extends ISelf { export interface ILngLat extends ISelf {
typeName:string
lng: number lng: number
lat: number lat: number
offset(x: number, y: number) KL:number
kT:number
offset(x: number, y: number):ILngLat
getArray():number[]
} }
export interface ILayer extends ISelf { export interface ILayer extends ISelf {

Loading…
Cancel
Save