简体   繁体   English

为什么我不能在极坐标立体图中添加刻度? (OpenLayers 4)

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

I'm working on a map in OpenLayers 4 with projection EPSG:32661 我正在使用投影EPSG:32661在OpenLayers 4中处理地图

This is the JavaScript, which targets a #map div on the page: 这是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);

This CodePen demonstrates the problem I'm having. 该CodePen演示了我遇到的问题。 Commenting out the final line, which is the line that attaches the graticule to the map, causes the map to render normally. 注释掉最后一行,即将标线附加到地图的那一行,会使地图正常渲染。 Running the code with that line in causes the following error: 在该行中运行代码会导致以下错误:

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)

It's my understanding that proj4 automatically generates the transformation functions. 据我了解,proj4自动生成转换函数。 Transforming points or feature layers has been successful, so as far as I can tell, the graticule is the only thing causing trouble. 转换点或要素图层已成功完成,据我所知,方格线是唯一会引起麻烦的事情。

该错误是由于未定义worldExtent引起的,对此进行设置可以解决该问题

north_stereo.setWorldExtent([...]);

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

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