From f536cea0994a41121857a12c37280e3a73bec6c8 Mon Sep 17 00:00:00 2001 From: anxinCPF <1105965053@qq.com> Date: Wed, 23 Jun 2021 09:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=91=E8=BE=BE=E5=9C=B0=E5=9B=BE=E8=81=94?= =?UTF-8?q?=E8=B0=83=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/map/declare/factory.ts | 2 +- src/modules/map/declare/gaode-map.ts | 4 +- src/modules/map/declare/keda-map.ts | 70 ++++++++++++++++++++++------ src/modules/map/declare/map.d.ts | 16 +++---- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/src/modules/map/declare/factory.ts b/src/modules/map/declare/factory.ts index 37349ba..a5e1311 100644 --- a/src/modules/map/declare/factory.ts +++ b/src/modules/map/declare/factory.ts @@ -1,4 +1,4 @@ -const mapSupplier: number = 1; // 1:高德, 2:科达 +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 { GaodeCircle, GaodeIcon, GaodeInfoWindow, GaodeLayer, GaoDeLngLat, GaoDeMap, GaoDeMarker, GaoDeMarkerCluster, GaodeMouseTool, GaoDePixel, GaoDeRenderClusterMarker, GaodeTileLayer, GaodeSize, GaodeDriving, GaodeAutocomplete, GaodePlaceSearch } from './gaode-map' diff --git a/src/modules/map/declare/gaode-map.ts b/src/modules/map/declare/gaode-map.ts index 4ea9e7f..0dfea5f 100644 --- a/src/modules/map/declare/gaode-map.ts +++ b/src/modules/map/declare/gaode-map.ts @@ -66,7 +66,9 @@ export class GaoDeMap extends GaodeBasic implements IMap { return this.self.setCenter(pos) } getCenter() { - return this.self.getCenter(); + let d = this.self.getCenter(); + let res = new GaoDeLngLat(d.lng,d.lat); + return res; } getZoom() { return this.self.getZoom(); diff --git a/src/modules/map/declare/keda-map.ts b/src/modules/map/declare/keda-map.ts index ea326a0..a1d57ae 100644 --- a/src/modules/map/declare/keda-map.ts +++ b/src/modules/map/declare/keda-map.ts @@ -7,11 +7,31 @@ class KedaBasic implements ISelf { } export class KeDaMap extends KedaBasic implements IMap { - constructor(container: string, options: IMapOptions) { + constructor(container: string, options: IMapOptions) { //地图初始化 super(); + let that = this let opt = Object.assign({}, { containerId: container }, options) as any; - opt.configUrl = "../../../assets/kmap/Kmap.config.json"; - opt.targetCoordinateType = "WGS84", + opt.configUrl = "/assets/kmap/Kmap.config.json"; + opt.targetCoordinateType = "WGS84"; + let mapLayer = function () { + if (opt.viewMode && opt.viewMode=="3D") { + let data = { + type: 'FeatureCollection', + features: [ + { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [121.495126354, 31.241993148] + }, + properties: {height: 30} + } + ] + }; + that.self.add3DLayer({data: data}); + } + } + opt.onLoadMap = mapLayer this.self = new KMap(opt); } setAdministrativeAreaStyle(conponent: any, getData?: Function, setData?: Function) { //自定义 行政区划 样式 @@ -51,19 +71,41 @@ export class KeDaMap extends KedaBasic implements IMap { throw new Error('Method not implemented.'); } setCity(city: string) { - console.log(1) - } - setZoom(zoom) { - throw new Error('Method not implemented.'); - } - setCenter([x, y]) { - throw new Error('Method not implemented.'); - } - getZoom() { - throw new Error('Method not implemented.'); + let that = this + if (city.includes("上海")) { + window.setTimeout(function(){ + that.self.flyTo({ + zoom:9, + point:[121.495126354, 31.241993148] + }); + },10000) + } + } + setZoom(zoom:number) { + this.self.zoomTo({ + zoom:zoom + }); + } + getZoom():number { + let num + this.self.getZoom({ + callback:(e)=>{ + num = e.data; + } + }) + return num + } + setCenter(pos: number[]) { + this.self.flyTo({point:pos}) } getCenter() { - throw new Error('Method not implemented.'); + let center + this.self.getCenter({ + callback: function (data) { + console.log(data); + } + }); + return center } on(eventName: string, callback: Function): void { let eventMapProfile = { diff --git a/src/modules/map/declare/map.d.ts b/src/modules/map/declare/map.d.ts index 7e33256..971e225 100644 --- a/src/modules/map/declare/map.d.ts +++ b/src/modules/map/declare/map.d.ts @@ -8,19 +8,19 @@ export interface IMap extends ISelf { //异步加载插件,插件完成的callback //pluginName:要加载的插件名 plugin(pluginName: string[], callback: Function); - add(obj: IMarker|any): any; - remove(obj: any): any; + add(obj: IMarker|any); + remove(obj: any); clearMap(); containerToLngLat(e:any); setFitView(options:any); setBounds(zoom?:any, x?:any, y?:any, is?:boolean); - setCity(city: string): any; + setCity(city: string); getCity(callback: Function): any; - setZoom(zoom: number): any; - setZoomAndCenter(zoom: number, pos: number[]): any; - getZoom(): any; - setCenter(any): any; - getCenter(): any; + setZoom(zoom: number); + setZoomAndCenter(zoom: number, pos: number[]); + getZoom(): number; + setCenter(pos: number[]|ILngLat); + getCenter(): ILngLat; getBounds(): any; distance(a:number[],b:number[]): any; setAdministrativeAreaStyle(conponent:any,getData?:Function,setData?:Function): any; //自定义 行政区划 样式