Skip to content

Commit

Permalink
add plugin-feature-click
Browse files Browse the repository at this point in the history
  • Loading branch information
hongfaqiu committed Apr 24, 2024
1 parent 4c98212 commit b369e8b
Show file tree
Hide file tree
Showing 24 changed files with 259 additions and 8 deletions.
12 changes: 12 additions & 0 deletions examples/vite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# dde-earth-vite-example

## 0.0.12

### Patch Changes

- Updated dependencies
- [email protected]
- @dde-earth/plugin-martini-terrain-loader@1.0.3
- @dde-earth/plugin-mvt-loader@1.2.3
- @dde-earth/plugin-nc-loader@1.2.3
- @dde-earth/plugin-tiff-loader@1.2.3
- @dde-earth/recommend-plugins@1.3.3

## 0.0.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dde-earth-vite-example",
"version": "0.0.11",
"version": "0.0.12",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
6 changes: 6 additions & 0 deletions packages/dde-earth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# dde-earth

## 1.2.3

### Patch Changes

- export EventEmitter

## 1.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/dde-earth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dde-earth",
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/dde-earth/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from "./layerItem";
export * from "./layerManager";
export * from "./terrainManager";
export * from "./debug";
export * from "./event";
export * from "./pluginManager";
8 changes: 8 additions & 0 deletions packages/plugin-feature-click/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @dde-earth/plugin-feature-click

## 1.3.3

### Patch Changes

- Updated dependencies
- [email protected]
37 changes: 37 additions & 0 deletions packages/plugin-feature-click/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@dde-earth/plugin-feature-click",
"version": "1.3.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
"types": "./dist/typings/index.d.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "rimraf dist && rollup -c",
"dev": "rollup -c --watch"
},
"keywords": [
"cesium",
"dde"
],
"license": "MIT",
"peerDependencies": {
"cesium": "*"
},
"devDependencies": {
"@dde-earth/recommend-plugins": "workspace:^",
"cesium": "latest"
},
"engines": {
"node": "^18.0.0 || >=20.0.0"
},
"dependencies": {
"@cesium-extends/primitive-geojson": "^1.0.7",
"dde-earth": "workspace:^"
}
}
3 changes: 3 additions & 0 deletions packages/plugin-feature-click/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createConfig } from "../../shared/rollup.config.mjs";

export default createConfig();
17 changes: 17 additions & 0 deletions packages/plugin-feature-click/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Earth } from "dde-earth";

declare module "dde-earth" {
namespace Earth {
interface Events {
FEATURE_CLICK: [
reslt: {
feature: any;
position?: number[];
properties: any;
[key: string]: any;
},
];
}
}
}
76 changes: 76 additions & 0 deletions packages/plugin-feature-click/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type { Earth, EventEmitter } from "dde-earth";

import "./api";

import { GeoJsonPrimitiveLayer } from "@cesium-extends/primitive-geojson";
import { JulianDate } from "cesium";
import { BasePlugin } from "dde-earth";

import type { Subscriber } from "@dde-earth/recommend-plugins";
import type { DataSource, Entity } from "cesium";

export class FeatureClick extends BasePlugin<
FeatureClick.Args,
FeatureClick.Intl
> {
name = "FeatureClick";
private _subscriber: Subscriber | undefined;
private _eventEmitter: EventEmitter | undefined;

public init(earth: Earth) {
this._init(earth);
this._subscriber = this.earth.getSubscriber();
this._eventEmitter = this.earth.eventEmitter;
this.addListner();
return this;
}

addListner() {
if (!this._subscriber || !this._eventEmitter) return;

const sub = this._subscriber;
sub.on("LEFT_CLICK", (move, result) => {
if (result?.id) {
const entity = result.id as Entity;
const properties = entity.properties?.propertyNames?.length
? entity.properties?.getValue(new JulianDate())
: undefined;
const position = sub.cartesiantoLonlat(
entity.position?.getValue(new JulianDate()),
);

this.earth.emit("FEATURE_CLICK", {
feature: entity,
properties,
position,
});
}
});

this.earth.on("layer:add", (layerItem) => {
const layer = layerItem.instance;
if (layer instanceof GeoJsonPrimitiveLayer) {
sub.on("LEFT_CLICK", (move, result) => {
if (result?.primitive) {
const id = result.id;
const feature = layer.getFeatureItemById(id);
if (feature)
this.earth.emit("FEATURE_CLICK", {
feature: feature,
properties: feature.properties,
position: sub.cartesiantoLonlat(feature.center?.cartesian3),
});
}
});
}
});
}
}

export namespace FeatureClick {
export type Intl = {};

export type Args = [];

export type SupportedLayer = GeoJsonPrimitiveLayer | DataSource;
}
21 changes: 21 additions & 0 deletions packages/plugin-feature-click/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext", "dom"],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"outDir": "./dist",
"declaration": true,
"inlineSourceMap": true,
"types": ["node"]
},
"include": ["src/**/*", "test/**/*"],
"exclude": ["**/dist/**"]
}
7 changes: 7 additions & 0 deletions packages/plugin-geojson-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/plugin-geojson-loader

## 1.2.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-geojson-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/plugin-geojson-loader",
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-martini-terrain-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/plugin-martini-terrain-loader

## 1.0.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-martini-terrain-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/plugin-martini-terrain-loader",
"version": "1.0.2",
"version": "1.0.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-mvt-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/plugin-mvt-loader

## 1.2.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-mvt-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/plugin-mvt-loader",
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-nc-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/plugin-nc-loader

## 1.2.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nc-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/plugin-nc-loader",
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-tiff-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/plugin-tiff-loader

## 1.2.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-tiff-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/plugin-tiff-loader",
"version": "1.2.2",
"version": "1.2.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/recommend-plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dde-earth/recommend-plugins

## 1.3.3

### Patch Changes

- Updated dependencies
- [email protected]

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/recommend-plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dde-earth/recommend-plugins",
"version": "1.3.2",
"version": "1.3.3",
"type": "module",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b369e8b

Please sign in to comment.