From 8ac3a87733b421c1f1cb3b691f946c05bdae02df Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Fri, 06 Jul 2018 13:54:14 +0800 Subject: [PATCH] 设备,监控点维护 完善 --- src/app/routes/map/coordinates-picker/coordinates-picker.component.ts | 81 ++++++++++++++++++++++++++++++++-------- 1 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts index 470d625..1a787bd 100644 --- a/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts +++ b/src/app/routes/map/coordinates-picker/coordinates-picker.component.ts @@ -1,6 +1,6 @@ import { NzModalSubject } from 'ng-zorro-antd'; import { ReactiveFormsModule } from '@angular/forms'; -import { ViewEncapsulation, Component, ViewChild, ElementRef, NgZone } from '@angular/core'; +import { ViewEncapsulation, Component, ViewChild, ElementRef, NgZone, OnInit } from '@angular/core'; import { MapOptions, Point, MarkerOptions, ControlAnchor, NavigationControlOptions, NavigationControlType, BMapInstance } from 'angular2-baidu-map'; import { CoorPicker } from '@business/entity/data'; import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service'; @@ -13,9 +13,10 @@ templateUrl: './coordinates-picker.component.html', styleUrls: [ './coordinates-picker.component.css' ], }) -export class CoordinatesPickerComponent { +export class CoordinatesPickerComponent implements OnInit { Default_LNG = 121; Default_LAT = 31.4; + showZoom = 19; isSaving = false; markerOption: { point: Point, @@ -30,21 +31,24 @@ _BMap: any = null; constructor(private subject: NzModalSubject, private coorPickerService: CoorPickerService) { + + } + ngOnInit(): void { this.data = this.coorPickerService.data; let lng = this.data.longitude; - lng = lng === 0 || lng == null ? this.Default_LNG : lng; + lng = !lng ? this.Default_LNG : lng; this.data.longitude = lng; let lat = this.data.latitude; - lat = lat === 0 || lat == null ? this.Default_LAT : lat; + lat = !lat ? this.Default_LAT : lat; this.data.latitude = lat; this.options = { minZoom: 3, maxZoom: 19, cursor: 'default', - centerAndZoom: { - lng: lng, - lat: lat, - zoom: 19 + centerAndZoom: { + lng: this.data.longitude, + lat: this.data.latitude, + zoom: this.showZoom }, enableKeyboard: true }; @@ -69,7 +73,7 @@ width: -15 } }; - } + } private _marker: any = null; loadMarker(marker) { if (this._marker == null) { @@ -84,7 +88,7 @@ this._map.addEventListener( 'tilesloaded', (type, fn) => { - this._map.clearOverlays(); + // this._map.clearOverlays(); this._map.addOverlay(this._marker); } ); @@ -95,14 +99,59 @@ && this.data.longitude === this.Default_LNG && !!this.data.address && !!this.data.address.trim()) { - this._localSearch.search(this.data.address); + this.mapSearch(this.data.address); } } - queryTest: string; - mapSearch(param: any) { - let text = this.queryTest; - text = text == null || text.trim() === '' ? '���������' : text; - this._localSearch.search(text); + city: string; + // queryText: string; + mapSearch(queryText: string, isSearch?: boolean) { + + if (!!queryText && !!queryText.trim()) { + this.city = !!this.city ? this.city : '���������'; + const end = queryText.indexOf('���') + 1; + if (end > 0) { + let start = queryText.indexOf('���') + 1; + start = start > 0 ? start : queryText.indexOf('���') + 1; + start = start > end ? 0 : start; + if (start < end) { + this.city = queryText.slice(start, end).trim(); + if (!!this.city) { + this._map.setCurrentCity(this.city); + } + } + } + console.log(this.city); + const myGeo = new this._BMap.Geocoder(); + const that = this; + that._map.setCurrentCity(that.city); + myGeo.getPoint(queryText, function(point){ + let getPoint = false; + if (point) { + that.data.latitude = point.lat; + that.data.longitude = point.lng; + getPoint = true; + }else { + console.log('������������������������������������!'); + } + that.markerOption.point = { + lng: that.data.longitude, + lat: that.data.latitude + }; + that.options.centerAndZoom = { + lng: that.data.longitude, + lat: that.data.latitude, + zoom: that.showZoom + }; + // setTimeout(() => { + if (getPoint && !isSearch) { + that._map.centerAndZoom(point, that.showZoom); + + } else { + that._localSearch.search(queryText); + } + // }, 3000); + }, that.city); + } } clickMap(e: any) { this.markerOption.point = { -- Gitblit v1.8.0