3

I would like to add this layer to a site I'm working on that uses leaflet:

http://116.240.195.134/vicmapapi/UserGuide.jsp

The API itself is a javascript file based on OpenLayers: http://api.maps.vic.gov.au/vicmapapi/js/vicmapapi.js (I don't know OpenLayers at all, so I'm not really sure what I'm looking at).

Am I able to access the tiles using leaflet? This didn't work:

var map = L.map('map').setView([-37.3, 145.3], 5);

        var wms = L.tileLayer.wms("http://api.maps.vic.gov.au/vicmapapi/map/wms", {
        LAYERS: 'CARTOGRAPHICAL',
        FORMAT: 'image/png',
        FIRSTTITLE: false,
        transparent: true,
        WIDTH:512,
        HEIGHT:512,
        EXCEPTIONS:"application/vnd.ogc.se_inimage",
        SRS:"EPSG:3111"
        });
        wms.addTo(map);

In particular, it didn't work because the tiles it tried to fetch had URLs like this:

http://api.maps.vic.gov.au/vicmapapi/map/wms?service=WMS&request=GetMap&version=1.1.1&layers=&styles=&format=image/jpeg&transparent=true&height=256&width=256&LAYERS=CARTOGRAPHICAL&FORMAT=image/png&FIRSTTITLE=false&WIDTH=512&HEIGHT=512&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:3111&srs=EPSG:3857&bbox=18785164.071364917,-3757032.814272983,20037508.342789244,-2504688.542848655

instead of:

http://api.maps.vic.gov.au/vicmapapi/map/wms?LAYERS=CARTOGRAPHICAL&FORMAT=image%2Fpng&FIRSTTILE=false&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A3111&BBOX=2327867.7504022,2539132.2495979,2869735.5008043,3081000&WIDTH=512&HEIGHT=512&cache_bbox=2296369.732799%2C2279293.001349%2C2931371.002802%2C2702627.181351

The server then returns error messages like "400: (x + width) is outside of Raster". If I increase WIDTH to 10000, then Apache returns 500 Internal Server error with a complaint about Java heap space. Oops.

So - am I barking up the wrong tree here, or is there a way to do this?

  • Try zooming in further. Your bounding box contains huge negative numbers. Set the zoomlevel to eg 10. – johanvdw Sep 3 '13 at 7:36
  • 1
    I think the problem might also be due to the SRS being EPSG:3111. Leaflet generally works with EPSG:3857; I'm not aware of the correct way of setting a LeafLet map in another Spatial reference. – Devdatta Tengshe Sep 3 '13 at 8:10
  • see api.maps.vic.gov.au/vicmapapi/map/wms?request=getcapabilities - as @DevdattaTengshe says the layers are only available as 3111 – Ian Turton Sep 3 '13 at 8:19
  • Thanks. Looks like changing the project in leaflet is possible (blog.kartena.se/…) but won't really help me, as I'd really need to reproject the tiles to match my existing project. – Steve Bennett Sep 4 '13 at 1:17
1

user1147183 put me on the right track, but I wanted to give a more complete answer.

So, first, yes, Leaflet can access a WMS service, using the TileLayer.WMS subclass.

If the tiles are not available in ESPG 3857 (Web Mercator) then you can either switch your whole leaflet interface to use whatever the WMS service is using (http://blog.kartena.se/local-projections-in-a-world-of-spherical-mercator/), or give up.

In this instance, after I posted the original question, VicMap began providing a separate WMS service in Web Mercator. They don't seem to have documented it anywhere, so thanks user1147183 for providing the URL: /geowebcacheWM/service/wms.

Calling the WMS function getCapabilities (http://api.maps.vic.gov.au/geowebcacheWM/service/wms?request=getcapabilities) shows that there is a layer called WEB_MERCATOR. (Strangely, the layer names bear no relation to those in the EPSG:3111 service, such as CARTOGRAPHICAL).

So, finally you can make this call in leaflet:

var wms = L.tileLayer.wms("http://api.maps.vic.gov.au/geowebcacheWM/service/wms?VERSION=1.1.1&TILED=true", {
                layers: ['WEB_MERCATOR'],
                format: 'image/png',
                transparent: false,
                continuousWorld: true,
            });

            wms.addTo(map);

The rendering is a little funny, but it's usable.

What it looks like

1

I am using the same API, just use their Web mercator version. I am making the request as such:

var wms = L.tileLayer.wms("http://api.maps.vic.gov.au/geowebcacheWM/service/wms?VERSION=1.1.1&TILED=true", {
    layers: [layer],
    format: 'image/'+ imgType,
    transparent: choice,
});

This map is then in 3857, which is the same as Google. Any data then that is in EPSG 4326 can be reprojected on the fly and does not need reprojection, such as GeoJSON. GeoJson by default uses 4326 so using 3111 is inconvenient.

Additional notes:

Note, they may have since changed the web mercator URL, I will update when I have the final one. Also, if you are using their satellite imagery, add the following: height:'512', width:'512' Furthermore, if you are calling the Hybrid or Cartograhic layers you should set the transparent to true because it is a png. The satellite imagery is in JPEG format and thus can be set to false.

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.