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

291
Visualizações
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 Respostas
Responde à pergunta

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 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