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

199
Visualizações
Leaflet Map Cursor Configuration not Updating

I have a leaflet map with a cursor displaying the lat lang coordinate of the cursor.

L.CursorHandler = L.Handler.extend({

    addHooks: function () {
        this._popup = new L.Popup();
        this._map.on('mouseover', this._open, this);
        this._map.on('mousemove', this._update, this);
        this._map.on('mouseout', this._close, this);
    },

    removeHooks: function () {
        this._map.off('mouseover', this._open, this);
        this._map.off('mousemove', this._update, this);
        this._map.off('mouseout', this._close, this);
    },
    
    _open: function (e) {
        this._update(e);
        this._popup.openOn(this._map);
    },

    _close: function () {
        this._map.closePopup(this._popup);
    },

    _update: function (e) {
        this._popup.setLatLng(e.latlng)
            .setContent(e.latlng.toString());
    }
});

L.Map.addInitHook('addHandler', 'cursor', L.CursorHandler);

The original code formatted the lat-lon as "LatLng(12.25232563, 43.52432453)" for example. I edited the format in order to display to two decimal places without the LatLng or parentheses - eg: 12.25,43.52.

However, at some point, the configuration became fixed, and now only displays in this later 2-decimal places format:

enter image description here

This behaviour is bizarre, since even when I change the code to something like

_update: function (e) {
        this._popup.setLatLng(e.latlng)
            .setContent("Hello");
    }

the map popup format does not change, still displaying the decimal lat-lon from earlier. I am not sure why this is occuring, and why changes to the code do not reflect on the map. Even more strangely, I am not sure where the map draws the logic from, as it stubbornly continues to display the lat-long even when the entire method is deleted. The behaviour does not change upon stopping the React (npm) server / reloading the web-browser.

This is probably due to some internal state of the map which needs to be deleted/updated on page load. I would appreciate any advice!

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

0

It would seem that cursor settings for leaflet are global, and results set in a separate directory were affecting the cursor on all maps in the project.

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