Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
Load Google Maps once and then only manipulate it

I'm currently building an Angular project that uses Google Maps Javascript API. I've created component that contains map and maniulating it using @Input values.

But I'm placing this component in multiple routes and every time after navigating to components thats using this one, the map is loading again.

I'm curious if there is a solution to load map only once, after app start and then only manipulating using inputs or services. I think this will prevent from way tooo many conversions which could be expensive.

Thanks for any ideas!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Google map only load one time if you initialize it in ngAfterViewInit: For example:

You have this method that create the map with its settings and invoke the method in ngAfterViewInit:

  @ViewChild('mapContainer', {static: false}) gmap: ElementRef;
      
  lat: number = 41.850033;
  lng: number = -87.6500523;
  
  mapOptions: google.maps.MapOptions;
  map:        google.maps.Map;

mapInitializer() {
    
    let coordinates = new google.maps.LatLng(this.lat, this.lng);
    this.mapOptions = {
      center:                 coordinates,
      zoom:                   4,
      disableDefaultUI:       true,
      zoomControl:            false,
      scrollwheel:            false,
      disableDoubleClickZoom: true,
      
    };
    this.map = new google.maps.Map(this.gmap.nativeElement, 
                                    this.mapOptions);
      
  }

ngAfterViewInit(): void {
    this.mapInitializer();
  }

Let me know it worked for you

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda