I need to run Graticule labels in OpenLayers 3 . 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
But I cant get it works in my 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). See OL3 API reference here: 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. See OL5 API reference here: https://openlayers.org/en/latest/apidoc/module-ol_Graticule.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.