[OpenLayers-Users] How to use Other Projections in a stand alone client side environment

Subhani Minhas subhaniminhas at gmail.com
Tue Jul 20 10:23:10 EDT 2010


Hello All, I recently came across, the site
http://spatialreference.org/ref/epsg/24378/  which can show coordinates of
projection EPSG:24378 once we click on the map, I am interested to put the
same functionality on my locally hosted html file and perform the coordinate
calculation client side, i.e no server side calculations from
http://spatialreference.org   . The code referred was map.js in the HTML
file which is as follows:

function init(code) {
    m = new OpenLayers.Map('map', {'maxResolution': 360/512});
    m.addLayer(new OpenLayers.Layer.WMS('',
'http://labs.metacarta.com/wms-c/Basic.py', {'layers':'basic'}));
    m.addLayer(new OpenLayers.Layer.Markers(''));
    m.zoomToMaxExtent();
    m.marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0));
    m.layers[1].addMarker(m.marker);
    if (window.bounds) {
    m.addLayer(new OpenLayers.Layer.Boxes());
    m.layers[2].addMarker(new OpenLayers.Marker.Box(bounds));
    }
    m.events.register('moveend', m, function() {
        var c = this.getCenter();
        this.marker.moveTo(this.getLayerPxFromLonLat(c));
        document.getElementById("out").innerHTML = "Waiting...";
        document.getElementById("in").innerHTML = [c.lon,c.lat].join(", ");
        var json = '{"type":"Feature", "geometry":{"type":"Point",
"coordinates":[' + c.lon + ', '+ c.lat + ']},"properties":{}}';
        var s = document.createElement("script");
        s.src = "/projection/?json=" + escape(json) +
"&inref=EPSG:4326&outref="+code+"&callback=project_out"
        document.body.appendChild(s);
    });
    if (window.bounds) {
        m.setCenter(bounds.getCenterLonLat());
    } else {
        m.zoomToMaxExtent();
    }
}
function project_out(data) {
    if (data.coordinates) {
      document.getElementById("out").innerHTML = data.coordinates.join(", ");
    } else if (data.error) {
        if (window.console) {
            console.log(data.error);
        }
        document.getElementById('out').innerHTML = 'An error occurred.';
    }
}

while the html only has following script:

var bounds = new OpenLayers.Bounds(70.329999999999998, 28.0,
97.450000000000003, 35.549999999999997);

defining bounds of this specific projection:

How can i use this code locally, i want to place it in e.g examples
folder of OL 2.9 source, and make it work, but the projection
information is missing which is as follows in WKT:
PROJCS["Kalianpur 1975 / India zone I",
    GEOGCS["Kalianpur 1975",
        DATUM["Kalianpur_1975",
            SPHEROID["Everest 1830 (1975 Definition)",6377299.151,300.8017255,
                AUTHORITY["EPSG","7045"]],
            TOWGS84[295,736,257,0,0,0,0],
            AUTHORITY["EPSG","6146"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.01745329251994328,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4146"]],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    PROJECTION["Lambert_Conformal_Conic_1SP"],
    PARAMETER["latitude_of_origin",32.5],
    PARAMETER["central_meridian",68],
    PARAMETER["scale_factor",0.99878641],
    PARAMETER["false_easting",2743195.5],
    PARAMETER["false_northing",914398.5],
    AUTHORITY["EPSG","24378"],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH]]
.

Any help or source code will be highly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100720/38ebb661/attachment.html


More information about the Users mailing list