File

libs/open-layers/src/lib/controls/ol-mouse-position/ol-mouse-position.component.ts

Description

Control component to show the coordinates at the mouse position

Extends

OlBaseComponent

Metadata

selector n52-ol-mouse-position

Index

Methods
Inputs

Constructor

constructor(mapService: OlMapService, mapidService: OlMapId, elementRef: ElementRef)
Parameters :
Name Type Optional
mapService OlMapService No
mapidService OlMapId No
elementRef ElementRef No

Inputs

projection
Default value : 'EPSG:3857'

Methods

mapInitialized
mapInitialized(map: Map)
Parameters :
Name Type Optional
map Map No
Returns : void
Abstract mapInitialized
mapInitialized(map: Map)
Inherited from OlBaseComponent
Defined in OlBaseComponent:33

This method will be triggered, when the corrsponding map is initialized.

Parameters :
Name Type Optional Description
map Map No
  • the created map
Returns : any
ngAfterViewInit
ngAfterViewInit()
Inherited from OlBaseComponent
Defined in OlBaseComponent:24

Subscribes for the initialization of the map after view is initialized

Returns : void
import { Component, ElementRef, Host, Input } from '@angular/core';
import { Map } from 'ol';
import { MousePosition } from 'ol/control';
import { createStringXY } from 'ol/coordinate';

import { OlBaseComponent } from '../../ol-base.component';
import { OlMapService } from '../../services/map.service';
import { OlMapId } from '../../services/mapid.service';

/**
 * Control component to show the coordinates at the mouse position
 */
@Component({
  selector: 'n52-ol-mouse-position',
  template: '',
})
export class OlMousePositionComponent extends OlBaseComponent {

  @Input() projection = 'EPSG:3857';

  constructor(
    protected mapService: OlMapService,
    @Host() protected mapidService: OlMapId,
    private elementRef: ElementRef
  ) {
    super(mapService, mapidService);
  }

  mapInitialized(map: Map) {
    const target = this.elementRef.nativeElement.parentElement ? this.elementRef.nativeElement : null;
    const ctrl = new MousePosition({
      coordinateFormat: createStringXY(4),
      projection: this.projection,
      undefinedHTML: ' ',
      target: target
    });
    map.addControl(ctrl);
  }

}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""