Blame view

src/app/data/map-items/map-items.component.ts 2.07 KB
c984e4db   Administrator   virtual page fix
1
2
3
4
5
  import { Component, Input, Output, OnInit } from '@angular/core';
  import * as L from 'leaflet';
  @Component({
      selector: 'map-items',
      template:`
9a741780   Administrator   virtual page fix
6
          <div class="map-items" [class.show]="show"> 
c984e4db   Administrator   virtual page fix
7
8
9
10
11
              <div id="mapItemsId"></div>
          </div>`,
      styleUrls: ['map-items.scss']
  })
  
53b62eea   Administrator   virtual page fix
12
  export class MapItemsComponent implements OnInit{
c984e4db   Administrator   virtual page fix
13
14
15
      @Input() position: string;
      public map: L.Map;
      public icon: L.Icon;
b4e8113b   Administrator   virtual page fix
16
      public markersGroup: L.FeatureGroup;
9a741780   Administrator   virtual page fix
17
      public show = false;
53b62eea   Administrator   virtual page fix
18
      ngOnInit(){
9a741780   Administrator   virtual page fix
19
  
b4e8113b   Administrator   virtual page fix
20
21
22
23
24
25
26
27
28
29
30
          // if(this.position != null){
          //     let options = {
          //         draggable:true,
          //         icon: this.icon,
          //     };
          //     let latLng = this.position.split(',');
          //     let marker = L.marker(new L.LatLng(parseInt(latLng[0]),parseInt(latLng[1])),options);
          //     this.map.addLayer(marker);
          //
          // }
      }
c984e4db   Administrator   virtual page fix
31
  
9a741780   Administrator   virtual page fix
32
33
34
35
36
37
38
39
40
41
42
43
      showMap(){
          this.show = true;
          this.icon = L.icon({
              iconUrl: '/assets/icons/marker-icon.png',
              iconSize:     [25, 41], // size of the icon
              popupAnchor:  [-3, -76], // point from which the popup should open relative to the iconAnchor
          });
          this.map = L.map('mapItemsId').setView([51.505, -0.09], 13);
          L.tileLayer('https://a.tile.openstreetmap.org/{z}/{x}/{y}.png', {
              maxZoom: 18,
          }).addTo(this.map);
      }
b4e8113b   Administrator   virtual page fix
44
45
46
      refreshMap(rows): void{
          if(this.markersGroup != null){
              this.map.removeLayer(this.markersGroup);
c984e4db   Administrator   virtual page fix
47
          }
b4e8113b   Administrator   virtual page fix
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
          let options = {
              draggable:true,
              icon: this.icon,
          };
          let markers = [];
          rows.map((row)=>{
              if(row != null){
                  let latLng = row.position.split(',');
                  console.log(parseFloat(latLng[0]) +'  '+parseFloat(latLng[1]));
                  markers.push(L.marker(new L.LatLng(parseFloat(latLng[0]),parseFloat(latLng[1])),options));
                  //markers.addLayer(marker);
              }
          });
          this.markersGroup = new L.FeatureGroup(markers);
          this.map.addLayer(this.markersGroup);
c984e4db   Administrator   virtual page fix
63
64
      }
  }