question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to open snazzy info window programmatically?

See original GitHub issue

Issue description I want to open snazzy window from parent component. _openInfoWindow is protected, so I am not able to call it from my component. Maybe I am doing it wrong. I want to open the window of first marker

Steps to reproduce and a minimal demo of the problem

 <agm-map (mapReady)="mapReady()" [latitude]="lat" [longitude]="lng" [zoom]="zoom">            
            <agm-marker *ngFor="let m of markers; let i = index" [latitude]="m.latitude" [longitude]="m.longitude" [label]="m.label">
                <agm-snazzy-info-window [closeWhenOthersOpen]="true" [placement]="'bottom'" [maxWidth]="400" #infoWindow>
                    <ng-template>
                        My first Snazzy Info Window!                      
                    </ng-template>
                </agm-snazzy-info-window>
            </agm-marker>
        </agm-map>

class MyComponent{
 @ViewChildren("infoWindow") infoWindowComponents;
  mapReady() {
      let infoWindows: AgmSnazzyInfoWindow[] = this.infoWindowComponents._results;   
      //Want to open the info window of 0th window
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
calbear47commented, Oct 17, 2017

This is what I did:

In the component class:

@ViewChildren(AgmSnazzyInfoWindow) snazzyWindowChildren:QueryList<AgmSnazzyInfoWindow>;

  selectFacility(marker_index){
      let livewindow = this.snazzyWindowChildren.find((window, i)=>{return i === marker_index});
      livewindow._openInfoWindow();
  }

In template:


      <agm-map (mapClick)="mapClick()"
               [latitude]="(geoposition$ | async)?.latitude"
               [longitude]="(geoposition$ | async)?.longitude"
               [zoom]="zoom$ | async"
               [disableDefaultUI]="true"
               [streetViewControl]="false"
               [usePanning]="true"
               (centerChange)="centerChanged($event)">
        <agm-marker
          *ngFor="let facility of facilities$ | async; let idx = index;"
          [zIndex]="facility.obj._id === (highlightedIcon$ | async) ? 10000 : 100"
          [visible]="(currentFacility$ | async)?._id != facility.obj._id"
          [opacity]="1"
          (markerClick)="selectFacility(idx)"
          [iconUrl]="facility.obj._id === (highlightedIcon$ | async) ? currenticon : icon"
          [latitude]="facility.obj.location.coordinates[1]"
          [longitude]="facility.obj.location.coordinates[0]">
          <agm-snazzy-info-window [wrapperClass]="'cz-info-window-container'"
                                  [maxWidth]="275"
                                  [pointer]="'10px'"
                                  [openOnMarkerClick]="false"
                                  [closeWhenOthersOpen]="true"
                                  [showCloseButton]="false"
                                  [borderRadius]="'4px'"
                                  (beforeOpen)="infoWindowOpening()"
                                  [backgroundColor]="'#FFF'"
                                  [padding]="'0px'">
            <ng-template>
              <div #infoWindowContainer class="main-window-content" [routerLink]="['./', facility.obj._id]">
                <div class="full-image" [defaultImage]="'https://take.imgix.net/'+facility.obj.thumbnail+'?auto=format&w=273&h=auto&q=1&blur=100'" [lazyLoad]="'https://fake.imgix.net/'+facility.obj.thumbnail+'?auto=format&w=273&h=auto&q=50'"></div>
                <p>{{facility.obj.name}}</p>
              </div>
            </ng-template>
          </agm-snazzy-info-window>
        </agm-marker>
      </agm-map>

0reactions
Svathnacommented, May 27, 2020

This is what I did:

In the component class:

@ViewChildren(AgmSnazzyInfoWindow) snazzyWindowChildren:QueryList<AgmSnazzyInfoWindow>;

  selectFacility(marker_index){
      let livewindow = this.snazzyWindowChildren.find((window, i)=>{return i === marker_index});
      livewindow._openInfoWindow();
  }

In template:


      <agm-map (mapClick)="mapClick()"
               [latitude]="(geoposition$ | async)?.latitude"
               [longitude]="(geoposition$ | async)?.longitude"
               [zoom]="zoom$ | async"
               [disableDefaultUI]="true"
               [streetViewControl]="false"
               [usePanning]="true"
               (centerChange)="centerChanged($event)">
        <agm-marker
          *ngFor="let facility of facilities$ | async; let idx = index;"
          [zIndex]="facility.obj._id === (highlightedIcon$ | async) ? 10000 : 100"
          [visible]="(currentFacility$ | async)?._id != facility.obj._id"
          [opacity]="1"
          (markerClick)="selectFacility(idx)"
          [iconUrl]="facility.obj._id === (highlightedIcon$ | async) ? currenticon : icon"
          [latitude]="facility.obj.location.coordinates[1]"
          [longitude]="facility.obj.location.coordinates[0]">
          <agm-snazzy-info-window [wrapperClass]="'cz-info-window-container'"
                                  [maxWidth]="275"
                                  [pointer]="'10px'"
                                  [openOnMarkerClick]="false"
                                  [closeWhenOthersOpen]="true"
                                  [showCloseButton]="false"
                                  [borderRadius]="'4px'"
                                  (beforeOpen)="infoWindowOpening()"
                                  [backgroundColor]="'#FFF'"
                                  [padding]="'0px'">
            <ng-template>
              <div #infoWindowContainer class="main-window-content" [routerLink]="['./', facility.obj._id]">
                <div class="full-image" [defaultImage]="'https://take.imgix.net/'+facility.obj.thumbnail+'?auto=format&w=273&h=auto&q=1&blur=100'" [lazyLoad]="'https://fake.imgix.net/'+facility.obj.thumbnail+'?auto=format&w=273&h=auto&q=50'"></div>
                <p>{{facility.obj.name}}</p>
              </div>
            </ng-template>
          </agm-snazzy-info-window>
        </agm-marker>
      </agm-map>

@calbear47 the thing is that _openInfoWindow() method is declare as protect . so i can not use that method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to open snazzy info window programmatically? #1203
I want to open snazzy window from parent component. _openInfoWindow is protected, so I am not able to call it from my component....
Read more >
How to open/close a snazzy-info-window ... - Stack Overflow
Show activity on this post. You can indeed use the isOpen attribute to dynamically open/close the Snazzy info window. Save this answer. Show ......
Read more >
How to open/close a snazzy-info-window programmatically in ...
Coding example for the question How to open/close a snazzy-info-window programmatically in angular-google-maps?-Googlemaps.
Read more >
Angular (forked) - StackBlitz
open -close-a-snazzy-info-window-programmatically-in-angular-google-maps.
Read more >
Styled Info Windows with Snazzy Info Window & Angular ...
This creates a basic styled info window that opens when the user clicks on the marker and closes when another snazzy info window...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found