Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CRS Support #37

Open
Alexr03 opened this issue Jun 24, 2024 · 4 comments
Open

Custom CRS Support #37

Alexr03 opened this issue Jun 24, 2024 · 4 comments

Comments

@Alexr03
Copy link

Alexr03 commented Jun 24, 2024

Hey! Great library!
I am really wanting to use this to show a game map (not the real world map). To do this I need to apply a custom CRS.

CUSTOM_CRS = L.extend({}, L.CRS.Simple, {
    projection: L.Projection.LonLat,
    scale: function(zoom) {
        return Math.pow(2, zoom);
    },
    zoom: function(sc) {
        return Math.log(sc) / 0.6931471805599453;
    },
    distance: function(pos1, pos2) {
        let x_difference = pos2.lng - pos1.lng;
        let y_difference = pos2.lat - pos1.lat;
        return Math.sqrt(x_difference * x_difference + y_difference * y_difference);
    },
    transformation: new L.Transformation(scale_x, center_x, -scale_y, center_y),
    infinite: true,
});

Im unsure whether this library can currently do this, if not I would love to see this functionality added! :)

Thanks.

@ichim
Copy link
Owner

ichim commented Jun 24, 2024

Hello sir,

Not, for this moment. Thanks a lot for your ideea.
You can provides more information about your project?

@Ksdmg
Copy link

Ksdmg commented Nov 8, 2024

Hi! Thanks for this awesome library! I wanted to do the same for a game, you can check the following page which basically does this: https://www.izurvive.com/
It is important to be able to map ingame coordinates to the leaflet map, so it is of any value. Please let me know if you have any more questions @ichim

@ichim
Copy link
Owner

ichim commented Nov 8, 2024

Hello sir,

I would like you to be more explicit. Want to create map elements (points, lines, polygons) using screen coordinates (pixels)?

@Ksdmg
Copy link

Ksdmg commented Nov 8, 2024

That is correct. I can give you an example:
My game map has its origin in the bottom left corner, x=0 y=0 and top right would be x=15360 y=15360.
Currently I'm working on a translation function, but it's more difficult than I thought. I just started using your library, so I still have to figure out how this works. I tried using a simple translation function: Leaflet currently has it's origin in the center 0/0 and lower left is x=-180 y=-85.

this is my translation:

private static double[] TranslateCoordinates(double[] coords)
{
    var latFactor = 15360 / 360;
    var lonFactor = 15360 / 170;
    return [(coords[0] / latFactor) - 180, (coords[1] / lonFactor) - 85];
}

However, does not translate correctly.

Edit:

Just found this library: https://github.com/iv-mexx/izurvive-sdk/tree/master which does exactly what I need. But it's more complicated than it has to be. Would be nice if we would get custom CRS :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants