packages/location/src/lib/location-map.component.ts
Shows Google Maps Map
selector | ec-location-map |
styleUrls | ./location-map.component.scss |
templateUrl | ./location-map.component.html |
Methods |
Inputs |
Outputs |
center | |
Type : literal type
|
|
Default value : { latitude: 48.8093253, longitude: 9.159388100000001 }
|
|
The desired map center |
disabled | |
Type : boolean
|
|
If true, no marker can be chaned |
readOnly | |
Type : boolean
|
|
If true, no markers can be changed or set |
value | |
Type : literal type
|
|
Form input component |
changed | |
Type : EventEmitter<any>
|
|
Emits when the marker has been changed |
markerDragEnd | ||||
markerDragEnd(coords)
|
||||
changes value on marker dragend
Parameters :
Returns :
void
|
setValue | ||||
setValue(value)
|
||||
sets the value cand changes the center
Parameters :
Returns :
void
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
/** Shows Google Maps Map */
@Component({
selector: 'ec-location-map',
templateUrl: './location-map.component.html',
styleUrls: ['./location-map.component.scss'],
})
export class LocationMapComponent {
/** The desired map center */
@Input() center: { longitude: any; latitude: any } = { latitude: 48.8093253, longitude: 9.159388100000001 };
/** If true, no markers can be changed or set */
@Input() readOnly: boolean;
/** If true, no marker can be chaned */
@Input() disabled: boolean;
/** Emits when the marker has been changed */
@Output() changed: EventEmitter<any> = new EventEmitter();
/** Form input component */
@Input() value: {
longitude: number;
latitude: number;
};
/** sets the value cand changes the center */
setValue(value) {
if (this.disabled) {
console.warn('cannot change map value: disabled!');
return;
}
this.value = value;
if (value) {
this.center = value;
}
}
/** changes value on marker dragend */
markerDragEnd(coords) {
if (!coords) {
console.warn('no coords');
return;
}
if (this.disabled) {
return;
}
const position = { longitude: coords.lng, latitude: coords.lat };
this.setValue(position);
this.changed.emit(position);
}
}
<agm-map [latitude]="center?.latitude" [longitude]="center?.longitude">
<agm-marker #marker [markerDraggable]="!readOnly&&!disabled" (dragEnd)="markerDragEnd($event?.coords)" [latitude]="value?.latitude"
[longitude]="value?.longitude" *ngIf="value"></agm-marker>
</agm-map>
./location-map.component.scss
:host {
height: 300px;
}
agm-map {
height: 300px;
}