Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!