CloudMade/Leaflet — Issue #422: Create a new Layer based on WMS
Author: kokoni
Created: 2012-01-06 15:18:51+00:00
State: open

Hi,

I'm working on a new Leaflet layer. The source is a WMS server from IGN, a french organization. They provide us an OpenLayer kit, but I prefer to use Leaflet.

I need to add an extra option called gppkey, which is a validation key -provided by IGN) based on time and referer header.
I got the gppkey value, that's not my problem.

So I've created a new class called L.TileLayer.IGN which extend L.TileLayer.
I have added all the options I need to build the url.

But when I add the layer to the map, nothing happend. I use fiddler2 to see what I send to server, but nothing appears again.
When I switch to a cloudmade layer (from sample), all is fine and fiddler2 says ok too (with the good url).

So, my question is do I need to do something else to create a new L.TileLayer ? Or is there an other solution to use IGN layer ?

Here is my new class :
-----------------------------------------------------------------------------------------
L.TileLayer.IGN = L.TileLayer.WMS.extend({
defaultWmsParams: {
layers: "",
exceptions: "text/xml",
format: "image/jpeg",
service: "WMS",
version: "1.1.1",
request: "GetMap",
styles: "",
srs: "IGNF:GEOPORTALFXX",
width: "256",
height: "256",
tiled: "true",
gppkey: ""
},
initialize: function (a, b) {
this._url = a,
this.wmsParams = L.Util.extend({},this.defaultWmsParams),
//this.wmsParams.width = this.wmsParams.height = this.options.tileSize;

//for (var c in b)
//	this.options.hasOwnProperty(c) || (this.wmsParams[c] = b[c]);

L.Util.setOptions(this, b)
},
onAdd: function (a) {
//var b = parseFloat(this.wmsParams.version) < 1.3 ? "srs" : "crs";
//this.wmsParams[b] = a.options.crs.code, L.TileLayer.prototype.onAdd.call(this, a)
},
getTileUrl: function (a, b) {
var c = this.options.tileSize,
d = a.multiplyBy(c),
e = d.add(new L.Point(c, c)),
f = this._map.unproject(d, this._zoom, !0),
g = this._map.unproject(e, this._zoom, !0),
h = this._map.options.crs.project(f),
i = this._map.options.crs.project(g),
j = [h.x, i.y, i.x, h.y].join(",");
return this._url + L.Util.getParamString(this.wmsParams) + "&bbox=" + j
}
});
-----------------------------------------------------------------------------------------

Thanks in advance.