[GIS] OpenLayers 2.11 WMS layer in custom projection

openlayers-2wms

I am using OpenLayers 2.11 from here http://cdnjs.com/libraries/openlayers
and trying to display WMS layer.
It is in 3301 projection so projection is defined as follows:

proj4.defs("EPSG:3301","+proj=lcc +lat_1=59.33333333333334 +lat_2=58 +lat_0=57.51755393055556 +lon_0=24 +x_0=500000 +y_0=6375000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
var projection = new OpenLayers.Projection('EPSG:3301');

and WMS layer and map like this:

 var bounds = new OpenLayers.Bounds(
            370753.1145, 6382922.7769, 739245.6000, 6624811.0577
    );
    var options = {
        maxExtent: bounds,
        maxResolution: 2601.4538070271437,
        projection:projection,
        units: 'm'
    };
    map = new OpenLayers.Map('map', options);
var base  = new OpenLayers.Layer.WMS("Maa/ameti aluskaart",
            "http://kaart.maaamet.ee/wms/alus?",{layers: 'MA-ALUS',
                version: '1.1.1' ,'srs':projection});
map.addLayer(base);

But there are no request at all with 2.11 version of OpenLayers. With OpenLayers 2.12 it is shown, but I am interesting in how to show WMS in older OpenLayers 2.11 version.

Best Answer

just add this js from the cdn:

https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-combined.js

and use following code:

var projection= new OpenLayers.Projection("EPSG:3301");
var bounds = new OpenLayers.Bounds(
            370753.1145, 6382922.7769, 739245.6000, 6624811.0577
    );
    var options = {
        maxExtent: bounds,
        maxResolution: 2601.4538070271437,
        projection:projection,
        units: 'm'
    };
    map = new OpenLayers.Map('map', options);
var base  = new OpenLayers.Layer.WMS("Maa/ameti aluskaart",
            "http://kaart.maaamet.ee/wms/alus?",{layers: 'MA-ALUS',
                version: '1.1.1' ,'srs':projection});
map.addLayer(base);
map.setCenter(new OpenLayers.LonLat(25.567422, 58.885704).transform(new OpenLayers.Projection("EPSG:4326"),projection),2);

see this example: http://jsfiddle.net/expedio/ccp9L6gv/