Giter VIP home page Giter VIP logo

Comments (4)

seabre avatar seabre commented on July 18, 2024

Custom distance, as in, showing a different unit than meters?

from leaflet.editablehandlers.

skunkfu2 avatar skunkfu2 commented on July 18, 2024

Hey seabre,

Not all, I still wish to use meters. Sorry if I didn't describe it properly.

I am using a game map with custom tiles and the maximum distance between each side of the map is 2km.

When using the measuring tool, I measure from point A to point B, and it gives me a crazy distance of 10231840.88m.

How would I go about defining the maximum distance between each end of the map? So instead of such a large distance, it will give me, for example, 200m.

Also, I tried using crs: L.CRS.Simple for simple latlng (which I use already for the map) however this does not work and it throws the following error: "Uncaught TypeError: Cannot call method 'latLngToPoint' of undefined".

I know I'm shocking at describing things, so I'll be happy to do a jsfiddle if need Be.

Cheers.

from leaflet.editablehandlers.

perliedman avatar perliedman commented on July 18, 2024

The measuring tool uses Leaflet's L.LatLng.distanceTo to calculate the distance between to LatLngs. In your case, since you're not using real latitudes and longitudes (I guess?), this method will give bogus values back.

A hack you could try is to overwrite L.LatLng.prototype.distanceTo with whatever distance calculation that suites you (I guess it would be an application of the Pythagorean theorem).

It could be nice to add functionality to the measuring tool so that you could give it your own function for calculating distances.

from leaflet.editablehandlers.

skunkfu2 avatar skunkfu2 commented on July 18, 2024

Hey perliedman,

Thanks for pointing me to the distanceTo function. My Javascript skills are limited but I will see what I can come up with.

Cheers buddy.

from leaflet.editablehandlers.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.