Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D map issue #47

Open
icemagno opened this issue Oct 3, 2020 · 1 comment
Open

2D map issue #47

icemagno opened this issue Oct 3, 2020 · 1 comment

Comments

@icemagno
Copy link

icemagno commented Oct 3, 2020

When I change my map to Cesium.SceneMode.SCENE2D the scale bar vanishes....

What is wrong?

@icemagno
Copy link
Author

icemagno commented Oct 3, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant