More

Can we set the latlng start point : leaflet

Can we set the latlng start point : leaflet


I am working with the leaflet api.

I am trying to figure out how to change or set the latlng start point in leaflet map.

Currently i am working on use image as map,,,,the latlng(0,0) is at the top left of the image or container of that image…

If its possible that i change it to left-bottom

Snapshot of map :

If its possible to change the position of origin (0,0) from top-left to bottom-left,,,,


First, read the source code forL.CRS.Simple, particularly, this line:

transformation: toTransformation(1, 0, -1, 0),

That is a factory method to instantiate an affine transformation from L.Transformation. Reading the documentation you can note that aL.Transformation(a, b, c, d)corresponds to the transformation with the affine matrix:

a 0 b 0 c d 0 0 1

So theL.Transformation(1, 0, -1, 0)fromL.CRS.Simplecorresponds to

1 0 0 0 -1 0 0 0 1

And by now you should be thinking "Hey, why does Leaflet invert the Y coordinate inL.CRS.Simple?" The answer is that screen pixel coordinates go down and right while coordinates in a cartesian coordinate system go up and right.

You should also note that planar coordinate systems are infinite in both the horizontal and vertical directions. That means that (0, 0) is not in a corner of the coordinate system, because… the coordinate system does not have corners.

Also note that there is no requirement that the (0, 0) coordinate corresponds to a corner of the image. You should define what are the semantics of your origin of coordinates. Do you want coordinates relative to a corner of the image, to the center (or centroid) of the building, to a nearby landmark, relative to another geographic CRS?

Also, what are the units of your CRS? Is 1 unit = 1 pixel in the image? 1 unit = 1 meter? 1 unit = 1 centimeter? 1 unit = 1 feet? 1 unit = 1 yard?

Now, assuming that you want to use a cartesian coordiante system, assign the (0, 0) coordinate to the bottom left of your image, and ensure that all pixels have positive (larger than zero) coordinates, then you don't need to do anything. (Just pay more attention to the semantics of your CRS).

Assuming that you want to use a cartesian coordinate system, assign the (0, 0) coordinate to the top left of your image, and ensure that all pixels have positive coordinates, then use a custom CRS inverting the Y axis relative toL.CRS. This can be achieved by defining such a CRS asL.CRS.Simple.extend({ transformation: L.transformation(1, 0, 1, 0) })(as per the Leaflet documentation on extending classes).

In any case, I suggest you pay more attention to the semantics of your coordinate system.