LatLngBounds flyer with simpler CRS and projection

I am using Leaflet 0.7.7, the latest stable release, and I am using custom CRS inherited from L.CRS.Simple .

CRS:

It is very similar to Simple CRS, but with c set to 1 (in Simple, c set to -1 ).

 L.CRS.XY = L.Util.extend({}, L.CRS.Simple, { code: 'XY', projection: L.Projection.LonLat, transformation: new L.Transformation(1, 0, 1, 0) }); 

The goal of this CRS is to have a real display system {x, y} , where y gets higher when reaching the bottom of the map (for example, a bitmap image).

Verification Code:

 var southWest = L.latLng(133, 0); var northEast = L.latLng(0, 170); var bounds = L.latLngBounds(southWest, northEast); document._map.setMaxBounds(bounds); document._map.fitBounds(bounds); document._markers[68].setLatLng(bounds.getNorthEast()); console.info('southWest', southWest); // L.LatLng {lat: 133, lng: 0} console.info('northEast', northEast); // L.LatLng {lat: 0, lng: 170} console.info('bounds', bounds); // L.LatLngBounds ( _northEast: L.LatLng {lat: 133, lng: 170 } _southWest: L.LatLng {lat: 0, lng: 0 } ) 

In fact, since I have custom CRS, I think that these lines are the source of the problem, since the maximum and minimum values ​​are incorrect in the {x, y} plane (even if I would prefer to use the "Point", but I can only use LatLng objects: confused :).

Actually, it seems obvious that this problem comes from my code, but in fact I would like to find a solution for this, that I did not need to switch to L.CRS.Simple , in which y above on the map.

So what is the solution to using borders with this simple custom projection?

0
source share
1 answer

EDIT:

It seems that Leaflet internally assumes that the points increase (as in the images), and it should be opposite in latitude (i.e., decrease during descent), since min, max, <= and> = comparisons are hard-coded.

Thus, it is probably not possible to create a CRS that will give you latitude in the same direction as Y. Also, if you are ready to change every function that compares latitudes in a sheet library ...

You can still “manipulate” the numbers the way you want, if you use the intermediate conversion function every time you need to provide coordinates, but rather when you need to read coordinates.

It will also give you the option to return the order of latitude (y) and longitude (x) as [x, y].

For instance:

 function revertLat(x, y) { return [-y, x]; } 

Demo: http://jsfiddle.net/ve2huzxw/101/


Original answer:

Any reason not to tweak L.LatLngBounds to suit your needs?

First of all, if you definitely do not need southWest and northEast, but only the angles for your borders, you can use L.LatLngBounds as it is. For example, all Leaflet methods would continue to work, even if the corners were not exactly southWest and northEast: map.fitBounds , L.imageOverlay , etc. Should work fine.

Otherwise, you will need to configure many methods in L.LatLngBounds (extension, pad, contains, intersects) to return the min / max and <= / "> = values.

0
source

All Articles