-
Notifications
You must be signed in to change notification settings - Fork 28
/
esri4-map.component.ts
65 lines (54 loc) · 1.53 KB
/
esri4-map.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Component, OnInit, Input, Output, ElementRef, ViewChild, EventEmitter } from '@angular/core';
import { Esri4MapService } from './../core';
@Component({
selector: 'esri4-map',
template: `
<div class="map" id="esri4-map" #map></div>
`,
styles: [`
.map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
`]
})
export class Esri4MapComponent implements OnInit {
map: __esri.Map;
mapView: __esri.MapView;
@ViewChild('map') mapEl: ElementRef;
@Input() mapProperties: __esri.MapProperties;
@Input() mapViewProperties: __esri.MapViewProperties = {};
@Input() portalItemId: string;
@Output() mapInit = new EventEmitter();
constructor(private mapService: Esri4MapService) { }
ngOnInit() {
if (this.map) {
// map is already initialized
return;
}
this.loadMap();
}
loadMap() {
// determine if loading a WebMap or creating a custom map
if (this.portalItemId) {
// create one object containing the portalItemId and the map properties
const mapProperties = Object.assign({
portalItem: {
id: this.portalItemId
}
}, this.mapProperties);
}
this.mapService.loadMap(this.mapProperties, this.mapViewProperties, this.mapEl).then(mapInfo => {
this.map = mapInfo.map;
this.mapView = mapInfo.mapView;
// emit event informing application that the map has been loaded
this.mapInit.emit({
map: this.map,
mapView: this.mapView
});
this.mapInit.complete();
});
}
}