10 changed files with 139 additions and 17 deletions
@ -0,0 +1,5 @@
|
||||
<div class="box"> |
||||
<div class="mapbox" id="mapbox"> |
||||
|
||||
</div> |
||||
</div> |
@ -0,0 +1,12 @@
|
||||
.box { |
||||
width: 100%; |
||||
height: 100%; |
||||
display: flex; |
||||
align-items: center; |
||||
justify-content: center; |
||||
} |
||||
.mapbox{ |
||||
width: 600px; |
||||
height: 500px; |
||||
border: 1px solid red; |
||||
} |
@ -0,0 +1,94 @@
|
||||
import { Component, OnInit } from '@angular/core'; |
||||
declare var AMap: any; |
||||
declare var AMapUI: any; |
||||
|
||||
@Component({ |
||||
selector: 'app-home', |
||||
templateUrl: './home.component.html', |
||||
styleUrls: ['./home.component.scss'] |
||||
}) |
||||
export class HomeComponent implements OnInit { |
||||
|
||||
constructor() { } |
||||
|
||||
ngOnInit(): void { |
||||
window.setTimeout(()=>{ |
||||
this.mapInit() //初始化地图
|
||||
},0) |
||||
} |
||||
|
||||
map |
||||
mapInit() { |
||||
//创建地图
|
||||
this.map = new AMap.Map('mapbox', { |
||||
cursor: 'default', |
||||
zooms: [8, 16], |
||||
mapStyle: "amap://styles/light", |
||||
// bubble: true
|
||||
}); |
||||
|
||||
let colors = [ |
||||
"#EE30B3", "#B37CF0", "#BD2CE6", "#7768EE", "#359EEF", "#7B95CA", "#CAFBF8", "#43D0E1", |
||||
"#72C6EF" |
||||
]; |
||||
|
||||
AMapUI.loadUI(['geo/DistrictExplorer'], (DistrictExplorer) => { |
||||
|
||||
//创建一个实例
|
||||
let districtExplorer = new DistrictExplorer({ |
||||
map: this.map, |
||||
eventSupport: true, //打开事件支持
|
||||
}); |
||||
|
||||
// let adcode = this.adcode; //行政编码
|
||||
let adcode = 370100 |
||||
|
||||
|
||||
districtExplorer.loadAreaNode(adcode, (error, areaNode) => { |
||||
|
||||
//更新地图视野
|
||||
this.map.setBounds(areaNode.getBounds(), null, null, true); |
||||
|
||||
//设置定位节点,支持鼠标位置识别
|
||||
//注意节点的顺序,前面的高优先级
|
||||
districtExplorer.setAreaNodesForLocating(areaNode); |
||||
|
||||
//清除已有的绘制内容
|
||||
districtExplorer.clearFeaturePolygons(); |
||||
|
||||
//绘制子区域
|
||||
districtExplorer.renderSubFeatures(areaNode, (feature, i) => { |
||||
console.log(111,feature) |
||||
let fillColor = colors[i % colors.length]; |
||||
let strokeColor = colors[colors.length - 1 - i % colors.length]; |
||||
return { |
||||
cursor: 'default', |
||||
bubble: true, |
||||
strokeColor: strokeColor, //线颜色
|
||||
strokeOpacity: 1, //线透明度
|
||||
strokeWeight: 1, //线宽
|
||||
fillColor: fillColor, //填充色
|
||||
fillOpacity: 0.5, //填充透明度
|
||||
}; |
||||
}); |
||||
|
||||
//绘制父区域
|
||||
districtExplorer.renderParentFeature(areaNode, { |
||||
cursor: 'default', |
||||
bubble: true, |
||||
strokeColor: 'black', //线颜色
|
||||
strokeOpacity: 1, //线透明度
|
||||
strokeWeight: 1, //线宽
|
||||
fillColor: null, //填充色
|
||||
fillOpacity: 0.5, //填充透明度
|
||||
}); |
||||
|
||||
// 更新地图视野以适合区划面
|
||||
this.map.setFitView(districtExplorer.getAllFeaturePolygons()); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
|
||||
} |
||||
} |
@ -1,4 +1,4 @@
|
||||
|
||||
<div class="box"> |
||||
<nz-empty></nz-empty> |
||||
</div> |
||||
</div> |
||||
<!-- <router-outlet></router-outlet> --> |
Loading…
Reference in new issue