|
@@ -1,9 +1,7 @@
|
|
|
import {Component, Input, Output, EventEmitter, ViewChild, AfterViewInit} from '@angular/core';
|
|
|
import * as Parse from "parse";
|
|
|
|
|
|
-import {IonModal, ModalController} from '@ionic/angular';
|
|
|
-import {ComponentRef} from '@angular/core';
|
|
|
-
|
|
|
+import {IonModal} from '@ionic/angular';
|
|
|
import {OverlayEventDetail} from '@ionic/core';
|
|
|
|
|
|
|
|
@@ -19,9 +17,20 @@ import * as AMapLoader from "@amap/amap-jsapi-loader"
|
|
|
styleUrls: ['./comp-poi-picker.component.scss']
|
|
|
})
|
|
|
export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
+ @Input("name") _name: string
|
|
|
+ get name() {
|
|
|
+ return this._name
|
|
|
+ }
|
|
|
+
|
|
|
+ set name(v) {
|
|
|
+ this._name = v;
|
|
|
+ this.nameChange.emit(v)
|
|
|
+ }
|
|
|
|
|
|
+ @Output() nameChange: EventEmitter<string> = new EventEmitter()
|
|
|
|
|
|
- @Input("address") _address?: string
|
|
|
+
|
|
|
+ @Input("address") _address: string
|
|
|
get address() {
|
|
|
return this._address
|
|
|
}
|
|
@@ -33,7 +42,7 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
|
|
|
@Output() addressChange: EventEmitter<string> = new EventEmitter()
|
|
|
|
|
|
- @Input("location") _location?: Parse.GeoPoint
|
|
|
+ @Input("location") _location!: Parse.GeoPoint
|
|
|
get location() {
|
|
|
return this._location
|
|
|
}
|
|
@@ -45,23 +54,26 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
|
|
|
@Output() locationChange: EventEmitter<Parse.GeoPoint> = new EventEmitter()
|
|
|
|
|
|
- constructor(private modalController: ModalController) {
|
|
|
+ constructor() {
|
|
|
+ this._name = '';
|
|
|
+ this._address = '';
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
* 弹窗效果区域
|
|
|
*/
|
|
|
isModalOpen: boolean = false;
|
|
|
- @ViewChild(IonModal, {static: false}) modal: IonModal | undefined;
|
|
|
+ @ViewChild(IonModal) modal!: IonModal;
|
|
|
|
|
|
cancel() {
|
|
|
this.isModalOpen = false;
|
|
|
- this.modal?.dismiss(null, 'cancel');
|
|
|
+ this.modal.dismiss(null, 'cancel');
|
|
|
}
|
|
|
|
|
|
confirm() {
|
|
|
this.isModalOpen = false;
|
|
|
- this.modal?.dismiss(this.address, 'confirm');
|
|
|
+ this.modal.dismiss(this.address, 'confirm');
|
|
|
}
|
|
|
|
|
|
onWillDismiss(event: Event) {
|
|
@@ -73,7 +85,9 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
|
|
|
openModal() {
|
|
|
this.isModalOpen = true
|
|
|
- this.initMap()
|
|
|
+ setTimeout(() => {
|
|
|
+ this.initMap()
|
|
|
+ }, 500);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -82,10 +96,7 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
AMap: any;
|
|
|
map: any;
|
|
|
|
|
|
- async ngAfterViewInit() {
|
|
|
- const modalElement = await this.modalController.getTop();
|
|
|
- const componentProps = modalElement?.componentProps;
|
|
|
- const modal = componentProps?.['modal'] as IonModal;
|
|
|
+ ngAfterViewInit(): void {
|
|
|
}
|
|
|
|
|
|
initMap() {
|
|
@@ -122,7 +133,7 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
this.map.addControl(geolocation);
|
|
|
|
|
|
|
|
|
- geolocation.getCurrentPosition(<PositionCallback>function (status: any, result: any) {
|
|
|
+ geolocation.getCurrentPosition(function (status: string, result: any) {
|
|
|
if (status === 'complete') {
|
|
|
|
|
|
console.log('当前位置经度:' + result.position.getLng());
|
|
@@ -139,7 +150,7 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
this.AMap.plugin(["AMap.PlaceSearch"], () => {
|
|
|
|
|
|
let placeSearch = new this.AMap.PlaceSearch({
|
|
|
- pageSize: 5,
|
|
|
+ pageSize: 3,
|
|
|
pageIndex: 1,
|
|
|
|
|
|
|
|
@@ -150,10 +161,13 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
|
|
|
placeSearch.on('selectChanged', (event: any) => {
|
|
|
|
|
|
+ this.name = event.selected.data.name
|
|
|
+ this.address = event.selected.data.address
|
|
|
this.location = new Parse.GeoPoint({
|
|
|
latitude: event.selected.data.location.lat,
|
|
|
longitude: event.selected.data.location.lng
|
|
|
})
|
|
|
+ this.createCenterMarker();
|
|
|
})
|
|
|
|
|
|
|
|
@@ -164,4 +178,26 @@ export class CompPoiPickerComponent implements AfterViewInit {
|
|
|
placeSearch.search(this.address);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ centerMarker: any
|
|
|
+
|
|
|
+ createCenterMarker() {
|
|
|
+ if (this.centerMarker) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.centerMarker = new this.AMap.Marker({
|
|
|
+ position: this.map.getCenter(),
|
|
|
+ offset: new this.AMap.Pixel(-15, -15),
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ this.map.add(this.centerMarker)
|
|
|
+ this.map.on('dragging', () => {
|
|
|
+ this.centerMarker.setPosition(this.map.getCenter());
|
|
|
+ });
|
|
|
+ this.map.on('dragend', () => {
|
|
|
+ let pos = this.centerMarker.getPosition()
|
|
|
+ this.location = new Parse.GeoPoint({latitude: pos.lat, longitude: pos.lng})
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|