Search in sources :

Example 6 with Cartesian3

use of org.cesiumjs.cs.core.Cartesian3 in project gwt-cs by iSergio.

the class CirclePrimitive method getPositions.

public Cartesian3[] getPositions() {
    EllipsePositionsOptions options = new EllipsePositionsOptions();
    options.semiMajorAxis = getRadius();
    options.semiMinorAxis = getRadius();
    options.center = getCenter();
    options.granularity = granularity;
    options.rotation = 0;
    JsObject jsObject = EllipseGeometryLibrary.computeEllipsePositions(options, false, true);
    if (jsObject.getObject("outerPositions") == null) {
        return null;
    }
    List<Cartesian3> positions = new ArrayList<>();
    JsArray<Number> nativePositions = (JsArray<Number>) jsObject.getObject("outerPositions");
    for (int i = 0; i < nativePositions.length(); i += 3) {
        double x = JsObject.getNumber(nativePositions, i).doubleValue();
        double y = JsObject.getNumber(nativePositions, i + 1).doubleValue();
        double z = JsObject.getNumber(nativePositions, i + 2).doubleValue();
        positions.add(new Cartesian3(x, y, z));
    }
    return positions.toArray(new Cartesian3[positions.size()]);
}
Also used : EllipsePositionsOptions(org.cesiumjs.cs.core.options.EllipsePositionsOptions) JsObject(org.cesiumjs.cs.js.JsObject) JsArray(org.cesiumjs.cs.js.JsArray) Cartesian3(org.cesiumjs.cs.core.Cartesian3) ArrayList(java.util.ArrayList)

Example 7 with Cartesian3

use of org.cesiumjs.cs.core.Cartesian3 in project gwt-cs by iSergio.

the class GeoJSONAndTopoJSON method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.getViewer().dataSources().removeAll();
    csVPanel.getViewer().camera.lookAt(Cartesian3.fromDegrees(-98.0, 40.0), new Cartesian3(0.0, -4790000.0, 3930000.0));
    csVPanel.getViewer().camera.lookAtTransform(Matrix4.IDENTITY());
    Button defaultStylingBtn = new Button("Default styling");
    defaultStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson"));
        }
    });
    Button basicStylingBtn = new Button("Basic styling");
    basicStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            reset();
            GeoJsonDataSourceOptions options = new GeoJsonDataSourceOptions();
            options.stroke = Color.HOTPINK();
            options.fill = Color.DEEPPINK().withAlpha(0.5f);
            options.strokeWidth = 3;
            csVPanel.getViewer().dataSources().add(GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson", options));
        }
    });
    Button customStylingBtn = new Button("Custom styling");
    customStylingBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            Math.setRandomNumberSeed(0);
            Promise<GeoJsonDataSource, String> promise = GeoJsonDataSource.load(GWT.getModuleBaseURL() + "SampleData/ne_10m_us_states.topojson");
            promise.then(new Fulfill<GeoJsonDataSource>() {

                @Override
                public void onFulfilled(GeoJsonDataSource dataSource) {
                    reset();
                    csVPanel.getViewer().dataSources().add(dataSource);
                    Entity[] entities = dataSource.entities.values();
                    HashMap<String, Color> colorHash = new HashMap<>();
                    for (int i = 0; i < entities.length; i++) {
                        Entity entity = entities[i];
                        String name = entity.name;
                        Color color = colorHash.get(name);
                        if (color == null) {
                            ColorRandomOptions options = new ColorRandomOptions();
                            options.alpha = 1.0f;
                            color = Color.fromRandom(options);
                            colorHash.put(name, color);
                        }
                        entity.polygon.material = new ColorMaterialProperty(new ConstantProperty<>(color));
                        entity.polygon.outline = new ConstantProperty<>(false);
                        entity.polygon.extrudedHeight = new ConstantProperty<>(JsObject.getObject(entity, "properties").getNumber("Population").doubleValue() / 50.);
                    }
                }
            }, new Reject<String>() {

                @Override
                public void onRejected(String value) {
                    Window.alert(value);
                }
            });
        }
    });
    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setSpacing(5);
    hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    hPanel.add(defaultStylingBtn);
    hPanel.add(basicStylingBtn);
    hPanel.add(customStylingBtn);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(hPanel, 20, 20);
    contentPanel.add(new HTML("<p>Load GeoJSON or TopoJSON data and apply custom styling.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) GeoJsonDataSource(org.cesiumjs.cs.datasources.GeoJsonDataSource) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) Reject(org.cesiumjs.cs.promise.Reject) Cartesian3(org.cesiumjs.cs.core.Cartesian3) ColorRandomOptions(org.cesiumjs.cs.core.options.ColorRandomOptions) GeoJsonDataSourceOptions(org.cesiumjs.cs.datasources.options.GeoJsonDataSourceOptions) Fulfill(org.cesiumjs.cs.promise.Fulfill) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) Color(org.cesiumjs.cs.core.Color) Promise(org.cesiumjs.cs.promise.Promise) ClickHandler(com.google.gwt.event.dom.client.ClickHandler)

Example 8 with Cartesian3

use of org.cesiumjs.cs.core.Cartesian3 in project gwt-cs by iSergio.

the class CameraTutorial method buildPanel.

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();
    csVPanel.addHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            csVPanel.getViewer().canvas().focus();
        }
    }, ClickEvent.getType());
    csVPanel.getViewer().canvas().setAttribute("tabindex", "0");
    csVPanel.getViewer().scene().screenSpaceCameraController().enableRotate = false;
    csVPanel.getViewer().scene().screenSpaceCameraController().enableTranslate = false;
    csVPanel.getViewer().scene().screenSpaceCameraController().enableZoom = false;
    csVPanel.getViewer().scene().screenSpaceCameraController().enableTilt = false;
    csVPanel.getViewer().scene().screenSpaceCameraController().enableLook = false;
    handler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
    handler.setInputAction(new ScreenSpaceEventHandler.Listener<org.cesiumjs.cs.core.events.MouseDownEvent>() {

        @Override
        public void function(org.cesiumjs.cs.core.events.MouseDownEvent event) {
            flags.looking = true;
            mousePosition = startMousePosition = new Cartesian3(event.position.x, event.position.y, 0);
        }
    }, ScreenSpaceEventType.LEFT_DOWN());
    handler.setInputAction(new ScreenSpaceEventHandler.Listener<org.cesiumjs.cs.core.events.MouseMoveEvent>() {

        @Override
        public void function(org.cesiumjs.cs.core.events.MouseMoveEvent event) {
            mousePosition = new Cartesian3(event.endPosition.x, event.endPosition.y, 0);
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
    handler.setInputAction(new ScreenSpaceEventHandler.Listener<org.cesiumjs.cs.core.events.MouseUpEvent>() {

        @Override
        public void function(org.cesiumjs.cs.core.events.MouseUpEvent event) {
            flags.looking = false;
        }
    }, ScreenSpaceEventType.LEFT_UP());
    RootPanel.get().addDomHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent keyDownEvent) {
            setFlag(keyDownEvent.getNativeKeyCode(), true);
        }
    }, KeyDownEvent.getType());
    RootPanel.get().addDomHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent keyUpEvent) {
            setFlag(keyUpEvent.getNativeKeyCode(), false);
        }
    }, KeyUpEvent.getType());
    csVPanel.getViewer().clock().onTick.addEventListener(new Event.Listener() {

        @Override
        public void function(Object... o) {
            org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
            // First element in array is Clock. Check this.
            if (o[0] instanceof Clock) {
                if (flags.looking) {
                    int width = csVPanel.getViewer().canvas().getClientWidth();
                    int height = csVPanel.getViewer().canvas().getClientHeight();
                    // Coordinate (0.0, 0.0) will be where the mouse was clicked.
                    double x = (mousePosition.x - startMousePosition.x) / width;
                    double y = -(mousePosition.y - startMousePosition.y) / height;
                    double lookFactor = 0.05;
                    camera.lookRight(x * lookFactor);
                    camera.lookUp(y * lookFactor);
                }
                // Change movement speed based on the distance of the camera to the surface of the ellipsoid.
                double cameraHeight = csVPanel.getViewer().scene().globe.ellipsoid.cartesianToCartographic(camera.position).height;
                double moveRate = cameraHeight / 100.0;
                if (flags.moveForward) {
                    camera.moveForward(moveRate);
                }
                if (flags.moveBackward) {
                    camera.moveBackward(moveRate);
                }
                if (flags.moveUp) {
                    camera.moveUp(moveRate);
                }
                if (flags.moveDown) {
                    camera.moveDown(moveRate);
                }
                if (flags.moveLeft) {
                    camera.moveLeft(moveRate);
                }
                if (flags.moveRight) {
                    camera.moveRight(moveRate);
                }
            }
        }
    });
    HTML html = new HTML();
    html.setHTML("<div id=\"toolbar\">\n" + "<div>Click on the Cesium display to start.</div>\n" + "<div>w/s - move forward/backward</div>\n" + "<div>a/d - move left/right</div>\n" + "<div>q/e - move up/down</div>\n" + "<div>left mouse button down plus mouse move changes the look direction</div>\n" + "</div>");
    html.getElement().getStyle().setColor("white");
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(html, 20, 20);
    contentPanel.add(new HTML("<p>Use the camera to control the view, and create custom event handlers for input.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) HTML(com.google.gwt.user.client.ui.HTML) Clock(org.cesiumjs.cs.core.Clock) Cartesian3(org.cesiumjs.cs.core.Cartesian3) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ScreenSpaceEventHandler(org.cesiumjs.cs.core.ScreenSpaceEventHandler) Event(org.cesiumjs.cs.core.Event)

Example 9 with Cartesian3

use of org.cesiumjs.cs.core.Cartesian3 in project gwt-cs by iSergio.

the class Models3D method createModel.

private void createModel(String url, double height) {
    csVPanel.getViewer().entities().removeAll();
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(url);
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(128);
    modelGraphicsOptions.maximumScale = new ConstantProperty<>(20000);
    ModelGraphics modelGraphics = new ModelGraphics(modelGraphicsOptions);
    Cartesian3 position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
    double heading = Math.toRadians(135);
    double pitch = 0;
    double roll = 0;
    Quaternion orientation = Transforms.headingPitchRollQuaternion(position, new org.cesiumjs.cs.core.HeadingPitchRoll(heading, pitch, roll));
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.name = url;
    entityOptions.position = new ConstantPositionProperty(position);
    entityOptions.orientation = new ConstantProperty<>(orientation);
    entityOptions.model = modelGraphics;
    csVPanel.getViewer().trackedEntity = csVPanel.getViewer().entities().add(entityOptions);
    ;
}
Also used : ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) Cartesian3(org.cesiumjs.cs.core.Cartesian3) Quaternion(org.cesiumjs.cs.core.Quaternion) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions)

Example 10 with Cartesian3

use of org.cesiumjs.cs.core.Cartesian3 in project gwt-cs by iSergio.

the class Tiles3DFeaturePicking method buildPanel.

@Override
public void buildPanel() {
    final ViewerPanel csVPanel = new ViewerPanel();
    nameOverlay = RootPanel.get().getElement().getOwnerDocument().createDivElement();
    csVPanel.getViewer().container().appendChild(nameOverlay);
    nameOverlay.setClassName("backdrop");
    nameOverlay.getStyle().setDisplay(Style.Display.NONE);
    nameOverlay.getStyle().setPosition(Style.Position.ABSOLUTE);
    nameOverlay.getStyle().setBottom(0, Style.Unit.PX);
    nameOverlay.getStyle().setLeft(0, Style.Unit.PX);
    // nameOverlay.style['pointer-events'] = 'none';
    nameOverlay.getStyle().setPadding(4, Style.Unit.PX);
    nameOverlay.getStyle().setBackgroundColor("black");
    Cartesian3 initialPosition = Cartesian3.fromDegrees(-74.01881302800248, 40.69114333714821, 753);
    org.cesiumjs.cs.core.HeadingPitchRoll initialOrientation = org.cesiumjs.cs.core.HeadingPitchRoll.fromDegrees(21.27879878293835, -21.34390550872461, 0.0716951918898415);
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.destinationPos = initialPosition;
    viewOptions.orientation = initialOrientation;
    viewOptions.endTransform = Matrix4.IDENTITY();
    csVPanel.getViewer().scene().camera().setView(viewOptions);
    // Load the NYC buildings tileset
    Cesium3DTileset tileset = (Cesium3DTileset) csVPanel.getViewer().scene().primitives().add(Cesium3DTileset.create("https://beta.cesium.com/api/assets/1461?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWJmM2MzNS02OWM5LTQ3OWItYjEyYS0xZmNlODM5ZDNkMTYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjFdLCJpYXQiOjE0OTkyNjQ3NDN9.vuR75SqPDKcggvUrG_vpx0Av02jdiAxnnB1fNf-9f7s"));
    csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            MouseMoveEvent movement = (MouseMoveEvent) event;
            // If a feature was previously highlighted, undo the highlight
            if (Cesium.defined(highlighted.feature)) {
                highlighted.feature.color = highlighted.originalColor;
                highlighted.feature = (Cesium3DTileFeature) JsObject.undefined();
            }
            // Pick a new feature
            Cesium3DTileFeature pickedFeature = (Cesium3DTileFeature) csVPanel.getViewer().scene().pick(movement.endPosition);
            if (!Cesium.defined(pickedFeature)) {
                nameOverlay.getStyle().setDisplay(Style.Display.NONE);
                return;
            }
            // A feature was picked, so show it's overlay content
            nameOverlay.getStyle().setDisplay(Style.Display.BLOCK);
            nameOverlay.getStyle().setBottom(csVPanel.getViewer().canvas().getClientHeight() - movement.endPosition.y + 26, Style.Unit.PX);
            nameOverlay.getStyle().setLeft(movement.endPosition.x + 26, Style.Unit.PX);
            String name = pickedFeature.getProperty("name").toString();
            if (!Cesium.defined(name)) {
                name = pickedFeature.getProperty("id").toString();
            }
            nameOverlay.setInnerHTML("<font color=\"white\">" + name + "</font>");
            // Highlight the feature if it's not already selected.
            if (!pickedFeature.equals(selected.feature)) {
                highlighted.feature = pickedFeature;
                Color.clone(pickedFeature.color, highlighted.originalColor);
                pickedFeature.color = Color.YELLOW();
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
    final Function clickHandler = csVPanel.getViewer().screenSpaceEventHandler().getInputAction(ScreenSpaceEventType.LEFT_CLICK());
    csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            MouseClickEvent movement = (MouseClickEvent) event;
            // If a feature was previously selected, undo the highlight
            if (Cesium.defined(selected.feature)) {
                selected.feature.color = selected.originalColor;
                selected.feature = (Cesium3DTileFeature) JsObject.undefined();
            }
            // Pick a new feature
            Cesium3DTileFeature pickedFeature = (Cesium3DTileFeature) csVPanel.getViewer().scene().pick(movement.position);
            if (!Cesium.defined(pickedFeature)) {
                GWT.log("undefined");
                clickHandler.exec();
                return;
            }
            // Select the feature if it's not already selected
            if (selected.feature == pickedFeature) {
                return;
            }
            selected.feature = pickedFeature;
            // Save the selected feature's original color
            if (pickedFeature == highlighted.feature) {
                Color.clone(highlighted.originalColor, selected.originalColor);
                highlighted.feature = (Cesium3DTileFeature) JsObject.undefined();
            } else {
                Color.clone(pickedFeature.color, selected.originalColor);
            }
            // Highlight newly selected feature
            pickedFeature.color = Color.LIME();
            // Set feature infobox description
            String featureName = pickedFeature.getProperty("name").toString();
            selectedEntity.name = featureName;
            selectedEntity.description = new ConstantProperty<>("Loading <div class=\"cesium-infoBox-loading\"></div>");
            csVPanel.getViewer().selectedEntity = selectedEntity;
            selectedEntity.description = new ConstantProperty<>("<table class=\"cesium-infoBox-defaultTable\"><tbody>" + "<tr><th>BIN</th><td>" + pickedFeature.getProperty("BIN").toString() + "</td></tr>" + "<tr><th>DOITT ID</th><td>" + pickedFeature.getProperty("DOITT_ID").toString() + "</td></tr>" + "<tr><th>SOURCE ID</th><td>" + pickedFeature.getProperty("SOURCE_ID").toString() + "</td></tr>" + "</tbody></table>");
        }
    }, ScreenSpaceEventType.LEFT_CLICK());
    contentPanel.add(new HTML("<p>Pick features in a 3D Tiles tileset.</p>"));
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) Cesium3DTileFeature(org.cesiumjs.cs.scene.Cesium3DTileFeature) ViewOptions(org.cesiumjs.cs.scene.options.ViewOptions) HTML(com.google.gwt.user.client.ui.HTML) ScreenSpaceEventHandler(org.cesiumjs.cs.core.ScreenSpaceEventHandler) Cesium3DTileset(org.cesiumjs.cs.scene.Cesium3DTileset) Function(org.cesiumjs.cs.promise.Function) Cartesian3(org.cesiumjs.cs.core.Cartesian3) JsObject(org.cesiumjs.cs.js.JsObject) MouseClickEvent(org.cesiumjs.cs.core.events.MouseClickEvent)

Aggregations

Cartesian3 (org.cesiumjs.cs.core.Cartesian3)10 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)7 HTML (com.google.gwt.user.client.ui.HTML)5 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)4 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)4 Entity (org.cesiumjs.cs.datasources.Entity)3 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)3 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)3 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)3 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)2 Quaternion (org.cesiumjs.cs.core.Quaternion)2 ScreenSpaceEventHandler (org.cesiumjs.cs.core.ScreenSpaceEventHandler)2 EllipsoidGraphics (org.cesiumjs.cs.datasources.graphics.EllipsoidGraphics)2 EllipsoidGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.EllipsoidGraphicsOptions)2 JsObject (org.cesiumjs.cs.js.JsObject)2 ViewOptions (org.cesiumjs.cs.scene.options.ViewOptions)2 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)2