徐振升 4 years ago
parent
commit
b1674967b8
  1. 9
      src/app/ui/basicinfo/basicinfo.component.html
  2. 25
      src/app/ui/basicinfo/basicinfo.component.scss
  3. 93
      src/app/ui/basicinfo/basicinfo.component.ts

9
src/app/ui/basicinfo/basicinfo.component.html

@ -144,6 +144,15 @@
<mat-icon style="width: 22px;height: 22px;font-size: 22px;">place</mat-icon> 位置
</div>
</div>
<div class="gistopbox hidden" [ngClass]="{'show': isGisTopBoxTwo}">
<div class="inputBox">
<span>位置: </span>
<input name="position" [(ngModel)]="searchTitle" id="tipinput" class="positionInput" type="text" autocomplete="off">
</div>
<div class="setPosition" (click)="search()">
搜索
</div>
</div>
</div>
</div>
</form>

25
src/app/ui/basicinfo/basicinfo.component.scss

@ -87,7 +87,6 @@
}
.gistopbox{
position: absolute;
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
border-radius: 4px;
left: 5%;
@ -126,9 +125,31 @@
align-items: center;
justify-content: center;
}
.inputBox{
width: 63%;
display: flex;
align-items: center;
.positionInput{
border: 0;
border-radius: 6px;
width: 90%;
height: 34px;
background: #F2F2F2;
margin-left: 8px;
box-sizing: border-box;
padding-left: 10px;
}
}
}
.hidden{
opacity: 0;
z-index: -1;
}
.show{
opacity: 1;
z-index: 1;
}
}
}
}

93
src/app/ui/basicinfo/basicinfo.component.ts

@ -98,6 +98,7 @@ export class BasicinfoComponent implements OnInit {
markerPosition:any = {x: 0, y: 0}//单位坐标
map:any //地图实例
isGisTopBox:boolean = false//点击位置按钮
isGisTopBoxTwo:boolean = false//点击位置按钮
oldPositionMarker:any //旧位置marker实例
newPositionMarker:any //新位置marker实例
@ -114,6 +115,23 @@ export class BasicinfoComponent implements OnInit {
'<div class="custom-content-marker">' +
' <img src="/assets/images/oldposition.png">' +
'</div>'
//初始化地图
searchTitle:any//搜索内容
placeSearch:any//地址搜索类
search(){
this.placeSearch.search(this.searchTitle, (status, result) => {
// 搜索成功时,result即是对应的匹配数据
if(result.info == "OK"){
this.newPositionMarker.setPosition([result.poiList.pois[0].location.lng,result.poiList.pois[0].location.lat])
this.markerPosition2 = {x: result.poiList.pois[0].location.lng, y: result.poiList.pois[0].location.lat}
this.map.setCenter([result.poiList.pois[0].location.lng,result.poiList.pois[0].location.lat]); //设置地图中心点
}else{
alert('查询不到输入地址信息')
}
})
}
//初始化地图
labelGis(){
this.map = new AMap.Map('container', {
@ -122,24 +140,43 @@ export class BasicinfoComponent implements OnInit {
this.map.on('complete', () => {
this.isGisTopBox = true
});
if(this.isMapLabel){//如果已经标注单位坐标
console.log('已标注单位位置')
this.map.setCenter([this.unitinfo.location.x,this.unitinfo.location.y]);
this.oldPositionMarker = new AMap.Marker({
position: [this.unitinfo.location.x,this.unitinfo.location.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-15, -18)
})
// 将 markers 添加到地图
this.map.add(this.oldPositionMarker);
}else{
console.log('未标注单位位置')
this.map.setCity('上海市');
}
//输入提示
var autoOptions = {
input: "tipinput"
};
AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], ()=>{
var auto = new AMap.AutoComplete(autoOptions);
this.placeSearch = new AMap.PlaceSearch(); //构造地点查询类
auto.on("select", (e)=>{
console.log(e)
console.log( this.newPositionMarker)
this.newPositionMarker.setPosition([e.poi.location.lng,e.poi.location.lat])
this.markerPosition2 = {x: e.poi.location.lng, y: e.poi.location.lat}
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]);
this.oldPositionMarker = new AMap.Marker({
position: [this.unitinfo.location.x,this.unitinfo.location.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-15, -18)
})
// 将 markers 添加到地图
this.map.add(this.oldPositionMarker);
}else{
console.log('未标注单位位置')
this.map.setCity('上海市');
}
}
markerPosition2
//点击位置按钮
setPosition(){
this.isGisTopBox = false
this.isGisTopBoxTwo = true
if(this.isMapLabel){//如果已经标注单位坐标
console.log('已标注单位位置')
@ -159,36 +196,38 @@ export class BasicinfoComponent implements OnInit {
this.map.add(this.newPositionMarker);
let markerPosition
if(this.markerPosition.x && this.markerPosition.x != 0){
markerPosition = {x: this.markerPosition.x,y: this.markerPosition.y}
this.markerPosition2 = {x: this.markerPosition.x,y: this.markerPosition.y}
}else{
markerPosition = {x: this.map.getCenter().lng,y: this.map.getCenter().lat} //获取当前地图中心位置
this.markerPosition2 = {x: this.map.getCenter().lng,y: this.map.getCenter().lat} //获取当前地图中心位置
}
this.newPositionMarker.on('dragend', (e)=>{
markerPosition = {x: e.lnglat.lng, y: e.lnglat.lat}
this.markerPosition2 = {x: e.lnglat.lng, y: e.lnglat.lat}
})
//点击确定
this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'),'click',(event)=>{
this.map.clearMap();
this.isGisTopBox = true
this.isGisTopBoxTwo = false
this.newPositionMarker = new AMap.Marker({
position: [markerPosition.x,markerPosition.y],
position: [this.markerPosition2.x,this.markerPosition2.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-15, -18)
});
this.markerPosition = markerPosition
this.markerPosition = this.markerPosition2
this.map.add(this.newPositionMarker);
})
//点击取消
this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionClose'),'click',(event)=>{
this.isGisTopBox = true
this.isGisTopBoxTwo = false
this.map.clearMap();
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x,this.markerPosition.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-15, -18)
});
this.map.setCenter([this.markerPosition.x,this.markerPosition.y]); //设置地图中心点
this.map.add(this.newPositionMarker);
})
@ -213,19 +252,20 @@ export class BasicinfoComponent implements OnInit {
});
this.map.add(this.newPositionMarker);
let markerPosition
// let markerPosition
if(this.markerPosition.x && this.markerPosition.x != 0){
markerPosition = {x: this.markerPosition.x,y: this.markerPosition.y}
this.markerPosition2 = {x: this.markerPosition.x,y: this.markerPosition.y}
}else{
markerPosition = {x: this.map.getCenter().lng,y: this.map.getCenter().lat} //获取当前地图中心位置
this.markerPosition2 = {x: this.map.getCenter().lng,y: this.map.getCenter().lat} //获取当前地图中心位置
}
this.newPositionMarker.on('dragend', (e)=>{
markerPosition = {x: e.lnglat.lng, y: e.lnglat.lat}
this.markerPosition2 = {x: e.lnglat.lng, y: e.lnglat.lat}
})
//点击确定
this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionOk'),'click',(event)=>{
this.isGisTopBox = true
this.markerPosition = markerPosition
this.isGisTopBoxTwo = false
this.markerPosition = this.markerPosition2
this.map.clearMap();
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x,this.markerPosition.y],
@ -237,16 +277,19 @@ export class BasicinfoComponent implements OnInit {
this.renderer2.listen(this.elementRef.nativeElement.querySelector('#setPositionClose'),'click',(event)=>{
this.map.clearMap();
this.isGisTopBox = true
this.isGisTopBoxTwo = false
if(this.markerPosition.x && this.markerPosition.x != 0){//说明之前标过点
this.newPositionMarker = new AMap.Marker({
position: [this.markerPosition.x,this.markerPosition.y],
content: this.newPositionMarkerContent,
offset: new AMap.Pixel(-15, -18)
});
this.map.setCenter([this.markerPosition.x,this.markerPosition.y]); //设置地图中心点
this.map.add(this.newPositionMarker);
}
})//取消
}

Loading…
Cancel
Save