File

feature-libs/storefinder/components/store-finder-map/store-finder-map.component.ts

Implements

OnChanges

Metadata

selector cx-store-finder-map
templateUrl ./store-finder-map.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(googleMapRendererService: GoogleMapRendererService)
Parameters :
Name Type Optional
googleMapRendererService GoogleMapRendererService No

Inputs

locations
Type : any[]

Outputs

selectedStoreItem
Type : EventEmitter<number>

Methods

centerMap
centerMap(latitude: number, longitude: number)

Sets the center of the map to the given location

Parameters :
Name Type Optional Description
latitude number No

latitude of the new center

longitude number No

longitude of the new center

Returns : void
ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
renderMap
renderMap()
Returns : void
Private selectStoreItemClickHandle
selectStoreItemClickHandle(markerIndex: number)
Parameters :
Name Type Optional
markerIndex number No
Returns : void

Properties

locations
Type : any[]
Decorators :
@Input()
mapElement
Type : ElementRef
Decorators :
@ViewChild('mapElement', {static: true})
selectedStoreItem
Type : EventEmitter<number>
Default value : new EventEmitter()
Decorators :
@Output()
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  OnChanges,
  Output,
  SimpleChanges,
  ViewChild,
} from '@angular/core';
import { GoogleMapRendererService } from '@spartacus/storefinder/core';

@Component({
  selector: 'cx-store-finder-map',
  templateUrl: './store-finder-map.component.html',
})
export class StoreFinderMapComponent implements OnChanges {
  @ViewChild('mapElement', { static: true })
  mapElement: ElementRef;
  @Input()
  locations: any[];
  @Output()
  selectedStoreItem: EventEmitter<number> = new EventEmitter();

  constructor(private googleMapRendererService: GoogleMapRendererService) {}

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.locations && this.locations) {
      this.renderMap();
    }
  }

  /**
   * Sets the center of the map to the given location
   * @param latitude latitude of the new center
   * @param longitude longitude of the new center
   */
  centerMap(latitude: number, longitude: number): void {
    this.googleMapRendererService.centerMap(latitude, longitude);
  }

  renderMap(): void {
    this.googleMapRendererService.renderMap(
      this.mapElement.nativeElement,
      this.locations,
      (markerIndex) => {
        this.selectStoreItemClickHandle(markerIndex);
      }
    );
  }

  private selectStoreItemClickHandle(markerIndex: number) {
    this.selectedStoreItem.emit(markerIndex);
  }
}
<div #mapElement class="cx-store-map"></div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""