1

I am not sure about Leaflet 1.7 possibility to show layers in EPSG:3765. Not sure because from Leaflet docs it is not possible but I found something like Proj4Leaflet and it looks like it can... I get some error:

GridLayer.js:661 Uncaught Error: Attempted to load an infinite number of tiles

My code:

//define crs    
var crs= new L.Proj.CRS('EPSG:3765',
        '+proj=tmerc +lat_0=0 +lon_0=16.5 +k=0.9999 +x_0=500000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
        {
        resolutions: [128, 64, 32, 16,
        8, 4, 2, 1, 0.5,
        0.25, 0.125, 0.0625],
        origin: [477174.25,4882262.63],
        bounds:[208311.05,4614890.75,
        724721.78,5159767.36] 
        }
        );

can someone explain what is represented with resolutions (is that zoom level), origin and bounds?

//map
var mymap = L.map('map',{
            zoomControl:false, 
            crs:crs
            }).setView([477174.25,4882262.63], 15);

//WMS
var lyrDOF = new L.TileLayer.WMS('https://geoportal.dgu.hr/services/dof/wms', {
                layers: 'DOF5_2011',
                format: 'image/png',
                transparent: true,
                version: '1.3.0',
                crs: crs
            }).addTo(mymap);

Error is: GridLayer.js:661 Uncaught Error: Attempted to load an infinite number of tiles.

  • 1
    I recommend reading the Proj4Leaflet ReadMe where they explain about using L.Proj.geoJson. You should note that basemaps (for example the common OpenStreetmap background) are mostly in EPSG:3857/EPSG:900913 – Dror Bogin Oct 12 at 11:21
  • 1
    Leaflet supports only one CRS per map and it has no option for layer source reprojection to another CRS. This means all you layer must have the same CRS, and if it's not one of the Leaflet defined CRSs (see Defined CRSs section in leafletjs.com/reference-1.7.1.html#crs), as @DrorBogin wrote, you'll have to use Proj4Leaflet plugin to define your CRS. – TomazicM Oct 12 at 13:59
2

There are several reasons why your map does not work:

  1. If you specify origin when defining CRS, it is lower left corner of CRS, not center. In your case that would be [208311.05, 4614890.75].
  2. When defining CRS, you don't have to specify bounds. If you do, they must be in the form of L.bounds object, the first two coordinates must be lower left corner and the last two upper rightr corner. In your case that would be L.bounds([[208311.05, 4614890.75], [724721.78, 5159767.36]]).
  3. Regardless of the CRS you are using, all coordinates passed as parameters to Leflet methods/functions must be unprojected [lat, lng] (notice reversed order).
  4. in setView you are setting your initial zoom to 15, but you have only 12 resolutions defined in CRS, so the highest zoom would be 11, since they start with 0.
  5. Highest actual resolution of your WMS layer is 0.5, so there is no need to define resolutions beyond that.

So code could then look something like this (view is centered on Zagreb):

var crs = new L.Proj.CRS('EPSG:3765',
  '+proj=tmerc +lat_0=0 +lon_0=16.5 +k=0.9999 +x_0=500000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
  {
    resolutions: [128, 64, 32, 16, 8, 4, 2, 1, 0.5],
    origin: [208311.05, 5159767.36],
  }
);

var mymap = L.map('map',{
  zoomControl:false, 
  crs: crs
});
          
var lyrDOF = new L.TileLayer.WMS('https://geoportal.dgu.hr/services/dof/wms', {
                layers: 'DOF5_2011',
                format: 'image/png',
                transparent: true,
                version: '1.3.0',
                crs: crs
            });

lyrDOF.addTo(mymap);

mymap.setView([45.842734, 15.962578], 1);
| improve this answer | |
  • thanks for great explanation, it works. Number 2. you mean lower left and upper right? Just few additional question, why is setView in LatLng, and on map click I get LatLng instead of procjection coordinates? How to get projection coordinates? OSM layers doesn't work in these case and I presumed all calculations/distances/area are in wgs84 not projection, so I willstick to original crs. – ejovrh2 Oct 14 at 12:41
  • If you have new/additional questions, please post them as separate questions. Keep in mind GIS SE policy: one question per question. – TomazicM Oct 14 at 14:34
  • I corrected my answer regarding origin and bounds (points 1 and 2). – TomazicM Oct 15 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.