cesium-navigation
cesium-navigation copied to clipboard
2D map issue
When I change my map to Cesium.SceneMode.SCENE2D the scale bar vanishes....
What is wrong?
I have a solution.
Go to the method function updateDistanceLegendCesium(viewModel, scene)
and add this code:
function updateDistanceLegendCesium(viewModel, scene) {
var now = getTimestamp();
if (now < viewModel._lastLegendUpdate + 250) {
return
}
viewModel._lastLegendUpdate = now;
var width = scene.canvas.clientWidth;
var height = scene.canvas.clientHeight;
// I've changed from here ...
var p1 = new Cartesian2(width / 2 | 0, height - 1);
var p2 = new Cartesian2(1 + width / 2 | 0, height - 1);
// try to get from a 3D map.
var left = scene.camera.getPickRay( p1 );
var right = scene.camera.getPickRay( p2 );
var globe = scene.globe;
var leftPosition = globe.pick(left, scene);
var rightPosition = globe.pick(right, scene);
if (!defined(leftPosition) || !defined(rightPosition)) {
// It is a 2D map. globe.pick won't work
leftPosition = scene.camera.pickEllipsoid(p1, scene.globe.ellipsoid);
rightPosition = scene.camera.pickEllipsoid(p2, scene.globe.ellipsoid);
}
// ... to here
if (!defined(leftPosition) || !defined(rightPosition)) {
viewModel.barWidth = undefined;
viewModel.distanceLabel = undefined;
return
}
Now it will work both for 3D and 2D map.