@openglobus/ext-drag-and-drop 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +217 -0
- package/README.md +33 -2
- package/dist/DragAndDrop.d.ts +52 -0
- package/dist/GeoTiffTypeDialog.d.ts +24 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +222 -0
- package/dist/style.d.ts +8 -0
- package/package.json +30 -5
package/LICENSE.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
203
|
+
----------------------------------------------------------------------------
|
|
204
|
+
|
|
205
|
+
Copyright 2026 Michael Gevlich
|
|
206
|
+
|
|
207
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
208
|
+
you may not use this file except in compliance with the License.
|
|
209
|
+
You may obtain a copy of the License at
|
|
210
|
+
|
|
211
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
212
|
+
|
|
213
|
+
Unless required by applicable law or agreed to in writing, software
|
|
214
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
215
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
216
|
+
See the License for the specific language governing permissions and
|
|
217
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @openglobus/ext-drag-and-drop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drag and drop for [OpenGlobus](https://github.com/openglobus/openglobus): files dropped on the globe are added to it.
|
|
4
|
+
|
|
5
|
+
- glb, gltf and obj models (with the mtl file dropped together) and images are placed at the drop point;
|
|
6
|
+
- GeoTIFF rasters are placed by their georeference; a GeoTIFF that may hold heights asks whether to add it as a terrain or as a layer.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @openglobus/ext-drag-and-drop
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import dragAndDrop from "@openglobus/ext-drag-and-drop";
|
|
14
|
+
|
|
15
|
+
const globe = new Globe({ target: "map", extensions: [dragAndDrop] });
|
|
16
|
+
|
|
17
|
+
await globe.extensions.remove("og.drag-and-drop");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or at runtime:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
await globe.extensions.load("https://cdn.jsdelivr.net/npm/@openglobus/ext-drag-and-drop@1.0.0/dist/index.js");
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The control can be used without the extension, a dropped model is selected in the given entity editor:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { DragAndDrop } from "@openglobus/ext-drag-and-drop";
|
|
30
|
+
|
|
31
|
+
globe.planet.addControl(new DragAndDrop({ entityEditor }));
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The control adds its styles to the page itself, the og.css of openglobus is still needed.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Control, Entity, GeoTIFFLayer, GeoTiffTerrain, Vector } from "@openglobus/og";
|
|
2
|
+
import type { EmptyTerrain, IControlParams, LonLat } from "@openglobus/og";
|
|
3
|
+
import { GeoTiffTypeDialog, type GeoTiffType } from "./GeoTiffTypeDialog";
|
|
4
|
+
/** Selects the dropped model, e.g. EntityEditor of og.entity-editor */
|
|
5
|
+
export interface IEntitySelector {
|
|
6
|
+
selectEntity(entity: Entity): void;
|
|
7
|
+
}
|
|
8
|
+
export interface IDragAndDropParams extends IControlParams {
|
|
9
|
+
entityEditor?: IEntitySelector;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Adds dropped files on the globe: glb/obj models and images are placed in the drop point,
|
|
13
|
+
* GeoTIFF rasters are placed by their georeference. A GeoTIFF that is not an image for certain may hold
|
|
14
|
+
* heights, its tags do not tell that, so the control asks whether to add it as a terrain or as a layer.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DragAndDrop extends Control {
|
|
17
|
+
geoObjectsLayer: Vector;
|
|
18
|
+
markersLayer: Vector;
|
|
19
|
+
tiffLayers: GeoTIFFLayer[];
|
|
20
|
+
tiffTerrains: GeoTiffTerrain[];
|
|
21
|
+
protected _entityEditor: IEntitySelector | null;
|
|
22
|
+
/** Terrain to bring back when the control is removed */
|
|
23
|
+
protected _baseTerrain: EmptyTerrain | null;
|
|
24
|
+
protected _tiffDialog: GeoTiffTypeDialog | null;
|
|
25
|
+
/** Dropped files are added in parallel, their questions go one by one */
|
|
26
|
+
protected _tiffQuestions: Promise<unknown>;
|
|
27
|
+
constructor(options?: IDragAndDropParams);
|
|
28
|
+
oninit(): void;
|
|
29
|
+
onremove(): void;
|
|
30
|
+
protected _removeTiffTerrains(): void;
|
|
31
|
+
protected _isTiffTerrain(terrain: EmptyTerrain | null): boolean;
|
|
32
|
+
onactivate(): void;
|
|
33
|
+
ondeactivate(): void;
|
|
34
|
+
protected _onDragOver: (e: DragEvent) => void;
|
|
35
|
+
protected _onDrop: (e: DragEvent) => void;
|
|
36
|
+
protected _getLonLatFromEvent(e: DragEvent): LonLat | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Adds files on the globe. Mtl file goes along with the obj file in the same list.
|
|
39
|
+
*/
|
|
40
|
+
addFiles(files: File[], lonLat?: LonLat): void;
|
|
41
|
+
addFile(file: File, lonLat?: LonLat, mtlFile?: File | null): Promise<void>;
|
|
42
|
+
protected _addGltf(file: File, lonLat: LonLat): Promise<void>;
|
|
43
|
+
protected _addObj(file: File, lonLat: LonLat, mtlFile?: File | null): Promise<void>;
|
|
44
|
+
protected _selectEntity(entity: Entity): void;
|
|
45
|
+
protected _addBillboard(file: File, lonLat: LonLat): Promise<void>;
|
|
46
|
+
protected _createTiffLayer(file: File): GeoTIFFLayer;
|
|
47
|
+
protected _createTiffTerrain(file: File): GeoTiffTerrain;
|
|
48
|
+
protected _askTiffType(file: File): Promise<GeoTiffType | null>;
|
|
49
|
+
protected _showTiffDialog(file: File): Promise<GeoTiffType | null>;
|
|
50
|
+
protected _addTiff(file: File): Promise<void>;
|
|
51
|
+
protected _addTiffTerrain(file: File): Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ui } from "@openglobus/og";
|
|
2
|
+
export type GeoTiffType = "terrain" | "layer";
|
|
3
|
+
interface IGeoTiffTypeDialogParams {
|
|
4
|
+
fileName: string;
|
|
5
|
+
onClose: (type: GeoTiffType | null) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Asks how to add a GeoTIFF. The dialog answers null when it is closed without a choice.
|
|
9
|
+
* @class
|
|
10
|
+
* @extends {ui.Dialog}
|
|
11
|
+
* @param {IGeoTiffTypeDialogParams} params - Options:
|
|
12
|
+
* @param {string} params.fileName - File name, shown as a plain text.
|
|
13
|
+
* @param {Function} params.onClose - Takes the answer when the dialog is closed.
|
|
14
|
+
*/
|
|
15
|
+
declare class GeoTiffTypeDialog extends ui.Dialog<null> {
|
|
16
|
+
protected _fileName: string;
|
|
17
|
+
protected _onClose: (type: GeoTiffType | null) => void;
|
|
18
|
+
protected _type: GeoTiffType | null;
|
|
19
|
+
constructor(params: IGeoTiffTypeDialogParams);
|
|
20
|
+
render(params?: any): this;
|
|
21
|
+
protected _appendButton($parent: HTMLElement, text: string, type: GeoTiffType): void;
|
|
22
|
+
remove(): void;
|
|
23
|
+
}
|
|
24
|
+
export { GeoTiffTypeDialog };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DragAndDrop } from "./DragAndDrop";
|
|
2
|
+
export * from "./GeoTiffTypeDialog";
|
|
3
|
+
export * from "./DragAndDrop";
|
|
4
|
+
/**
|
|
5
|
+
* Adds files dropped on the globe: glb/gltf/obj models, images and GeoTIFF rasters or terrains.
|
|
6
|
+
* Exports the DragAndDrop control.
|
|
7
|
+
* @example
|
|
8
|
+
* import dragAndDrop from "@openglobus/ext-drag-and-drop";
|
|
9
|
+
*
|
|
10
|
+
* const globe = new Globe({ target: "map", extensions: [dragAndDrop] });
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: import("@openglobus/og").IExtension<DragAndDrop>;
|
|
13
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Control as e, Entity as t, GeoTIFFLayer as n, GeoTiffTerrain as r, Gltf as i, Object3d as a, Vec2 as o, Vector as s, defineExtension as c, ui as l } from "@openglobus/og";
|
|
2
|
+
// src/GeoTiffTypeDialog.ts
|
|
3
|
+
var u = class extends l.Dialog {
|
|
4
|
+
constructor(e) {
|
|
5
|
+
super({
|
|
6
|
+
title: "Add GeoTIFF",
|
|
7
|
+
classList: ["og-geotiff-type"],
|
|
8
|
+
resizable: !1,
|
|
9
|
+
width: 300
|
|
10
|
+
}), this._fileName = e.fileName, this._onClose = e.onClose, this._type = null;
|
|
11
|
+
}
|
|
12
|
+
render(e) {
|
|
13
|
+
super.render(e);
|
|
14
|
+
let t = document.createElement("div");
|
|
15
|
+
t.classList.add("og-geotiff-type__body");
|
|
16
|
+
let n = document.createElement("div");
|
|
17
|
+
n.classList.add("og-geotiff-type__file"), n.textContent = this._fileName, n.title = this._fileName, t.appendChild(n);
|
|
18
|
+
let r = document.createElement("div");
|
|
19
|
+
r.textContent = "Add the file as a terrain or as a raster layer?", t.appendChild(r);
|
|
20
|
+
let i = document.createElement("div");
|
|
21
|
+
return i.classList.add("og-geotiff-type__buttons"), t.appendChild(i), this._appendButton(i, "Terrain", "terrain"), this._appendButton(i, "Layer", "layer"), this.container.appendChild(t), this;
|
|
22
|
+
}
|
|
23
|
+
_appendButton(e, t, n) {
|
|
24
|
+
let r = new l.Button({
|
|
25
|
+
classList: ["og-geotiff-type__button"],
|
|
26
|
+
text: t
|
|
27
|
+
});
|
|
28
|
+
r.appendTo(e), r.events.on("click", () => {
|
|
29
|
+
this._type = n, this.close();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
remove() {
|
|
33
|
+
super.remove(), this._onClose(this._type);
|
|
34
|
+
}
|
|
35
|
+
}, d = ".og-geotiff-type__body{color:var(--grey6);padding:0 12px 10px}.og-geotiff-type__file{white-space:nowrap;text-overflow:ellipsis;margin-bottom:8px;font-weight:600;overflow:hidden}.og-geotiff-type__buttons{flex-direction:row;justify-content:flex-end;gap:8px;margin-top:14px;display:flex}.og-geotiff-type__button{border:1px solid var(--grey2);color:var(--grey6);padding:4px 14px}", f = null, p = 0;
|
|
36
|
+
function m() {
|
|
37
|
+
p++ === 0 && (f = document.createElement("style"), f.textContent = d, document.head.appendChild(f));
|
|
38
|
+
}
|
|
39
|
+
function h() {
|
|
40
|
+
p > 0 && --p === 0 && (f?.remove(), f = null);
|
|
41
|
+
}
|
|
42
|
+
// src/DragAndDrop.ts
|
|
43
|
+
var g = [
|
|
44
|
+
"png",
|
|
45
|
+
"jpg",
|
|
46
|
+
"jpeg",
|
|
47
|
+
"gif",
|
|
48
|
+
"webp",
|
|
49
|
+
"svg"
|
|
50
|
+
], _ = ["tif", "tiff"], v = /[<>&"'`]/g, y = 256;
|
|
51
|
+
function b(e) {
|
|
52
|
+
let t = e.name.lastIndexOf(".");
|
|
53
|
+
return t === -1 ? "" : e.name.slice(t + 1).toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
function x(e) {
|
|
56
|
+
let t = e.name.lastIndexOf(".");
|
|
57
|
+
return t === -1 ? e.name : e.name.slice(0, t);
|
|
58
|
+
}
|
|
59
|
+
function S(e) {
|
|
60
|
+
return new Promise((t, n) => {
|
|
61
|
+
let r = new Image();
|
|
62
|
+
r.onload = () => t(r), r.onerror = () => n(/* @__PURE__ */ Error(`Unable to load image '${e}'`)), r.src = e;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
var C = class extends e {
|
|
66
|
+
constructor(e = {}) {
|
|
67
|
+
super({
|
|
68
|
+
name: "DragAndDrop",
|
|
69
|
+
autoActivate: !0,
|
|
70
|
+
...e
|
|
71
|
+
}), this._onDragOver = (e) => {
|
|
72
|
+
e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "copy");
|
|
73
|
+
}, this._onDrop = (e) => {
|
|
74
|
+
if (e.preventDefault(), !e.dataTransfer || !e.dataTransfer.files.length) return;
|
|
75
|
+
let t = this._getLonLatFromEvent(e);
|
|
76
|
+
this.addFiles(Array.from(e.dataTransfer.files), t);
|
|
77
|
+
}, this.geoObjectsLayer = new s("__geoObjects__"), this.markersLayer = new s("__markers__"), this.tiffLayers = [], this.tiffTerrains = [], this._entityEditor = e.entityEditor || null, this._baseTerrain = null, this._tiffDialog = null, this._tiffQuestions = Promise.resolve();
|
|
78
|
+
}
|
|
79
|
+
oninit() {
|
|
80
|
+
m(), this.planet.addLayers([this.geoObjectsLayer, this.markersLayer]);
|
|
81
|
+
}
|
|
82
|
+
onremove() {
|
|
83
|
+
this.geoObjectsLayer.remove(), this.markersLayer.remove();
|
|
84
|
+
for (let e = 0; e < this.tiffLayers.length; e++) this.tiffLayers[e].remove();
|
|
85
|
+
this.tiffLayers = [], this._tiffDialog?.close(), this._removeTiffTerrains(), this._initialized && h();
|
|
86
|
+
}
|
|
87
|
+
_removeTiffTerrains() {
|
|
88
|
+
let e = this.planet;
|
|
89
|
+
this._baseTerrain && this._isTiffTerrain(e.terrain) && e.setTerrain(this._baseTerrain), this.tiffTerrains = this.tiffTerrains.filter((t) => t === e.terrain || (e.removeTerrain(t), t.reader.destroy(), !1)), this._baseTerrain = null;
|
|
90
|
+
}
|
|
91
|
+
_isTiffTerrain(e) {
|
|
92
|
+
return this.tiffTerrains.some((t) => t === e);
|
|
93
|
+
}
|
|
94
|
+
onactivate() {
|
|
95
|
+
let e = this.renderer.getInnerContainer();
|
|
96
|
+
e.addEventListener("dragover", this._onDragOver), e.addEventListener("drop", this._onDrop);
|
|
97
|
+
}
|
|
98
|
+
ondeactivate() {
|
|
99
|
+
let e = this.renderer.getInnerContainer();
|
|
100
|
+
e.removeEventListener("dragover", this._onDragOver), e.removeEventListener("drop", this._onDrop);
|
|
101
|
+
}
|
|
102
|
+
_getLonLatFromEvent(e) {
|
|
103
|
+
let t = this.renderer.handler, n = t.canvas.getBoundingClientRect(), r = new o((e.clientX - n.left) * t.pixelRatio, (e.clientY - n.top) * t.pixelRatio);
|
|
104
|
+
return this.planet.getLonLatFromPixelTerrain(r);
|
|
105
|
+
}
|
|
106
|
+
addFiles(e, t) {
|
|
107
|
+
let n = e.find((e) => b(e) === "mtl") || null;
|
|
108
|
+
for (let r = 0; r < e.length; r++) this.addFile(e[r], t, n).catch((t) => {
|
|
109
|
+
console.warn(`DragAndDrop: unable to add '${e[r].name}'.`, t);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async addFile(e, t, n) {
|
|
113
|
+
let r = b(e);
|
|
114
|
+
r === "glb" || r === "gltf" ? t && await this._addGltf(e, t) : r === "obj" ? t && await this._addObj(e, t, n) : g.includes(r) ? t && await this._addBillboard(e, t) : _.includes(r) && await this._addTiff(e);
|
|
115
|
+
}
|
|
116
|
+
async _addGltf(e, n) {
|
|
117
|
+
let r = URL.createObjectURL(e);
|
|
118
|
+
try {
|
|
119
|
+
let a = b(e) === "glb" ? await i.loadGlb(r) : await i.loadGltf(r), o = new t({
|
|
120
|
+
name: x(e),
|
|
121
|
+
lonlat: n
|
|
122
|
+
});
|
|
123
|
+
o.appendChildren(a.toEntities(), !0), this.geoObjectsLayer.add(o), this._selectEntity(o);
|
|
124
|
+
} finally {
|
|
125
|
+
URL.revokeObjectURL(r);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async _addObj(e, n, r) {
|
|
129
|
+
let i = x(e), o = await a.readFileObj(e, r), s = new t({
|
|
130
|
+
name: i,
|
|
131
|
+
lonlat: n
|
|
132
|
+
});
|
|
133
|
+
for (let e = 0; e < o.length; e++) s.appendChild(new t({
|
|
134
|
+
relativePosition: !0,
|
|
135
|
+
geoObject: {
|
|
136
|
+
tag: `${i}:${e.toString()}`,
|
|
137
|
+
object3d: o[e]
|
|
138
|
+
}
|
|
139
|
+
}));
|
|
140
|
+
this.geoObjectsLayer.add(s), this._selectEntity(s);
|
|
141
|
+
}
|
|
142
|
+
_selectEntity(e) {
|
|
143
|
+
let t = this._entityEditor || this.renderer?.controls.EntityEditor;
|
|
144
|
+
typeof t?.selectEntity == "function" && t.selectEntity(e);
|
|
145
|
+
}
|
|
146
|
+
async _addBillboard(e, n) {
|
|
147
|
+
let r = await S(URL.createObjectURL(e)), i = Math.min(1, y / Math.max(r.width, r.height));
|
|
148
|
+
this.markersLayer.add(new t({
|
|
149
|
+
name: x(e),
|
|
150
|
+
lonlat: n,
|
|
151
|
+
billboard: {
|
|
152
|
+
image: r,
|
|
153
|
+
width: Math.round(r.width * i),
|
|
154
|
+
height: Math.round(r.height * i)
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
_createTiffLayer(e) {
|
|
159
|
+
return new n(`__tif__${e.name}`, { src: e });
|
|
160
|
+
}
|
|
161
|
+
_createTiffTerrain(e) {
|
|
162
|
+
return new r(x(e).replace(v, ""), { src: e });
|
|
163
|
+
}
|
|
164
|
+
_askTiffType(e) {
|
|
165
|
+
let t = this._tiffQuestions.then(() => this._showTiffDialog(e));
|
|
166
|
+
return this._tiffQuestions = t, t;
|
|
167
|
+
}
|
|
168
|
+
_showTiffDialog(e) {
|
|
169
|
+
return new Promise((t) => {
|
|
170
|
+
if (!this.renderer) {
|
|
171
|
+
t(null);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let n = new u({
|
|
175
|
+
fileName: e.name,
|
|
176
|
+
onClose: (e) => {
|
|
177
|
+
this._tiffDialog = null, t(e);
|
|
178
|
+
}
|
|
179
|
+
}), r = this.renderer.getUIContainer();
|
|
180
|
+
n.appendTo(r), n.setPosition(Math.max(0, (r.clientWidth - n.el.offsetWidth) / 2), Math.max(0, (r.clientHeight - n.el.offsetHeight) / 2)), this._tiffDialog = n;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async _addTiff(e) {
|
|
184
|
+
let t = this._createTiffLayer(e), n;
|
|
185
|
+
try {
|
|
186
|
+
n = (await t.whenReady()).isImagery;
|
|
187
|
+
} catch (e) {
|
|
188
|
+
throw t.remove(), e;
|
|
189
|
+
}
|
|
190
|
+
let r = n ? "layer" : await this._askTiffType(e);
|
|
191
|
+
r === "layer" ? (this.tiffLayers.push(t), this.planet.addLayer(t), t.flyExtent()) : (t.remove(), r === "terrain" && await this._addTiffTerrain(e));
|
|
192
|
+
}
|
|
193
|
+
async _addTiffTerrain(e) {
|
|
194
|
+
let t = this._createTiffTerrain(e);
|
|
195
|
+
try {
|
|
196
|
+
await t.whenReady();
|
|
197
|
+
} catch (e) {
|
|
198
|
+
throw t.reader.destroy(), e;
|
|
199
|
+
}
|
|
200
|
+
if (!this.renderer) {
|
|
201
|
+
t.reader.destroy();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let n = this.planet;
|
|
205
|
+
this._isTiffTerrain(n.terrain) || (this._baseTerrain = n.terrain), this.tiffTerrains.push(t), n.setTerrain(t), t.flyExtent();
|
|
206
|
+
}
|
|
207
|
+
}, w = c({
|
|
208
|
+
id: "og.drag-and-drop",
|
|
209
|
+
version: "1.0.0",
|
|
210
|
+
og: "^1.0.0-rc.50",
|
|
211
|
+
extensionApi: "^1",
|
|
212
|
+
optional: { "og.entity-editor": "^1.0.0" },
|
|
213
|
+
activate(e) {
|
|
214
|
+
if (!e.globe) throw Error("og.drag-and-drop needs a Globe");
|
|
215
|
+
let t = new C();
|
|
216
|
+
return e.globe.planet.addControl(t), t;
|
|
217
|
+
},
|
|
218
|
+
deactivate(e) {
|
|
219
|
+
e.get("og.drag-and-drop")?.exports?.remove();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
export { C as DragAndDrop, u as GeoTiffTypeDialog, w as default };
|
package/dist/style.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@openglobus/ext-drag-and-drop",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Drag and drop extension for OpenGlobus: adds models, images and GeoTIFF files dropped on the globe",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/openglobus/og-extensions.git",
|
|
10
|
+
"directory": "packages/drag-and-drop"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"openglobus-extension"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "vite build && tsc --emitDeclarationOnly"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@openglobus/og": "^1.0.0-rc.50"
|
|
30
|
+
}
|
|
31
|
+
}
|