Search in sources :

Example 6 with ColorMaterialProperty

use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty in project gwt-cs by iSergio.

the class Tiles3DClippingPlanes method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.skyAtmosphere = null;
    viewerOptions.infoBox = false;
    viewerOptions.selectionIndicator = false;
    csVPanel = new ViewerPanel(viewerOptions);
    ScreenSpaceEventHandler downHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
    downHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            MouseDownEvent mouseDownEvent = (MouseDownEvent) event;
            PickedObject pickedObject = csVPanel.getViewer().scene().pick(mouseDownEvent.position);
            if (!Cesium.defined(pickedObject)) {
                return;
            }
            if (!(pickedObject.id instanceof Entity)) {
                return;
            }
            if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id) && Cesium.defined(((Entity) pickedObject.id).plane)) {
                selectedPlane = ((Entity) pickedObject.id).plane;
                selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.05f));
                selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
                csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = false;
            }
        }
    }, ScreenSpaceEventType.LEFT_DOWN());
    ScreenSpaceEventHandler upHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
    upHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            if (Cesium.defined(selectedPlane)) {
                selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
                selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
                selectedPlane = (PlaneGraphics) JsObject.undefined();
            }
            csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = true;
        }
    }, ScreenSpaceEventType.LEFT_UP());
    ScreenSpaceEventHandler moveHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().scene().canvas());
    moveHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            if (Cesium.defined(selectedPlane)) {
                MouseMoveEvent mouseMoveEvent = (MouseMoveEvent) event;
                double deltaY = mouseMoveEvent.startPosition.y - mouseMoveEvent.endPosition.y;
                targetY += deltaY;
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
    ListBox clipObjectLBox = new ListBox();
    clipObjectLBox.addItem("BIM");
    clipObjectLBox.addItem("Point Cloud");
    clipObjectLBox.addItem("Instanced");
    clipObjectLBox.addItem("Model");
    clipObjectLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            reset();
            ListBox source = (ListBox) event.getSource();
            switch(source.getSelectedIndex()) {
                case 0:
                    loadTileset(bimUrl);
                    break;
                case 1:
                    loadTileset(pointCloudUrl);
                    tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {

                        @Override
                        public void onFulfilled(Cesium3DTileset value) {
                            tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
                        }
                    });
                    break;
                case 2:
                    loadTileset(instancedUrl);
                    tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {

                        @Override
                        public void onFulfilled(Cesium3DTileset value) {
                            tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
                        }
                    });
                    break;
                case 3:
                    loadModel(modelUrl);
                    break;
                default:
                    break;
            }
        }
    });
    boundingVolumeCBox = new CheckBox("Show bounding volume");
    boundingVolumeCBox.setValue(false);
    boundingVolumeCBox.getElement().getStyle().setColor("white");
    boundingVolumeCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (Cesium.defined(tileset)) {
                tileset.debugShowBoundingVolume = event.getValue();
            }
        }
    });
    edgeStylingCBox = new CheckBox("Enable edge styling");
    edgeStylingCBox.setValue(true);
    edgeStylingCBox.getElement().getStyle().setColor("white");
    edgeStylingCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            double edgeWidth = event.getValue() ? 1.0 : 0.0;
            if (Cesium.defined(tileset)) {
                tileset.clippingPlanes.edgeWidth = edgeWidth;
            }
            if (Cesium.defined(modelEntityClippingPlanes)) {
                modelEntityClippingPlanes.edgeWidth = edgeWidth;
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(clipObjectLBox, 20, 20);
    aPanel.add(boundingVolumeCBox, 20, 50);
    aPanel.add(edgeStylingCBox, 20, 70);
    contentPanel.add(new HTML("<p>User-defined clipping planes applied to a batched 3D Tileset, point cloud, and model.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
    loadTileset(bimUrl);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Entity(org.cesiumjs.cs.datasources.Entity) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) HTML(com.google.gwt.user.client.ui.HTML) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) Cesium3DTileset(org.cesiumjs.cs.scene.Cesium3DTileset) PlaneGraphics(org.cesiumjs.cs.datasources.graphics.PlaneGraphics) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CheckBox(com.google.gwt.user.client.ui.CheckBox) JsObject(org.cesiumjs.cs.js.JsObject) ListBox(com.google.gwt.user.client.ui.ListBox) Fulfill(org.cesiumjs.cs.promise.Fulfill)

Example 7 with ColorMaterialProperty

use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty 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)

Aggregations

ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)7 Entity (org.cesiumjs.cs.datasources.Entity)5 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)5 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)5 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)5 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)4 HTML (com.google.gwt.user.client.ui.HTML)3 ClippingPlaneCollection (org.cesiumjs.cs.collections.ClippingPlaneCollection)3 ClippingPlaneCollectionOptions (org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions)3 Cartesian3 (org.cesiumjs.cs.core.Cartesian3)3 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)3 PlaneGraphics (org.cesiumjs.cs.datasources.graphics.PlaneGraphics)3 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)3 JsObject (org.cesiumjs.cs.js.JsObject)3 ClippingPlane (org.cesiumjs.cs.scene.ClippingPlane)3 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2