Hi all
So, I've been struggling a lot trying to make this library do what I want. Please bear in mind that I'm new to the world of maps. I am trying to make an gamemap that is interaction-wise just like the one you can find here:
There is a simple xy-pair coordinate system already in the game, and I need my map to accurately represent that system. The point at which x and y are both 0, is at the northwestern-most point of the map. The coordinates for the southeastern-most tip of the map is x=5120, y=4096, so the ratio between map coordinates and pixels is 1:1.
I use the zoomify-plugin (
https://github.com/turban/Leaflet.Zoomify) to create a tilelayer. For my tiles I simply export a .tiff-image of the gameworld (5120px wide, 4096px high) from Photoshop using the built-in Zoomify-support. The map renders just fine on the page, but I cannot for the life of me get the coordinates to match whats expected. I need accurate coordinates since I plan on populating the map with a lot of markers using in-game coordinate references.
I found that I had to use something called CRS.Simple, which support non-lat-lng worlds.
$(function(){
var map = L.map('map', {
crs: L.CRS.Simple,
}).setView([0, 0], 0);
L.tileLayer.zoomify('path/to/tiles/', {width: 5120, height: 4096}).addTo(map);
});
Now, how do I tell Leaflet that the northwest corner has coordinates [0,0] and, conversely, that the southeast corner is [5120,4096]?
If i try to add a marker to the map this way, for instance:
// Desired coordinates for my marker
var x = 20;
var y = 20;
// Make a new L.Point with the x and y values
var point = new L.Point(x, y);
// Convert the point to a LatLng
var latlng = L.CRS.Simple.pointToLatLng(point);
L.Marker(latlng).addTo(map);
One would expect that the marker would end up 20px from the top, and 20px from the left, but it doesn't. It's as if the marker was placed with lat and lng values. Additionally, when i zoom the map, the y coordinate is way off, so it appears that the marker actually moves quite a distance between different zoom levels.
Please, can anyone assist me? It would be much appreciated!
Thanks!