簡體   English   中英

我無法將幾何轉換為openlayers 5.3中proj4.defs中定義的投影

[英]I can't transform geometries to a projection defined in proj4.defs in openlayers 5.3

我有一個使用openlayers V5.3.0的節點映射應用程序。 當我嘗試將幾何從EPSG:4326轉換為使用proj4.defs定義的投影時,我收到以下錯誤消息:TypeError:無法讀取null的屬性'getCode'

如果我將openLayers更改為4.6.4版,則轉換幾何的代碼可以正常工作。

還有其他人遇到過這個問題嗎?

以下HTML演示了此問題。

<html>
<head>
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
    <title>Projection Test</title>

    <script
            src="https://code.jquery.com/jquery-2.2.4.min.js"
            integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
            crossorigin="anonymous"></script>

   <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.4/ol-debug.js"></script> -->

    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>


    <script>proj4.defs("EPSG:28355","+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");</script>

     <script>

         $(document).ready(function() {
             let gJSONOpts = {
                 dataProjection: "EPSG:3857",
                 featureProjection: "EPSG:28355"
             };

             let jsonPt = {
                 "type": "Feature",
                 "id": "GEO_BRM_STOPS.fid--79f50be5_16adc4d0ce7_6a6b",
                 "geometry": {
                     "type": "Point",
                     "coordinates": [16154413.50099648, -4988654.4460995]
                 },
                 "geometry_name": "OBJ"
             };

             let feature = new ol.format.GeoJSON().readFeature(jsonPt.geometry, gJSONOpts);
             let tg = feature.getGeometry().transform('EPSG:28355', "EPSG:4326");
             let out = 'Projected Coordinates: ' + tg.getCoordinates()[0] + ', ' +tg.getCoordinates()[1];

             $("#mapvwr").html(out);

         });
     </script>
</head>
<body>
    <div id="mapvwr">

    </div>
</body>
</html>

將上述內容粘貼到html文件中並在瀏覽器中顯示。

取消注釋這一行:

 <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/4.6.4/ol-debug.js"></script> -->

並注釋掉以下行:

<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>

要查看正確的結果:

Projected Coordinates: 145.11756553931886, -40.83921285742692

我發現了這個問題。 我需要將其添加為腳本ol.proj.proj4.register(proj4); 在我定義了投影之后。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM