2

My tilecache.cfg is like so (working with MapServer)

[mylayer]
type=WMS
url=http://server/mapserver/app
spherical_mercator=true
layers=mylayer

The following works just fine

var mylayer = new OpenLayers.Layer.WMS(
    "My Layer",
    "http://server/tilecache/tilecache.cgi",
    {layers: "mylayer", transparent: true},
    {isBaseLayer: false, opacity: 0.6, visibility: true}
);

However, when I change the above to Leafletjs like below

var mylayer = L.tileLayer.wms("http://server/tilecache/tilecache.cgi", {
    layers: 'mylayer',
    format: 'image/png',
    transparent: true,
    attribution: 'Data from blah blah'
});

I get the following error

An error occurred: Current y value -5009377.085697 is too far from tile corner y -10018754.170400

Suggestions?

Update2: (top-posted). I tried adding srs definitions (srs:"EPSG:4326" or srs:"EPSG:900913"). While the latter didn't help at all, the particular error I reported above went away with 4326, and a couple of tiles were also returned, though most tiles were just blank. This tells me something is goofy with the way Leaflet expects the projection. I'd rather not change anything on the source (MapServer or Tilecache side), if possible, as other applications are depending on that to be working.

Update: Adding the MapServer map file, in case that might help

MAP
    EXTENT -180.150250417362 -90 180.150250417362 90
    IMAGECOLOR 255 255 255
    IMAGETYPE "png"
    NAME "mylayer"
    SIZE 1200 600
    STATUS ON
    UNITS DD
    DEBUG 3
    CONFIG "MS_ERRORFILE" "/tmp/ms_mylayer_error.log"

    OUTPUTFORMAT
        NAME "png24"
        MIMETYPE "image/png"
        DRIVER "AGG/PNG"
        EXTENSION "png"
        IMAGEMODE RGBA
        TRANSPARENT ON
    END

    SHAPEPATH "/path/to/files"

    PROJECTION
        "init=epsg:4326"
    END

    WEB
        IMAGEPATH "/tmp/ms_tmp/"
        METADATA
            ows_enable_request "*"
            wms_abstract "This WMS mapservice serves a map of mylayer"
            wms_accessconstraints "none"
            wms_title "mylayer"
            wms_onlineresource "http://sever/cgi-bin/mylayer?"
            wms_srs "EPSG:900913 EPSG:4269 EPSG:4326"
            wms_keywordlist "World,mylayer"
            wms_enable_request "*"
        END
    END

    LAYER
        NAME "global"
        TYPE RASTER
        ..

        METADATA
            wms_srs "EPSG:4326"
            wms_name "global"
            wms_server_version "1.1.1"
            wms_format "image/png"
            wms_enable_reques "*"
            wms_extent "-180 -90 180 90"
        END
    END
END

1 Answer 1

1

Your map file says you are using epsg:4326 as a projection.

Leaflet map uses epsg:3857 as a default (https://github.com/Leaflet/Leaflet/blob/master/src/map/Map.js)

you could try passing following option when you create your L.Map object

var map = new L.Map('map', { crs: L.CRS.EPSG4326 });

Anyway, your problem is around projections

4
  • Mapfile does not have to do with this. There is TileCache in between and it naturally works as always. It is requesting EPSG:900913 which is configured in mapfile as default SRS on the MAP level. I would check if the error could be in the tile naming schema. TileCache is probably using the TMS specification by default while Leaflet may select the Google style tile naming schema. Same z/y/z means different tiles for these two schemata.
    – user30184
    Commented Aug 24, 2014 at 16:55
  • I tried adding srs:"EPSG:4326" as well as srs:"EPSG:900913" to the Leaflet definitions, but no real success (see updated note in the original question)
    – punkish
    Commented Aug 24, 2014 at 17:49
  • I think we are getting confused here. I am only speaking for Leaflet when I say "create your map". Furthermore, there is no option called srs (in Leaflet). Have you tried creating L.Map object with option crs: L.CRS.EPSG4326 ?
    – YaFred
    Commented Aug 24, 2014 at 18:02
  • You are indeed right; setting "srs" was wrong and pointless. Removed it, and added L.CRS.EPSG4326 to the map definition. Now I get the following error: "An error occurred: can't find resolution index for 0.175781. Available resolutions are: [156543.0339, 78271.51695, 39135.758475, 19567.8792375, 9783.93961875, 4891.969809375, 2445.9849046875, 1222.99245234375, 611.496226171875, 305.7481130859375, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.109257067871095, 9.554628533935547, 4.777314266967774, 2.388657133483887, 1.1943285667419434, 0.5971642833709717, 0.29858214168548586]"
    – punkish
    Commented Aug 24, 2014 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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