Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
Leaflet.js userscript, trouble converting from coords to lat-long

I'm trying to create a userscript to extend the functionality of Leaflet.js app for an online game: https://dayz.ginfo.gg/chernarusplus/#c=-12;-156;1 I'm having trouble creating a function to convert coordinates into the lat/long values leaflet.js uses.

The map itself is 15,360 x 15,360 metres (from the games perspective). I've experimentally determined the width/height of the map using the leaflet.js lat/long values.

The below code creates a circle in all 4 corners, and the centre.

// Top right corner: [83.81, 167.2]
// Bottom left corner: [-88.81, -180]

// Lat/long "height/width" of the map
var b = {x: 86.31, y: 173.6};

// Centre of the map (lat/long)
var h = {x: -2.5, y: -6.4};

L.circleMarker([h.x + b.x, h.y + b.y], {radius: 10}).addTo(iZurvive._map);
L.circleMarker([h.x + b.x, h.y - b.y], {radius: 10}).addTo(iZurvive._map);
L.circleMarker([h.x - b.x, h.y + b.y], {radius: 10}).addTo(iZurvive._map);
L.circleMarker([h.x - b.x, h.y - b.y], {radius: 10}).addTo(iZurvive._map);
L.circleMarker([h.x, h.y], {radius: 10}).addTo(iZurvive._map);

When I attempted to create a function that translates a game position (x/y coordinate in metres) to the lat/long value used by leaflet.js, I wasn't getting correct placement. I tested this further by trying to make a circle halfway between the centre and bottom left corner, but that was also offset; code below

// Should be halfway between centre and bottom left corner, but it isn't
L.circleMarker([h.x - (b.x / 2), h.y - (b.y / 2)], {radius: 10}).addTo(iZurvive._map);

This image shows where the halfway circle should be (marked in red):

Example of where the circles are, with red circle showing where the nearby blue circle should be

My function for converting between game coordinates and leaflet.js lat/long is as follows, though testing it produces results that are considerably offset:

const MAP_SIZE = 15360;
function circle(_x, _y) {
   var scale = {x: MAP_SIZE / (b.x * 2), y: MAP_SIZE / (b.y * 2)};
   var coords = {x: _x / scale.y, y: _y / scale.y};
   L.circleMarker([h.x - b.x + coords.x, h.y - b.y + coords.y], {radius: 10}).addTo(iZurvive._map);
}
// Should be bottom left of the map but is moreso left centre
circle(4420, 2840);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Fixed using the L.LocUtil.pointToCoords function and the scaling values stored in global variables for the leaflet.js application.

The following code correctly places a marker at the provided x, y (e.g. 1000, 1000) coordinates:

var t = L.LocUtil.pointToCoords({x: 1000, y: 1000}, iZurvive._locSearch.options.scalingParams)
L.circleMarker(t, {radius: 10}).addTo(iZurvive._map);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda