简体   繁体   中英

vector projection in OpenLayers

I am building a GIS app in geoDjango with OpenLayers and using data from PostGIS in projection EPSG:3908. The base layer is OSM. When I add vector data I got it rendered near Brazil instead of Bosnia. I tried everything but just can't get the solution.

Please can anyone help?

var map, osm, google, kml;
function init(){

        map = new OpenLayers.Map('map');

        map.addControl(new OpenLayers.Control.LayerSwitcher());

        var osm = new OpenLayers.Layer.OSM(
            "OSM");

        kml = new OpenLayers.Layer.GML("KML", upit, 
           {format: OpenLayers.Format.KML,
            projection: new OpenLayers.Projection("EPSG:3908")});

        map.addLayers([osm, kml]);

        map.zoomToExtent(
           new OpenLayers.Bounds(15.774414, 42.6, 19.662109, 45.2).transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913")));

OpenLayers and Proj4js doc

When doing transformations, you must check the isReady parameter before calling transform . This is because you must ensure that the definitions of your projections are loaded.

So define your transformation objects (4326 and 900913) and check if they are ready, then perform the transformation. If they fail to be ready, explicitly reference the respective Proj4js definition files in your html file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM