Browse Source

高德地图封装基本完成

上海一张图
陈鹏飞 4 years ago
parent
commit
f9630e5b1a
  1. 7
      src/app/data-collection/fire-force/fire-force.component.ts
  2. 8
      src/app/data-collection/linkage-forces/linkage-forces.component.ts
  3. 7
      src/app/data-collection/water-collection/water-collection.component.ts
  4. 31
      src/app/gis-management/gis-labeling/gis-labeling.component.ts
  5. 7
      src/app/key-unit/basicinfo-look/basicinfo.component.ts
  6. 11
      src/app/key-unit/basicinfo/basicinfo.component.ts
  7. 6
      src/app/key-unit/router-gis/router-gis.component.ts
  8. 1
      src/app/key-unit/six-familiarity/six-familiarity.component.ts
  9. 3
      src/app/key-unit/water-road/water-road.component.ts
  10. 2
      src/app/plan-audit/fireforce-audit/fireforce-audit.component.ts
  11. 2
      src/app/plan-audit/linkageforces-audit/linkageforces-audit.component.ts
  12. 2
      src/app/plan-audit/water-audit/water-audit.component.ts
  13. 4
      src/modules/map/declare/factory.ts
  14. 27
      src/modules/map/declare/gaode-map.ts
  15. 4
      src/modules/map/declare/map.d.ts

7
src/app/data-collection/fire-force/fire-force.component.ts

@ -12,7 +12,6 @@ import { Console } from 'console';
import { TreeService } from 'src/app/http-interceptors/tree.service';
import Viewer from 'viewerjs'
declare var CryptoJS
declare var AMap: any;
@Component({
selector: 'app-fire-force',
@ -93,7 +92,7 @@ export class FireForceComponent implements OnInit {
data : item
}) : null
})
this.map.plugin(["AMap.MarkerClusterer"],() => {
var gridSize = 60
var count = markerArrcluster.length;
@ -193,7 +192,7 @@ export class FireForceComponent implements OnInit {
})
}
})
});
}
ngOnInit(): void {
@ -823,7 +822,6 @@ export class FireForceComponent implements OnInit {
var autoOptions = {
input: "tipinput"
};
this.map.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], ()=>{
let auto = MapFactory.AutocompleteInstance(autoOptions);
this.placeSearch = MapFactory.PlaceSearchInstance(); //构造地点查询类
auto.on("select", (e)=>{
@ -832,7 +830,6 @@ export class FireForceComponent implements OnInit {
this.map.setCenter([e.poi.location.lng,e.poi.location.lat]); //设置地图中心点
});//注册监听,当选中某条记录时会触发
});
}
//点击位置
isGisTopBox:boolean = false //

8
src/app/data-collection/linkage-forces/linkage-forces.component.ts

@ -13,7 +13,7 @@ import Swiper from 'swiper';
import { MapFactory } from '@src/modules/map/declare/factory';
import { IMap, IMarker } from '@src/modules/map/declare/map';
declare var CryptoJS
declare var AMap: any;
@Component({
selector: 'app-linkage-forces',
templateUrl: './linkage-forces.component.html',
@ -126,7 +126,7 @@ export class LinkageForcesComponent implements OnInit {
})
}
})
this.map.plugin(["AMap.MarkerClusterer"],() => {
var gridSize = 60
var count = markerArrcluster.length;
@ -177,7 +177,7 @@ export class LinkageForcesComponent implements OnInit {
this.AttachmentArr = JSON.parse(item.relevantInfomationData)
}
})
});
}
ngOnInit(): void {
@ -543,7 +543,6 @@ export class LinkageForcesComponent implements OnInit {
var autoOptions = {
input: "tipinput"
};
this.map.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], ()=>{
let auto = MapFactory.AutocompleteInstance(autoOptions);
this.placeSearch = MapFactory.PlaceSearchInstance(); //构造地点查询类
auto.on("select", (e)=>{
@ -552,7 +551,6 @@ export class LinkageForcesComponent implements OnInit {
this.map.setCenter([e.poi.location.lng,e.poi.location.lat]); //设置地图中心点
});//注册监听,当选中某条记录时会触发
});
}
//点击位置
isGisTopBox:boolean = false //

7
src/app/data-collection/water-collection/water-collection.component.ts

@ -6,7 +6,6 @@ import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dial
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { MapFactory } from '@src/modules/map/declare/factory';
import { IMap, IMarker } from '@src/modules/map/declare/map';
declare var AMap: any;
@Component({
selector: 'app-water-collection',
@ -82,7 +81,7 @@ export class WaterCollectionComponent implements OnInit {
})
}
})
this.map.plugin(["AMap.MarkerClusterer"],() => {
var gridSize = 60
var count = markerArrcluster.length;
@ -137,7 +136,7 @@ export class WaterCollectionComponent implements OnInit {
this.positionLngLat = item.location
}
})
});
}
ngOnInit(): void {
@ -548,7 +547,6 @@ export class WaterCollectionComponent implements OnInit {
var autoOptions = {
input: "tipinput"
};
this.map.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], ()=>{
let auto = MapFactory.AutocompleteInstance(autoOptions);
this.placeSearch = MapFactory.PlaceSearchInstance(); //构造地点查询类
auto.on("select", (e)=>{
@ -557,7 +555,6 @@ export class WaterCollectionComponent implements OnInit {
this.map.setCenter([e.poi.location.lng,e.poi.location.lat]); //设置地图中心点
});//注册监听,当选中某条记录时会触发
});
}
//点击位置
isGisTopBox:boolean = false //

31
src/app/gis-management/gis-labeling/gis-labeling.component.ts

@ -365,7 +365,7 @@ export class GisLabelingComponent implements OnInit {
data: item
})
})
this.map.plugin(["AMap.MarkerClusterer"], () => {
var gridSize = 60
var count = unitMarkerArrcluster.length;
@ -459,7 +459,7 @@ export class GisLabelingComponent implements OnInit {
this.renderer2.listen(this.elementRef.nativeElement.querySelector('#share'), 'click', (event) => { this.share(item) })//分享点击事件
}
})
});
}
//取消显示单位
@ -541,7 +541,7 @@ export class GisLabelingComponent implements OnInit {
data: item
}) : null
})
this.map.plugin(["AMap.MarkerClusterer"], () => {
var gridSize = 60
var count = fireForceMarkerArrcluster.length;
@ -582,7 +582,7 @@ export class GisLabelingComponent implements OnInit {
gridSize: gridSize, // 设置网格像素大小
render: render //自定义聚合点样式, 自定义非聚合点样式
});
});
}
//取消消防力量
resetFireForce() {
@ -689,7 +689,7 @@ export class GisLabelingComponent implements OnInit {
}
// 用于点集合的数组
})
this.map.plugin(["AMap.MarkerClusterer"], () => {
var gridSize = 60
var count = linkageForcesMarkerArrcluster.length;
@ -731,7 +731,7 @@ export class GisLabelingComponent implements OnInit {
gridSize: gridSize, // 设置网格像素大小
render: render //自定义聚合点样式, 自定义非聚合点样式
});
});
}
//取消联动力量
resetLinkageForces() {
@ -835,7 +835,7 @@ export class GisLabelingComponent implements OnInit {
data: item
})
})
this.map.plugin(["AMap.MarkerClusterer"], () => {
var gridSize = 60
var count = waterMarkerArrcluster.length;
@ -916,7 +916,6 @@ export class GisLabelingComponent implements OnInit {
}
})
});
}
//取消显示水源
@ -1053,9 +1052,7 @@ export class GisLabelingComponent implements OnInit {
})
that.map = MapFactory.MapInstance('map', { layers: [layer] });
that.map.setCity('上海市');
that.map.plugin(["AMap.RangingTool", "AMap.MouseTool"], function () {
that.mouseTool = MapFactory.MouseToolInstance(that.map);
});
}
@ -1087,17 +1084,7 @@ export class GisLabelingComponent implements OnInit {
//清空距离测量
clearDistance() {
this.distanceList.forEach(item => {
if (item.className == 'AMap.Marker') {
let parent = item.dom.parentNode
let children = item.dom.nextElementSibling
parent && children ? parent.removeChild(item.dom.nextElementSibling) : null
this.map.remove(item)
} else {
this.map.remove(item)
}
})
this.distanceList = [] //清空数组
}
//清空面积测量
@ -1348,7 +1335,6 @@ export class GisLabelingComponent implements OnInit {
this.timeout = window.setTimeout(() => {
that.map.getCity(function (info) { //获取当前 city
that.map.plugin(['AMap.AutoComplete'], () => {
var autoOptions = { city: info.city }
let keywords
e == 0 ? keywords = that.routeStart : keywords = that.routeEnd
@ -1375,7 +1361,6 @@ export class GisLabelingComponent implements OnInit {
} //if
})
})
}); //获取当前 city
}, 500)

7
src/app/key-unit/basicinfo-look/basicinfo.component.ts

@ -5,15 +5,9 @@ import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { AbstractControl, FormControl, NG_VALIDATORS, Validator } from '@angular/forms';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import format from 'date-fns/format';
import { TreeService } from '../../http-interceptors/tree.service'
import { FileUploader, FileItem } from 'ng2-file-upload'
import { DomSanitizer } from '@angular/platform-browser'
import { Injectable } from "@angular/core"
import { filter } from 'rxjs/operators';
import { async } from '@angular/core/testing';
import { MatTableDataSource } from '@angular/material/table';
import { isNgTemplate } from '@angular/compiler';
import * as _ from 'lodash';
import Swiper from 'swiper';
import { ActivatedRoute } from '@angular/router';
@ -21,7 +15,6 @@ import { StatisticsOfFireFightingFacilities } from '../basicinfo/basicinfo.compo
import Viewer from 'viewerjs';
import { IMap, IMarker } from '@src/modules/map/declare/map';
import { MapFactory } from '@src/modules/map/declare/factory';
declare var AMap: any;
@Component({
selector: 'app-basicinfo-look',

11
src/app/key-unit/basicinfo/basicinfo.component.ts

@ -5,25 +5,19 @@ import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { AbstractControl, FormControl, NG_VALIDATORS, Validator } from '@angular/forms';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import format from 'date-fns/format';
import { TreeService } from '../../http-interceptors/tree.service'
import { FileUploader, FileItem } from 'ng2-file-upload'
import { AddHouseInfo } from './addhouseinfo.component'
import { DomSanitizer } from '@angular/platform-browser'
import { Injectable } from "@angular/core"
import { filter } from 'rxjs/operators';
import { async } from '@angular/core/testing';
import { MatTableDataSource } from '@angular/material/table';
import { isNgTemplate } from '@angular/compiler';
import * as _ from 'lodash';
import Swiper from 'swiper';
import { LookMaster } from './lookmaster.component'
import { ActivatedRoute } from '@angular/router';
import { TabbarAndScoreService } from 'src/app/http-interceptors/tabbar-and-score.service';
declare var AMap: any;
import Viewer from 'viewerjs';
import { IMap, IMarker, IPlaceSearch } from '@src/modules/map/declare/map';
import { MapFactory } from '@src/modules/map/declare/factory';
@Component({
selector: 'app-basicinfo',
templateUrl: './basicinfo.component.html',
@ -181,7 +175,6 @@ export class BasicinfoComponent implements OnInit {
var autoOptions = {
input: "tipinput"
};
this.map.plugin(['AMap.PlaceSearch', 'AMap.AutoComplete'], () => {
var auto = MapFactory.AutocompleteInstance(autoOptions);
this.placeSearch = MapFactory.PlaceSearchInstance(); //构造地点查询类
auto.on("select", (e) => {
@ -190,8 +183,6 @@ export class BasicinfoComponent implements OnInit {
this.map.setCenter([e.poi.location.lng, e.poi.location.lat]); //设置地图中心点
});//注册监听,当选中某条记录时会触发
});
if (this.isMapLabel) {//如果已经标注单位坐标
// console.log('已标注单位位置')
this.map.setCenter([this.unitinfo.location.x, this.unitinfo.location.y]);

6
src/app/key-unit/router-gis/router-gis.component.ts

@ -101,9 +101,7 @@ export class RouterGISComponent implements OnInit {
layers:[layer], //当只想显示标准图层时layers属性可缺省,
});
that.map.setCity('上海市');
that.map.plugin('AMap.Driving', function() {
that.startCoordinate && that.endCoordinate? that.queryGISRoute() : null
})
}
map:IMap; //地图实例
@ -125,7 +123,6 @@ export class RouterGISComponent implements OnInit {
this.timeout = window.setTimeout(()=>{
that.map.getCity( function(info){ //获取当前 city
that.map.plugin(['AMap.AutoComplete'], () =>{
var autoOptions = {city: info.city}
let keywords
e == 0 ? keywords = that.routeStart : keywords = that.routeEnd
@ -149,10 +146,9 @@ export class RouterGISComponent implements OnInit {
that.endCoordinate = MapFactory.LngLatInstance(result.tips[0].location.lng, result.tips[0].location.lat)
}
});
} //if
})
})
}); //获取当前 city
},500)

1
src/app/key-unit/six-familiarity/six-familiarity.component.ts

@ -1,6 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { MapFactory } from '@src/modules/map/declare/factory';
declare var AMap: any;
@Component({
selector: 'app-six-familiarity',

3
src/app/key-unit/water-road/water-road.component.ts

@ -6,7 +6,6 @@ import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { ActivatedRoute } from '@angular/router';
import { MapFactory } from '@src/modules/map/declare/factory';
import { ICircle, IMap, IMarker } from '@src/modules/map/declare/map';
declare var AMap: any;
@Component({
selector: 'app-water-road',
@ -223,7 +222,6 @@ export class WaterRoadComponent implements OnInit {
}
})
this.map.plugin(["AMap.MarkerClusterer"],() => {
var gridSize = 60
var count = waterMarkerArrcluster.length;
@ -269,7 +267,6 @@ export class WaterRoadComponent implements OnInit {
}
})
});
}

2
src/app/plan-audit/fireforce-audit/fireforce-audit.component.ts

@ -7,7 +7,7 @@ import { IMap, IMarker } from '@src/modules/map/declare/map';
import Viewer from 'viewerjs'
import { ViewDetailsComponent } from '../view-details/view-details.component';
declare var CryptoJS
declare var AMap: any;
@Component({
selector: 'app-fireforce-audit',
templateUrl: './fireforce-audit.component.html',

2
src/app/plan-audit/linkageforces-audit/linkageforces-audit.component.ts

@ -7,7 +7,7 @@ import { MatDialog } from '@angular/material/dialog';
import { MapFactory } from '@src/modules/map/declare/factory';
import { IMap, IMarker } from '@src/modules/map/declare/map';
declare var CryptoJS
declare var AMap: any;
@Component({
selector: 'app-linkageforces-audit',
templateUrl: './linkageforces-audit.component.html',

2
src/app/plan-audit/water-audit/water-audit.component.ts

@ -1,7 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { MapFactory } from '@src/modules/map/declare/factory';
import { IMap, IMarker } from '@src/modules/map/declare/map';
declare var AMap: any;
@Component({
selector: 'app-water-audit',
templateUrl: './water-audit.component.html',

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

@ -6,10 +6,10 @@ import { KeDaLngLat, KeDaMap, KeDaMarker, KeDaPixel } from './keda-map';
import MapTools from './map-tools';
export class MapFactory {
public static MapInstance(container: string, options: IMapOptions | any): IMap {
public static MapInstance(container: string, options: IMapOptions | any,plugins?:string[]): IMap {
let config = MapTools.ExplicitConvert(options);
switch (mapSupplier) {
case 1: return new GaoDeMap(container, config);
case 1: return new GaoDeMap(container, config,plugins);
case 2: return new KeDaMap(container, config);
default: return null;
}

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

@ -9,9 +9,18 @@ class GaodeBasic implements ISelf {
}
export class GaoDeMap extends GaodeBasic implements IMap {
constructor(container: string, options: IMapOptions) {
/// plugins:同步加载插件
constructor(container: string, options: IMapOptions,plugins?:string[]) {
super();
this.self = new AMap.Map(container, options);
if(!!plugins && plugins.length){
for(var i in plugins){
let name = plugins[i];
if(name.indexOf('AMap.')==-1)continue;
let pObj = eval(`new ${plugins[i]}()`);
this.self.plugin(pObj);
}
}
}
setBounds(zoom?: any, x?: any, y?: any, is?: boolean) {
return this.self.setBounds(zoom, x, y, is)
@ -34,8 +43,9 @@ export class GaoDeMap extends GaodeBasic implements IMap {
setZoomAndCenter(zoom: number, pos: number[]) {
return this.self.setZoomAndCenter(zoom, pos)
}
plugin(eventName: string[], callback: Function) {
return this.self.plugin(eventName, callback)
plugin(pluginNames: string[], callback: Function) {
let names = pluginNames.filter(s=>s.indexOf("AMap.")==0);
return this.self.plugin(names, callback)
}
getBounds() {
return this.self.getBounds()
@ -264,7 +274,10 @@ export class GaoDeMarkerCluster extends GaodeBasic implements IMarkerCluster {
constructor(map: IMap, list: Object[], options: any) {
super();
let conf = MapTools.ExplicitConvert(options);
AMap.plugin('AMap.MarkerClusterer',()=>{
this.self = new AMap.MarkerCluster(map.self, list, conf)
});
}
on(eventName: string, callback: Function): void {
return this.self.on(eventName, callback);
@ -331,7 +344,9 @@ export class GaodeDriving extends GaodeBasic implements IDriving {
constructor(options: IDrivingOptions) {
super();
options.map = options.map.self
AMap.plugin('AMap.Driving',()=>{
this.self = new AMap.Driving(options)
})
}
clear() {
return this.self.clear()
@ -344,7 +359,9 @@ export class GaodeDriving extends GaodeBasic implements IDriving {
export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete {
constructor(city: Object) {
super();
AMap.plugin('AMap.AutoComplete',()=>{
this.self = new AMap.Autocomplete(city)
})
}
on(eventName: string, callback: Function) {
return this.self.on(eventName, callback)
@ -357,7 +374,9 @@ export class GaodeAutocomplete extends GaodeBasic implements IAutocomplete {
export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch {
constructor() {
super();
AMap.plugin('AMap.PlaceSearch',()=>{
this.self = new AMap.PlaceSearch()
})
}
search(text: string, callback: Function) {
return this.self.search(text, callback)
@ -367,7 +386,9 @@ export class GaodePlaceSearch extends GaodeBasic implements IPlaceSearch {
export class GaodeMouseTool extends GaodeBasic implements IMouseTool {
constructor(map: IMap) {
super();
AMap.plugin(["AMap.RangingTool", "AMap.MouseTool"],()=>{
this.self = new AMap.MouseTool(map.self);
})
}
rule(options: any) {
let conf = MapTools.ExplicitConvert(options);

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

@ -5,7 +5,9 @@ export interface ISelf {
export interface IMap extends ISelf {
on(eventName: string, callback: Function);
plugin(eventName: string[]|string, callback: Function);
//异步加载插件,插件完成的callback
//pluginName:要加载的插件名
plugin(pluginName: string[], callback: Function);
add(obj: IMarker|any): any;
remove(obj: any): any;
clearMap();

Loading…
Cancel
Save