File

libs/open-layers/src/lib/controls/legend/ol-layer-zoom-extent/ol-layer-zoom-extent.component.ts

Description

Legend component to gather the layer extent by the WMS capabilities and provide the ability to zoom to the extent

Implements

OnInit

Metadata

selector n52-ol-layer-zoom-extent
templateUrl ./ol-layer-zoom-extent.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(wmsCaps: WmsCapabilitiesService, mapServices: OlMapService)
Parameters :
Name Type Optional
wmsCaps WmsCapabilitiesService No
mapServices OlMapService No

Inputs

layer
Type : BaseLayer
mapId
Type : string

corresponding map id

Methods

ngOnInit
ngOnInit()
Returns : void
Public zoomToExtent
zoomToExtent()
Returns : void

Properties

Private crs
Type : string
Private extent
Type : number[]
Private layerid
Type : string
Private url
Type : string
Private view
Type : View
import { Component, Input, OnInit } from '@angular/core';
import { Required } from '@helgoland/core';
import { View } from 'ol';
import BaseLayer from 'ol/layer/Base';
import Layer from 'ol/layer/Layer';
import { transformExtent } from 'ol/proj';
import { TileWMS } from 'ol/source';

import { OlMapService } from '../../../services/map.service';
import { WmsCapabilitiesService } from '../../../services/wms-capabilities.service';

/**
 * Legend component to gather the layer extent by the WMS capabilities and provide the ability to zoom to the extent
 */
@Component({
  selector: 'n52-ol-layer-zoom-extent',
  templateUrl: './ol-layer-zoom-extent.component.html'
})
export class OlLayerZoomExtentComponent implements OnInit {

  @Required @Input() layer: BaseLayer;

  /**
   * corresponding map id
   */
  @Required @Input() mapId: string;

  private url: string;
  private layerid: string;
  private extent: number[];
  private crs: string;
  private view: View;

  constructor(
    private wmsCaps: WmsCapabilitiesService,
    private mapServices: OlMapService
  ) { }

  ngOnInit() {
    if (this.layer.getExtent()) {
      this.extent = this.layer.getExtent();
    } else if (this.layer instanceof Layer) {
      const source = this.layer.getSource();
      this.layer.getExtent();
      if (source instanceof TileWMS) {
        this.url = source.getUrls()[0];
        this.mapServices.getMap(this.mapId).subscribe(map => {
          this.view = map.getView();
          const epsgCode = this.view.getProjection().getCode();
          this.layerid = source.getParams()['layers'] || source.getParams()['LAYERS'];
          this.wmsCaps.getExtent(this.layerid, this.url, epsgCode).subscribe(res => {
            this.extent = res.extent;
            this.crs = res.crs;
          });
        });
      }
    }
  }

  public zoomToExtent() {
    if (this.extent) {
      if (!this.crs) {
        this.view.fit(this.extent);
      } else {
        const transformation = transformExtent(this.extent, this.crs, this.view.getProjection().getCode());
        this.view.fit(transformation);
      }
    }
  }
}
<span (click)="zoomToExtent()">Zoom to extent</span>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""