datinc.7584:

I am trying to use the event_details to plot events on the world map. The issue the x,y,z returned in the event_details.json API is in map coordinates (I am guessing) and to plot them I need them in continent coordinates. To achieve this I get the details from maps.json which has map_rect and continent_rect. I am obviously doing something wrong because my events don’t plot correctly.

Using the shatterer as an example: event_details.json and maps.json

My math looks like:



map_width = map_rect[1][0] - map_rect[0][0]; 
map_height = map_rect[1][1] - map_rect[0][1];

continent_width = continent_rect[1][0] - continent_rect[0][0]; 
continent_height = continent_rect[1][1] - continent_rect[0][1];

xMap = (event_location["center"][0] - map_rect[0][0])/map_width;
yMap = (event_location["center"][1] - map_rect[0][1] )/map_height;

xContinent = continent_rect[0][0] + xMap * continent_width;
yContinent = continent_rect[0][1] + yMap * continent_height;

: xContinent = 29753.250000
: yContinent = 15739.083008

This gets me near the bottom of the map! Am I doing it wrong or is there a better way to get the continent coordinate for an event?

Here is a fiddle so you can see the math in action

THE FIX:
yMap = 1 – yMap;

smiley.1438:

For calculation of the map-coordinates -> world-coordinates have a look at this thread:
https://forum-en.guildwars2.com/forum/community/api/Event-Details-API-location-coordinates/first#post2262330

tl;dr: use the following to recalculate your coords:

function recalc_coords(continent_rect, map_rect, coords){
	return [
		Math.round(continent_rect[0][0]+(continent_rect[1][0]-continent_rect[0][0])*(coords[0]-map_rect[0][0])/(map_rect[1][0]-map_rect[0][0])),
		Math.round(continent_rect[0][1]+(continent_rect[1][1]-continent_rect[0][1])*(1-(coords[1]-map_rect[0][1])/(map_rect[1][1]-map_rect[0][1])))
	]
}

live example (caution, overkill!) http://gw2.chillerlan.net/examples/gw2maps-jquery.html

€: i checked your fiddle, the x coordinates were correct, buy y was far out, you should get [29753,12677]

Dr Ishmael.9685:

Specifically, see my second attachment in the thread that Smiley linked. Y coordinates get inverted when translating between continent and map coordinates, I don’t know why, but that’s why you got a point near the south end of the map when it should be at the north end.

In your fiddle, after the initial calculation of yMap, you need to do:

yMap = 1 – yMap;

before the yContinent calculation.

[EDIT] Whoops, I just realized that there are parentheses missing in that image. After the first set of parentheses in each equation, the (B2 – B1) terms should also be in parentheses, with the final + B1 outside of parentheses. If I have time later I’ll try to remember to type that all up in LaTeX again.

datinc.7584:

Thanks for the fast replies. It works perfectly now. Silly minus 1. I am not sure why they did that unless it is to cause developers sleepless nights.