Skip to content
Snippets Groups Projects
homemap.component.ts 3.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    import Map from 'ol/Map';
    import View from 'ol/View';
    import TileLayer from 'ol/layer/Tile';
    import OSM from 'ol/source/OSM';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import ImageWMS from 'ol/source/ImageWMS';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import { fromLonLat } from 'ol/proj';
    import VectorSource from 'ol/source/Vector';
    import GeoJSON from 'ol/format/GeoJSON';
    import VectorLayer from 'ol/layer/Vector';
    import { DragRotateAndZoom, defaults as defaultInteractions } from 'ol/interaction';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import {bbox as bboxStrategy} from 'ol/loadingstrategy';
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import { environment } from 'src/environments/environment';
    import { OpenWindowService } from 'src/app/services/open-window.service';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import { AuthService } from 'src/app/services/auth.service';
    import { ActivatedRoute } from '@angular/router';
    import { User } from 'src/app/models/user';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import { StyleCalque } from 'src/app/utlis/style';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    import ImageLayer from 'ol/layer/Image';
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    @Component({
      selector: 'frt-homemap',
      templateUrl: './homemap.component.html',
      styleUrls: ['./homemap.component.css'],
      changeDetection: ChangeDetectionStrategy.OnPush
    })
    export class HomemapComponent implements OnInit {
    
      map!: Map;
      rightPanelVisibility = false;
      leftPanelVisibility = false;
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
      currentUser!: User;
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
      constructor(private openWindowService: OpenWindowService, private authService: AuthService, private actRoute: ActivatedRoute, private changeDetectorRef: ChangeDetectorRef) {}
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
      ngOnInit(): void {
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
        let id = Number(this.actRoute.snapshot.paramMap.get('id'));
        this.authService.getUserProfile(id).subscribe((res) => {
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          if (res.status === 401) {
    
            this.authService.doLogout();
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          }
          else{
            this.currentUser = res as User;
            this.changeDetectorRef.detectChanges();
          }
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        });
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        this.openWindowService.openTocEvents.subscribe(status => {
          this.rightPanelVisibility = status;
        });
    
        this.openWindowService.openLeftPanelEvents.subscribe(status => {
          this.leftPanelVisibility = status;
        });
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        const vectorSourceCommunes = new VectorSource({
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          format: new GeoJSON(),
          url: environment.communesURL
        });
    
        const vectorCommunes = new VectorLayer({
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          source: vectorSourceCommunes
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        });
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        vectorCommunes.setProperties({ name: 'Communes', id:'communes' });
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        const vectorSourceCalques = new VectorSource({
          format: new GeoJSON(),
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          url: function (extent) {
            return (
              environment.calqueURL +
              '&bbox=' +
              extent.join(',')+
              ',EPSG:3857'
            );
          },
          strategy: bboxStrategy
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        const vectorCalque = new VectorLayer({
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          minZoom: 15,
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          source: vectorSourceCalques,
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          style: StyleCalque.styleFunction
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        });
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        vectorCalque.setProperties({ name: 'Plantabilité', id:'calque' });
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        const rasterOSM = new TileLayer({
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          source: new OSM()
        });
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        rasterOSM.setProperties({ name: 'Open Street Map', id:'osm' });
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        const rasterCalque =  new ImageLayer({
          maxZoom: 15,
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          source: new ImageWMS({
            projection: 'EPSG:404000',
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
            url: environment.calqueRaster,
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
            params: {'LAYERS': 'Métropole_ERASME:tiles_temp'},
          }),
        });
    
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        rasterCalque.setProperties({ name: 'Plantabilité Raster', id:'calqueRaster' });
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        this.map = new Map({
          interactions: defaultInteractions().extend([new DragRotateAndZoom()]),
          view: new View({
            center: fromLonLat([environment.centerLongitude, environment.centerLatitude]),
            zoom: 11
          }),
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
          layers: [rasterOSM, rasterCalque, vectorCalque, vectorCommunes]
    
    ["Younes MHARRECH"]'s avatar
    ["Younes MHARRECH"] committed
        });
      }
    
      IsRightPanelVisible(): boolean {
        return this.rightPanelVisibility;
      }
    
      IsLeftPanelVisible(): boolean {
        return this.leftPanelVisibility;
      }
    
    }