ng2-bingmaps
Version:
Angular 2 components for Bing Maps
134 lines (132 loc) • 4.99 kB
JavaScript
/**
* ng2-bingmaps - Angular 2 components for Bing Maps
* @version v0.2.0
* @link https://github.com/youjustgo/ng2-bingmaps
* @license MIT
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Directive, EventEmitter, ContentChild } from '@angular/core';
import { MarkerManager } from '../services/marker-manager';
import { BingMapInfoWindow } from './bing-map-info-window';
let markerId = 0;
/**
* SebmGoogleMapMarker renders a map marker inside a {@link SebmGoogleMap}.
*
* ### Example
* ```typescript
* import {Component} from 'angular2/core';
* import {SebmGoogleMap, SebmGoogleMapMarker} from 'angular2-google-maps/core';
*
* @Component({
* selector: 'my-map-cmp',
* directives: [SebmGoogleMap, SebmGoogleMapMarker],
* styles: [`
* .sebm-google-map-container {
* height: 300px;
* }
* `],
* template: `
* <sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
* <sebm-google-map-marker [latitude]="lat" [longitude]="lng" [label]="'M'">
* </sebm-google-map-marker>
* </sebm-google-map>
* `
* })
* ```
*/
export let BingMapMarker = class BingMapMarker {
constructor(_markerManager) {
this._markerManager = _markerManager;
/**
* If true, the marker can be dragged. Default value is false.
*/
this.draggable = false;
/**
* This event emitter gets emitted when the user clicks on the marker.
*/
this.markerClick = new EventEmitter();
/**
* This event is fired when the user stops dragging the marker.
*/
this.dragEnd = new EventEmitter();
this._markerAddedToManger = false;
this._id = (markerId++).toString();
}
/* @internal */
ngAfterContentInit() {
if (this._infoWindow != null) {
this._infoWindow.hostMarker = this;
if (typeof this._infoWindow.latitude !== 'number' || typeof this._infoWindow.longitude !== 'number') {
// infowindow does not have lat and/or long. Set from marker values.
this._infoWindow.latitude = this.latitude;
this._infoWindow.longitude = this.longitude;
}
}
}
/** @internal */
ngOnChanges(changes) {
if (typeof this.latitude !== 'number' || typeof this.longitude !== 'number') {
return;
}
if (!this._markerAddedToManger) {
this._markerManager.addMarker(this);
this._markerAddedToManger = true;
this._addEventListeners();
return;
}
if (changes['latitude'] || changes['longitude']) {
this._markerManager.updateMarkerPosition(this);
if (typeof this._infoWindow !== 'undefined') {
this._infoWindow.latitude = this.latitude;
this._infoWindow.longitude = this.longitude;
}
}
if (changes['title']) {
this._markerManager.updateTitle(this);
}
if (changes['label']) {
this._markerManager.updateLabel(this);
}
if (changes['draggable']) {
this._markerManager.updateDraggable(this);
}
if (changes['iconUrl']) {
this._markerManager.updateIcon(this);
}
}
_addEventListeners() {
this._markerManager.createEventObservable('click', this).subscribe(() => {
if (this._infoWindow != null) {
this._infoWindow.open();
}
this.markerClick.next(null);
});
}
/** @internal */
id() { return this._id; }
/** @internal */
toString() { return 'BingMapMarker-' + this._id.toString(); }
/** @internal */
ngOnDestroy() { this._markerManager.deleteMarker(this); }
};
__decorate([
ContentChild(BingMapInfoWindow),
__metadata('design:type', BingMapInfoWindow)
], BingMapMarker.prototype, "_infoWindow", void 0);
BingMapMarker = __decorate([
Directive({
selector: 'bing-map-marker',
inputs: ['latitude', 'longitude', 'title', 'label', 'draggable: markerDraggable', 'iconUrl'],
outputs: ['markerClick', 'dragEnd']
}),
__metadata('design:paramtypes', [MarkerManager])
], BingMapMarker);
//# sourceMappingURL=bing-map-marker.js.map