简体   繁体   English

无法在OpenLayers中使用特定的投影

[英]Can't use specific projection with OpenLayers

I'd like to use specific projection with OpenLayers. 我想对OpenLayers使用特定的投影。 I linked proj4js with my html 我将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>

and added new projection: 并添加了新的预测:

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

But reprojection doesn't work, I get NaN values. 但是重新投影不起作用,我得到了NaN值。 Here is code.js: 这是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);
}

The problem has been resolved. 这个问题已经解决。 I was given with bad projection string (some parameters were missed). 给我一个不好的投影字符串(错过了一些参数)。 Instead of using 而不是使用

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

I should have used 我应该用过

+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 + 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 +单位= m + no_defs

But it is curious that C version of Proj4 works perfectly with the fist string also. 但奇怪的是,Proj4的C版本也可以与第一弦完美配合。

Thanks to John Barça for help. 感谢JohnBarça的帮助。

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

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