繁体   English   中英

无法使用OpenLayers 3显示刻度

[英]Unable to display the graticule with OpenLayers 3

这个问题比OpenLayer更具JavaScript问题。 我猜...

该示例可以在我自己的WMS服务器上正常运行: http : //openlayers.org/en/v3.0.0/examples/graticule.html

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

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”。

我不是Java语言专家,因此可能是一个相对愚蠢的原因。

请帮助,我被困住了。

问题解决了。

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

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

暂无
暂无

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

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