Giter Club home page Giter Club logo

cesium-dnd's Introduction

cesium-dnd

cesium-dnd makes Cesium entities draggable with less code. Demo

Screenshot

Getting Started

To install:

npm install cesium cesium-dnd
# or
yarn add cesium cesium-dnd

Or

<script src="https://unpkg.com/cesium-dnd@latest/dist/cesium-dnd.umd.js"></script>
<script>
  const viewer = new Cesium.Viewer("cesiumContainer");
  new CesiumDnD(viewer);
</script>

Usage

// Init cesium-dnd
const viewer = new Cesium.Viewer("cesiumContainer");

const cesiumDnD = new CesiumDnD(viewer, { // CesiumWidget is also acceptable
  initialDisabled: false,
  onDrag: (entity, position, context) => {
    // ...
  },
  onDragging: (entity, position, context) => {
    // ...
  },
  onDrop: (entity, position, context) => {
    // ...
  }
});

// Disable drag and drop
cesiumDnD.disable();

// Enable drag and drop
cesiumDnD.enable();
type Context = {
  position?: Cartesian3;
  screenPosition: Cartesian2;
  initialPosition?: PositionProperty;
  initialScreenPosition: Cartesian2;
};

type Position = {
  /** Degrees */
  lat: number;
  /** Degrees */
  lng: number;
  /** Meters */
  height: number;
};

type Options = {
  /** If true, prevent dnd to be automatically enabled. */
  initialDisabled?: boolean;
  /** If false is returned, dragging will not start. */
  onDrag?: (e: Entity, position: Position | undefined, context: Context) => void | boolean;
  /**
   * If undefined is returned, new position will be automatically set to the entity. (default)
   * If false is returned, new position will not be set to the entity.
   * Otherwise, the return value will be set as new position to the entity.
   */
  onDragging?: (
    e: Entity,
    position: Position | undefined,
    context: Context & { previousScreenPosition: Cartesian2 },
  ) => void | false | Cartesian3;
  /**
   * If false is returned, new position will not be set to the entity and position of the entity will be reverted.
   * Otherwise, new position will be automatically set to the entity.
   */
  onDrop?: (e: Entity, position: Position | undefined, context: Context) => void | boolean;
};

License

MIT License

cesium-dnd's People

Contributors

airslice avatar hideba avatar rot1024 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cesium-dnd's Issues

Sudden move when click an entity

The entity will suddenly move to the position of the cursor, even we don't click at the center of the entity.
I think it will be better if we record the offset between the entity center and click position.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.