kartena / Proj4Leaflet

Smooth Proj4js integration with Leaflet.
http://kartena.github.io/Proj4Leaflet/
BSD 2-Clause "Simplified" License
589 stars 173 forks source link

Confused on how CRS with TMS works #49

Closed Thermometer91 closed 10 years ago

Thermometer91 commented 10 years ago

Hi,

Recently I started developing a Leaflet mapviewer for use in a mobile application. I am using my company's own tileserver and custom projection, so I tried implementing Proj4Leaflet's CRS with TMS.

However, I can't seem to get my projection working properly. I'm a bit confused as to which type of coordinate I need to pass for the projection settings. We have our own type of coordinates that are roughly 1 meter per coordinate, which we can convert to WGS84 and back via a complicated js method. I am a pretty big GIS newbie, so I don't immediately know if I should use my own coordinates or WGS84 in for example the 'center' property.

Could you maybe help me understand what I am doing wrong? If this is the wrong place to ask these questions, please say so and I'll try it on Stackoverflow or similar. Here is a redacted version of my code:

var bbox = [0, 0, 5000000, 5000000]; // Bounding box in our own coordinates
var sp2Proj = new L.Proj.CRS.TMS('EPSG:x',
      'ourOwnProj4Def',
      bbox,
      {         
        scales: [0.8,1.6,3.2,6.4,12.8,25.6,51.2,102.4,204.8,409.8], // Scales we use 
        origin: [0,0] // Origin is at 0,0 our coordinates
      });
var map = L.map('map', {            
    zoom: 7,
    center: [1550000, 1920000], // These are our coordinates we would like to center on
    crs: sp2Proj,
    continuousWorld: false,
    worldCopyJump: false,
    inertia: true
});

map.addLayer(new L.Proj.TileLayer.TMS('http://ourtileserver.com/ts?&x={x}&y={y}&z={z}', sp2Proj, {
    maxZoom: 10,
    minZoom: 1,
    tileSize: 250,
    attribution : 'Copyrighted by x',
    noWrap : true,
    zoomReverse: true 
}));
perliedman commented 10 years ago

From what you write, it sounds like you are dealing with some form of non-standard projection, since you use a custom built js-function to project latitudes and longitudes. Unless this projection is actually something that Proj4js can handle, you can not use Proj4Leaflet for this task. Instead, you would have to implement your own L.Projection and possibly also L.CRS.

However, if the projection you use actually does map to some well known projection, possibly with an EPSG code, the code looks about right.

Regarding what coordinates to use, there is a simple rule: Leaflet's API always uses WGS84 (L.LatLng). You only deal with the projected coordinates when setting up Proj4Leaflet, or if you happen to get projected coordinates from some other source.

Thermometer91 commented 10 years ago

Wow, thanks for the amazing explanation! This helped me to figure out that we use an exotic projection (only used internally I was told) that cannot be properly handled by the Proj4js library. I will try to delve into making our own L.Projection and/or CRS.