簡體   English   中英

為什么我不能在極坐標立體圖中添加刻度? (OpenLayers 4)

[英]Why can't I add graticule to my polar stereo map? (OpenLayers 4)

我正在使用投影EPSG:32661在OpenLayers 4中處理地圖

這是JavaScript,其目標是頁面上的#map div:

proj4.defs('EPSG:32661', '+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 
+a=3396190 +b=3376200 +units=m +no_defs');
var north_stereo = ol.proj.get('EPSG:32661');
north_stereo.setExtent([-2357032, -2357032, 2357032, 2357032]);
var npoleURL = "https://planetarymaps.usgs.gov/cgi-bin/mapserv? 
map=/maps/mars/mars_npole.map";

var np = new ol.layer.Tile({
    title: 'North Pole',
    source: new ol.source.TileWMS({
        url: npoleURL,
        params: {LAYERS: 'MOLA_color_north'}
    }),
    projection: north_stereo,
});

var map = new ol.Map({
    layers: [
        np
    ],
target: 'map',
view: new ol.View({
    projection: north_stereo,
    center: [0, 0],
    zoom: 4
  })
});
var graticule = new ol.Graticule({
    strokeStyle: new ol.style.Stroke({
        color: 'rgba(0,0,0,0.8)',
        width: 1,
    }),
});
graticule.setMap(map);

該CodePen演示了我遇到的問題。 注釋掉最后一行,即將標線附加到地圖的那一行,會使地圖正常渲染。 在該行中運行代碼會導致以下錯誤:

Uncaught TypeError: Cannot read property '0' of null
at Object.ol.extent.applyTransform (ol-debug.js:4719)
at Object.ol.proj.transformExtent (ol-debug.js:6268)
at ol.Graticule.updateProjectionInfo_ (ol-debug.js:57921)
at ol.Graticule.handlePostCompose_ (ol-debug.js:57876)
at ol.Map.boundListener (ol-debug.js:7277)
at ol.Map.ol.events.EventTarget.dispatchEvent (ol-debug.js:7697)
at ol.renderer.canvas.Map.dispatchComposeEvent_ (ol-debug.js:26392)
at ol.renderer.canvas.Map.renderFrame (ol-debug.js:26480)
at ol.Map.ol.PluggableMap.renderFrame_ (ol-debug.js:18709)
at ol.Map.<anonymous> (ol-debug.js:17624)

據我了解,proj4自動生成轉換函數。 轉換點或要素圖層已成功完成,據我所知,方格線是唯一會引起麻煩的事情。

該錯誤是由於未定義worldExtent引起的,對此進行設置可以解決該問題

north_stereo.setWorldExtent([...]);

暫無
暫無

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

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