Search in sources :

Example 1 with CirclePrimitiveOptions

use of org.cesiumjs.cs.scene.interaction.options.CirclePrimitiveOptions in project gwt-cs by iSergio.

the class DrawInteraction method startDrawing.

private void startDrawing(Object event) {
    if (!active) {
        return;
    }
    MouseDownEvent mouseDownEvent = (MouseDownEvent) event;
    if (mouseDownEvent.position == null) {
        return;
    }
    Cartesian3 cartesian;
    if (scene.mode.equals(SceneMode.SCENE3D())) {
        Ray ray = scene.camera().getPickRay(mouseDownEvent.position);
        cartesian = scene.globe.pick(ray, scene);
    } else {
        cartesian = scene.camera().pickEllipsoid(mouseDownEvent.position, scene.globe.ellipsoid);
    }
    if (cartesian == null) {
        return;
    }
    Event startEvent = new Event(EventType.DRAW_START, options.type);
    if (type == PrimitiveType.RECTANGLE) {
        if (rectangle == null) {
            firstPoint = scene.globe.ellipsoid.cartesianToCartographic(cartesian);
            Rectangle value = getExtent(firstPoint, firstPoint);
            updateExtent(value);
        // startEvent.setPrimitive();
        } else {
            finishDrawing();
        }
    } else if (type == PrimitiveType.POLYGON || type == PrimitiveType.CORRIDOR) {
        if (polygon == null && type == PrimitiveType.POLYGON) {
            polygon = new PolygonPrimitive(options);
            JsObject.setProperty(polygon, "asynchronous", false);
            collection.add(polygon);
            startEvent.setPrimitive(polygon);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
        } else if (corridor == null && type == PrimitiveType.CORRIDOR) {
            corridor = new CorridorPrimitive(scene, new CorridorPrimitiveOptions(options));
            JsObject.setProperty(corridor, "asynchronous", false);
            collection.add(corridor);
            startEvent.setPrimitive(corridor);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
        }
        if (markers == null) {
            markers = new MarkerGroup(scene, options);
        }
        if (positions.size() == 0) {
            positions.add(cartesian.clone());
            markers.add(positions.get(0));
        }
        if (positions.size() >= options.minPoints) {
            if (type == PrimitiveType.POLYGON) {
                polygon.setPositions(positions.toArray(new Cartesian3[positions.size()]));
                polygon.createPrimitive = true;
            } else {
                corridor.setPositions(positions.toArray(new Cartesian3[positions.size()]));
                corridor.createPrimitive = true;
            }
        }
        positions.add(cartesian);
        markers.add(cartesian);
    } else if (type == PrimitiveType.CIRCLE) {
        if (circle == null) {
            CirclePrimitiveOptions circlePrimitiveOptions = new CirclePrimitiveOptions(options);
            circlePrimitiveOptions.center = cartesian;
            circlePrimitiveOptions.radius = 0;
            circle = new CirclePrimitive(circlePrimitiveOptions);
            collection.add(circle);
            startEvent.setPrimitive(circle);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
            // Markers
            markers = new MarkerGroup(scene, options);
            markers.add(cartesian);
            // Create radius
            CorridorPrimitiveOptions radiusOptions = new CorridorPrimitiveOptions(options);
            radiusOptions.color = Color.YELLOW();
            radiusOptions.minPoints = 2;
            radius = new CorridorPrimitive(scene, radiusOptions);
            JsObject.setProperty(radius, "asynchronous", false);
            collection.add(radius);
            if (positions.size() == 0) {
                positions.add(cartesian.clone());
            }
            radius.setPositions(positions.toArray(new Cartesian3[positions.size()]));
            radius.createPrimitive = true;
            positions.add(cartesian);
        } else {
            // Done
            finishDrawing();
        }
    } else if (type == PrimitiveType.POINT) {
        if (point == null) {
            point = new org.cesiumjs.cs.scene.interaction.PointPrimitive(scene, new CorridorPrimitiveOptions(options));
            positions.add(cartesian.clone());
            point.setPositions(positions.toArray(new Cartesian3[positions.size()]));
            collection.add(point);
            finishDrawing();
        }
    }
}
Also used : MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) CirclePrimitiveOptions(org.cesiumjs.cs.scene.interaction.options.CirclePrimitiveOptions) PointPrimitive(org.cesiumjs.cs.scene.PointPrimitive) CorridorPrimitiveOptions(org.cesiumjs.cs.scene.interaction.options.CorridorPrimitiveOptions) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) MouseDblClickEvent(org.cesiumjs.cs.core.events.MouseDblClickEvent) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent)

Aggregations

KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1 MouseDblClickEvent (org.cesiumjs.cs.core.events.MouseDblClickEvent)1 MouseDownEvent (org.cesiumjs.cs.core.events.MouseDownEvent)1 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)1 PointPrimitive (org.cesiumjs.cs.scene.PointPrimitive)1 CirclePrimitiveOptions (org.cesiumjs.cs.scene.interaction.options.CirclePrimitiveOptions)1 CorridorPrimitiveOptions (org.cesiumjs.cs.scene.interaction.options.CorridorPrimitiveOptions)1