无法使用 OpenLayers 3 显示格线

Unable to display the graticule with OpenLayers 3

这个问题更像是一个 javascript 问题,而不是 OpenLayer 问题。我猜...

示例在我自己的 WMS 服务器上运行良好:http://openlayers.org/en/v3.0.0/examples/graticule.html

在我的项目中,'map'对象设置在map.js文件中,加载在index.html文件之前graticule.js文件。它会按预期显示地图。

var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    target: 'map',
});

现在我的代码非常简单 graticule.js

"use Strict";
var graticule = new ol.Graticule();
graticule.setMap(map);
map.getViewPort().style.cursor = 'crosshair';

好的,现在是有趣的部分: 我可以看到十字准线(所以地图对象没问题!),但是 setMap(map) 只是在调试控制台中抛出错误 "TypeError : a is null"。

我不是 Javascript 专家,所以这可能是一个相对愚蠢的理由。

请帮忙,我卡住了。

问题已解决。

我在视图属性中使用了ol.proj.Projection,但我需要直接使用字符串投影代码:

var view = new ol.View({
    center: center,
    zoom: 6,
    projection: 'EPSG:4326'
});