I am attempting to get Leaflet to work for a standard, non-map image so that I can place markers on the image using pixels, not geographic latitude and longitudinal coordinates.
Here's a fiddle I'm attempting to get working:
http://jsfiddle.net/letsgetsilly/8Neau/4/
<div id="map" style="width: 1500px; height: 2316px"></div>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script>
var map = L.map('map', {
maxZoom: 4,
minZoom: 2,
crs: L.CRS.Simple
}).setView([0,50], 4);
var southWest = map.unproject([0, 4000], map.getMaxZoom());
var northEast = map.unproject([1500, 0], map.getMaxZoom());
map.setMaxBounds(new L.LatLngBounds(southWest, northEast));
//actual image dimensions: 1500 x 2000
var imageUrl = 'https://i.imgur.com/bXA34EQ.jpg';
var southWestSize = map.unproject([0, 2000], map.getMaxZoom());
var northEastSize = map.unproject([1500, 0], map.getMaxZoom());
L.imageOverlay(imageUrl, new L.LatLngBounds(southWestSize, northEastSize)).addTo(map);
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(map);
}
map.on('click', onMapClick);
L.marker(map.unproject([800, 300])).addTo(map).bindPopup("<b>I'm a dog!</b><br />I am a popup.<br /> ").openPopup();
</script>
I'm struggling on a couple of levels:
- I don't understand how to setView appropriately for a picture. What does leaflet need?
- I don't know how to get lat/lng coordinates of an image
- I don't know how to control the image's location on the screen, nor its size, so that it doesn't appear mangled
For those in a similar situation I found partial help from these sources:
Is Leaflet a good tool for non-map images?
http://omarriott.com/aux/leaflet-js-non-geographical-imagery/