简体   繁体   English

如何在OpenLayers 3中运行Graticule标签?

[英]How to run Graticule labels in OpenLayers 3?

I need to run Graticule labels in OpenLayers 3 . 我需要在OpenLayers 3中运行Graticule 标签 I want to show and style labels of graticule with angle units. 我想用角度单位显示和标记刻度标签。 I just found this : 我刚发现这个:

https://github.com/Brictarus/ol3/blob/d41eb87204e76cbf99d61915eb89b1c16c4a4e05/examples/graticule.js https://github.com/Brictarus/ol3/blob/d41eb87204e76cbf99d61915eb89b1c16c4a4e05/examples/graticule.js

But I cant get it works in my html : 但我无法在我的HTML中使用它:

var polohaMysky = new ol.control.MousePosition({
  coordinateFormat: ol.coordinate.createStringXY(4),
  //projection: "EPSG:4326",
  className: "suradnice",
  target: document.getElementById("suradnice_div"),
                undefinedHTML: '0000'
})
            //------//
            var mierka = new ol.control.ScaleLine();
            var nahlad = new ol.control.OverviewMap();
            var a1 = new ol.source.OSM();
      var map = new ol.Map({
        renderer: 'canvas',
          // Zobrazenie súradníc myšky
        controls: ol.control.defaults({
            attributions: false
        }).extend([polohaMysky, mierka, nahlad]),
        layers: [
          new ol.layer.Tile({
            source: a1
          })
        ],
        target: 'map',
        view: new ol.View({
            //projection: 'EPSG:4326',
            center: ol.proj.fromLonLat([4.8, 47.75]),
          zoom: 3
        })
      });
           var lonFormatter = function(lon) {
  var formattedLon = Math.abs(Math.round(lon * 100) / 100);
  formattedLon += (lon < 0) ? 'W' : ((lon > 0) ? 'E' : '');
  return formattedLon;
};

var latFormatter = function(lat) {
  var formattedLat = Math.abs(Math.round(lat * 100) / 100);
  formattedLat += (lat < 0) ? 'S' : ((lat > 0) ? 'N' : '');
  return formattedLat;
};

// Create the graticule component
var graticule = new ol.Graticule({
  // the style to use for the lines, optional.
  strokeStyle: new ol.style.Stroke({
    color: 'rgba(255,120,0,0.9)',
    width: 2,
    lineDash: [0.5, 4]
  }),
  showLabels: true,
  lonLabelFormatter: lonFormatter,
  lonLabelPosition: 0.05,
  latLabelFormatter: latFormatter,
  latLabelPosition: 0.95
});
graticule.setMap(map);

When i run this code i just see only graticule without labels. 当我运行此代码时,我只看到没有标签的刻度。 Have you any idea what is wrong ? 你知道什么是错的吗? Thanks for any help . 谢谢你的帮助

最新文档来看,似乎OL3还不支持标签

Graticule labels are not supported in OpenLayers 3 (latest version of OL3 is 3.20.1). OpenLayers 3不支持经纬网标签(最新版本的OL3为3.20.1)。 See OL3 API reference here: https://openlayers.org/en/v3.20.1/apidoc/ol.Graticule.html 请参阅此处的OL3 API参考: https//openlayers.org/en/v3.20.1/apidoc/ol.Graticule.html

If you need to display graticule labels consider upgrading to OpenLayers 5, which does support graticule labels. 如果需要显示刻度标签,请考虑升级到OpenLayers 5,它支持刻度标签。 See OL5 API reference here: https://openlayers.org/en/latest/apidoc/module-ol_Graticule.html 请参阅此处的OL5 API参考: https ://openlayers.org/en/latest/apidoc/module-ol_Graticule.html

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

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