Limit movements area

1,202 views
Skip to first unread message

Tamy

unread,
Jul 23, 2013, 3:38:10 PM7/23/13
to cesiu...@googlegroups.com
Hi,

I need to limit the area that the user can move and zoom the map to an extent.  
The user can't see out of the extent. Is it possible? How can I do that?

Thanks!

Matthew Amato

unread,
Jul 25, 2013, 9:38:57 AM7/25/13
to cesiu...@googlegroups.com
Do you want to limit the viewable area on the screen (where the camera can look) or simply limit the camera position (the area the camera can be.).  In 2D, this are almost the same thing, but they are completely different in 3D and Columbus View.


--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tamy

unread,
Jul 25, 2013, 9:49:44 AM7/25/13
to cesiu...@googlegroups.com
I want to limit the viewable area on the screen. And I need it just for 2D.

Matthew Amato

unread,
Jul 25, 2013, 12:47:10 PM7/25/13
to cesiu...@googlegroups.com
I was curious, so I threw this together.

Go to http://cesium.agi.com/Cesium/Apps/Sandcastle/index.html?src=Cesium%20Viewer%20Widget.html  and paste the below code.  When you switch to 2D mode, you should have what you want.  I shut inertia off because it created some unpleasant jumpiness along the edges.  This isn't perfect, and it only works for 2D, but it should get you started.

require(['Cesium'], function(Cesium) {
    "use strict";

    var viewer = new Cesium.Viewer('cesiumContainer');

    //Set up the max extent.
    var west = Cesium.Math.toRadians(-77.0);
    var south = Cesium.Math.toRadians(38.0);
    var east = Cesium.Math.toRadians(-72.0);
    var north = Cesium.Math.toRadians(42.0);
    var maxExtent = new Cesium.Extent(west, south, east, north);

    viewer.scene.getScreenSpaceCameraController().inertiaTranslate = 0;
    viewer.clock.onTick.addEventListener(function() {
        if (viewer.scene.mode === Cesium.SceneMode.SCENE2D) {
            var topLeft = viewer.scene.getCamera().controller.pickEllipsoid(new Cesium.Cartesian2(0, 0));
            var topRight = viewer.scene.getCamera().controller.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth, 0));
            var bottomLeft = viewer.scene.getCamera().controller.pickEllipsoid(new Cesium.Cartesian2(0, viewer.canvas.clientHeight));
            var bottomRight = viewer.scene.getCamera().controller.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth, viewer.canvas.clientHeight));
            if (topLeft && topRight && bottomLeft && bottomRight) {
                topLeft = Cesium.Ellipsoid.WGS84.cartesianToCartographic(topLeft);
                topRight = Cesium.Ellipsoid.WGS84.cartesianToCartographic(topRight);
                bottomLeft = Cesium.Ellipsoid.WGS84.cartesianToCartographic(bottomLeft);
                bottomRight = Cesium.Ellipsoid.WGS84.cartesianToCartographic(bottomRight);
                var visibleExtent = Cesium.Extent.fromCartographicArray([topLeft, topRight, bottomLeft, bottomRight]);
                if (!maxExtent.contains(visibleExtent)) {
                    var validExtent = visibleExtent.intersectWith(maxExtent);
                    viewer.scene.getCamera().controller.viewExtent(validExtent, Cesium.Ellipsoid.WGS84);
                }
            } else {
                viewer.scene.getCamera().controller.viewExtent(maxExtent, Cesium.Ellipsoid.WGS84);
            }
        }
    });
    
    
    Sandcastle.finishedLoading();
});



On Thu, Jul 25, 2013 at 9:49 AM, Tamy <su_t...@hotmail.com> wrote:
I want to limit the viewable area on the screen. And I need it just for 2D.

--
Message has been deleted

ayazta...@gmail.com

unread,
Apr 4, 2020, 5:32:37 PM4/4/20
to cesium-dev
can you plz give me the sandcastle code working in 3d mode.
i want the same thing  "limit the viewable area" in 3d mode

above code is giving some error
Uncaught TypeError: Cesium.Extent is not a constructor (on line 14)
in this line
var maxExtent = new Cesium.Extent(west, south, east, north);

To unsubscribe from this group and stop receiving emails from it, send an email to cesiu...@googlegroups.com.

Omar Shehata

unread,
May 4, 2020, 2:39:26 PM5/4/20
to cesium-dev
Heads up that the forum has transitioned over to Discourse and this Google Group will be put into read-only mode today. Details about the transition here.
Reply all
Reply to author
Forward
0 new messages