Using image layer as a map in LeafLet

1,846 views
Skip to first unread message

Stefek Burczymucha

unread,
Nov 15, 2013, 7:49:22 AM11/15/13
to leafl...@googlegroups.com
Hello,

I would like to use LeafLet with image layer to get a simple map from image, with XY coordinates, and I have a questions:

1. How can I zoom out image layer to view whole image?
2. I've add marker in center point of map, I see that in LeafLet it is missplaced in compare to OpenLayers, what I' doing wrong?

Here is a sample code which I'm using in LeafLet and sample code from OpenLayers:


Thank you, best regards!

Stefek

Sameer Kalburgi

unread,
Nov 20, 2013, 1:21:39 PM11/20/13
to leafl...@googlegroups.com
I had to do something similar.

Basically the view as defined by the Simple CRS system is only 250x250 (I think), but you're showing an image that is 691x541, so you'll only ever see 250x250 of the image at a time.

One way is to "scale" the image by the ratio of the image's dimensions over the map's dimensions (I choose whichever dimension is bigger)

Here's an updated example: http://jsfiddle.net/CTxFs/2/

Hope that helps!

Sameer Kalburgi

unread,
Nov 20, 2013, 1:43:22 PM11/20/13
to leafl...@googlegroups.com
One more thing, I think you may have swapped lat and lng when defining your bounds.

Here's an updated example that fixes the centering: http://jsfiddle.net/xyf9j/

Stefek Burczymucha

unread,
Nov 21, 2013, 4:41:31 PM11/21/13
to leafl...@googlegroups.com
W dniu środa, 20 listopada 2013 19:43:22 UTC+1 użytkownik Sameer Kalburgi napisał:
One more thing, I think you may have swapped lat and lng when defining your bounds.

Here's an updated example that fixes the centering: http://jsfiddle.net/xyf9j/

Hello,

Great :) Thank you very much, here is an updated example with markers: http://jsfiddle.net/62GXR/1/

Best regards,
Stefek

Sameer Kalburgi

unread,
Nov 22, 2013, 3:13:30 PM11/22/13
to leafl...@googlegroups.com
Welcome, glad it helped!

Another caveat: if anyone needs to persist the marker information in anyway remember to un-scale the lat lng to get the "true" lat lng (which are really the x y positions as this is Simple CRS).

Ex:
marker_to_persist.x_position = lng * scale
marker_to_persist.y_position = lat * scale

Stefek Burczymucha

unread,
Nov 25, 2013, 7:00:07 AM11/25/13
to leafl...@googlegroups.com

W dniu środa, 20 listopada 2013 19:21:39 UTC+1 użytkownik Sameer Kalburgi napisał:
I had to do something similar.

Basically the view as defined by the Simple CRS system is only 250x250 (I think), but you're showing an image that is 691x541, so you'll only ever see 250x250 of the image at a time.

Hello,

Is it possible to do the same thing with TileLayer (when I generate tiles from my image with MapTiler)? I don't see an option to specify bounds on TileLayer :(

Best regards,
Stefek
Reply all
Reply to author
Forward
0 new messages