Advertisement
Guest User

Home,ts

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, ViewChild, ElementRef } from '@angular/core';
  2. import { IonicPage, AlertController } from 'ionic-angular';
  3. import { ModalProvider } from '../../providers/modal/modal';
  4. import {
  5.   RestaurantParserProvider,
  6.   Restaurant
  7. } from '../../providers/restaurant-parser/restaurant-parser';
  8. import {
  9.   GoogleMaps,
  10.   GoogleMap
  11. } from '@ionic-native/google-maps';
  12.  
  13. declare var google;
  14. import {
  15.   PAGE_TITLE_HOME,
  16.   PAGE_INDEX_HOME
  17. } from '../../config/constants';
  18.  
  19. @IonicPage()
  20. @Component({
  21.   selector: 'page-home',
  22.   templateUrl: 'home.html'
  23. })
  24. export class HomePage {
  25.   pageTitle: string = PAGE_TITLE_HOME;
  26.  
  27.   @ViewChild('map') mapElement: ElementRef;
  28.   private map: any;
  29.  
  30.   constructor(public modalProv: ModalProvider,
  31.               public restProv: RestaurantParserProvider,
  32.               private googleMaps: GoogleMaps) {
  33.   }
  34.  
  35.   ionViewDidLoad(){
  36.     console.log('ionViewDidLoad');
  37.     this.loadMap();
  38.   }
  39.  
  40.   loadMap() {
  41.  
  42.     let styles = [
  43.       {
  44.         featureType: "poi",
  45.          stylers: [
  46.           { visibility: "off" }
  47.         ]
  48.       }
  49.     ];
  50.  
  51.     let image = {
  52.       labelOrigin: new google.maps.Point(25,50),
  53.       url: '../assets/icon/marker_maps.png',
  54.       scaledSize: new google.maps.Size(50, 50),
  55.     };
  56.     let latLng = new google.maps.LatLng(50.781294, 6.078578);
  57.  
  58.     let mapOptions = {
  59.       center: latLng,
  60.       zoom: 15,
  61.       mapTypeId: google.maps.MapTypeId.ROADMAP,
  62.       disableDefaultUI: true,
  63.       styles: styles
  64.     };
  65.  
  66.     this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
  67.  
  68.     let locations = [
  69.       ['Example1', 50.780834, 6.079392, 4],
  70.       ['Example2', 50.780483, 6.078949, 5],
  71.       ['Example3', 50.780479, 6.080323, 3],
  72.       ['Example4', 50.781531, 6.078275, 2],
  73.       ['Example5', 50.779247, 6.078245, 1]
  74.     ];
  75.  
  76.     let infowindow = new google.maps.InfoWindow();
  77.  
  78.     let marker, i;
  79.  
  80.     for (i = 0; i < locations.length; i++) {
  81.       marker = new google.maps.Marker({
  82.         position: new google.maps.LatLng(locations[i][1], locations[i][2]),
  83.         map: this.map,
  84.         animation: google.maps.Animation.DROP,
  85.         icon: image,
  86.         label: {
  87.           text: locations[i][0],
  88.           color: "orange",
  89.           fontSize: "13px",
  90.           fontWeight: "bold"
  91.         }
  92.       });
  93.  
  94.       google.maps.event.addListener(marker, 'click', (function(marker, i) {
  95.         return function() {
  96.           infowindow.setContent(locations[i][0]);
  97.           infowindow.open(this.map, marker);
  98.         }
  99.       })(marker, i));
  100.     }
  101.   }
  102.  
  103.   openRestaurantPopover(restaurant: Restaurant): void {
  104.     this.modalProv.presentRestaurantPopover(restaurant);
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement