简体   繁体   English

OpenLayers中的矢量投影

[英]vector projection in OpenLayers

I am building a GIS app in geoDjango with OpenLayers and using data from PostGIS in projection EPSG:3908. 我正在使用OpenLayers在geoDjango中构建GIS应用,并在投影EPSG:3908中使用来自PostGIS的数据。 The base layer is OSM. 基本层是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 OpenLayers和Proj4js文档

When doing transformations, you must check the isReady parameter before calling transform . 进行转换时,必须在调用transform之前检查isReady参数。 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. 因此,定义您的转换对象(4326和900913)并检查它们是否准备就绪,然后执行转换。 If they fail to be ready, explicitly reference the respective Proj4js definition files in your html file. 如果它们没有准备好,请在html文件中显式引用相应的Proj4js定义文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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