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

201
Visualizações
MapboxGl Distinguishing Between "Move" and "Fly" Event

In MapboxGL JS, is it possible to watch a "flyTo" event triggered by the geolocate API, and not the user moving around the screen manually by dragging the map?

I'm trying to trigger an action in my application only when the user successfully enters a search into the Geolocation controller. The map has a movestart event that works for this, but it also captures the user's movement of the screen via the cursor or their finger.

import Geocoder from "@mapbox/mapbox-gl-geocoder";
const geocoder = new Geocoder({
  countries: "us",
  accessToken: mapboxGl.accessToken,
  mapboxgl: mapboxGl,
  marker: false,
  render: function (item) {
    return `<span class='geocoder-dropdown-text'>${item.text}</span>`;
  },
});

map.on("movestart", (e) => {
  // The problem is this event is too broad...
});

Is it possible to only listen for the "flying" event when the Geolocation API fires, or specifically provide a callback to the Geocoder that will fire when the animation begins?

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

0

You can create a variable flying and set it to true when the fly starts. Then you can listen for events movestart or moveenv and check if it is dragged by a user or triggered fly event.

let flying = false;

map.on("flystart", function () 
  flying = true;
});

map.on("flyend", function () {
  flying = false;
});

map.on("moveend", function () {
  if (flying) {
    map.fire("flyend");
  }
});

function fly() {
  map.flyTo({
    center: [....],
  });
  map.fire("flystart");
}

Fiddle: https://jsfiddle.net/wdtc91qo/

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