【问题标题】:Can't use specific projection with OpenLayers不能使用 OpenLayers 的特定投影
【发布时间】:2014-07-21 12:11:00
【问题描述】:

我想在 OpenLayers 中使用特定的投影。我将 proj4js 与我的 html 链接

<html>
  <head>
    <title>OpenLayers Test</title>
    <style type="text/css">
            #map {
                width: 600px;
                height: 300px;
                border: 1px solid black;
                float:left;
            }
        </style>
    <script type="text/javascript" src="http://svn.osgeo.org/metacrs/proj4js/trunk/lib/proj4js-compressed.js"></script>
    <script type="text/javascript" src="OpenLayers.js"></script>
    <script type="text/javascript" src="code.js"></script>
    <link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
  </head>

  <body onload="init()">
    <div id=map>
    </div>
    <div id=map_coord></div>
    <div id=lonlat></div>
  </body>
</html>

并添加了新的投影:

Proj4js.defs["EPSG:987654"] = "+proj=eqdc +lat_1=46.4 +lat_2=71.8 +lon_0=100 +ellps=krass +units=m +no_defs";

但是重投影不起作用,我得到 NaN 值。这是code.js:

Proj4js.defs["EPSG:987654"] = "+proj=eqdc +lat_1=46.4 +lat_2=71.8 +lon_0=100 +ellps=krass +units=m +no_defs";

var map;

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: {
    'single': true,
    'double': false,
    'pixelTolerance': 0,
    'stopSingle': false,
    'stopDouble': false
    },

    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(
            {}, this.defaultHandlerOptions
        );
        OpenLayers.Control.prototype.initialize.apply(
            this, arguments
        );

        this.handler = new OpenLayers.Handler.Click(
            this, {
                'click': this.trigger
            }, this.handlerOptions
        );
     },

    trigger: function(e) {
        var mapcoord = map.getLonLatFromPixel(e.xy);
        mapcoord.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:987654"));
        alert(mapcoord);
   }

});

function init()
{

    map = new OpenLayers.Map('map',
        {
            controls: [
              new OpenLayers.Control.MousePosition ({
                div: document.getElementById("map_coord")
              }),
              new OpenLayers.Control.MousePosition ({
                div: document.getElementById("lonlat"),
                displayProjection: new OpenLayers.Projection('EPSG:4326')
              })
            ],
            units: "m",
            projection: "EPSG:987654",
            maxExtent: new OpenLayers.Bounds(-5000000, 4400000, 4000000, 10000000)
        }
    );

    var ltopo = new OpenLayers.Layer.WMS("topo", "http://ows.mgs.geosys.ru/topo/base",
            { layers: "topo_land,world_ocean,topo_base,elev,vegt,lcov,phys,bath,hyps,dnet_pg,pplc_pg,dnet_pt,hydr,clmk,infr"}
        );

   map.addLayers([ltopo]);
   var click = new OpenLayers.Control.Click();
   map.addControl(click);
   click.activate();

   map.zoomTo(3);
}

【问题讨论】:

  • 那是您创建的投影,不是吗?您能否添加一对源和目标 (4326) 的坐标对以及您希望看到的内容,以便我们可以使用 proj4js 进行尝试,我怀疑这可能是问题所在。
  • -4481368.53 6317117.12 43d19'0.902"E 38d55'35.034"N -5724363.14 5844144.14 38d54'46.852"E 27d35'9.783"N
  • 转换方法是 tranfrom(from, to, method) 并且您将 EPSG:987654 作为地图投影,所以我认为进行转换的线应该是这样的:mapcoord.transform(新的 OpenLayers.Projection("EPSG:987654"), 新的 OpenLayers.Projection("EPSG:4326"));它仍然坏了,但我是对的吗?
  • 是的,你是对的,我在转换方法调用中混合了源和目标投影。但它仍然不起作用,返回 (NaN, NaN)。所以看来proj4js中的错误。
  • 是的,我认为这与 OpenLayers 无关。直接在 proj4js 中调试会更容易,这就是我要求样本点和预期输出的原因。

标签: openlayers projection proj4js


【解决方案1】:

问题已解决。我得到了错误的投影字符串(错过了一些参数)。 而不是使用

+proj=eqdc +lat_1=46.4 +lat_2=71.8 +lon_0=100 +ellps=krass +units=m +no_defs

我应该用过

+proj=eqdc +lon_0=100 +lat_0=0 +x_0=0 +y_0=0 +lat_1=46.4 +lat_2=71.8 +towgs84=0,0,0,0,0,0,0 +ellps= krass +units=m +no_defs

但奇怪的是,Proj4 的 C 版本也可以完美地与第一个字符串配合使用。

感谢约翰·巴萨的帮助。

【讨论】:

    猜你喜欢
    • 2021-02-19
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    相关资源
    最近更新 更多