@pirireis/webglobeplugins 0.6.27-a → 0.6.28-a

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.
@@ -1,486 +0,0 @@
1
-
2
- import {
3
- CSObjectArrayUpdateTypes,
4
- } from "@pirireis/webglobe";
5
- import { ENUM_HIDE, ENUM_TEXT_HIDE, COMPASS_MODES } from "./enum";
6
-
7
-
8
- const Degree = 180 / Math.PI;
9
-
10
-
11
-
12
- const fidKey = "__fid__";
13
-
14
-
15
- const object = {
16
- "displayName": "RangeRingAngleText",
17
- "layerType": 3,
18
- "wkbGeom": null,
19
- "wfsLayerName": null,
20
- "objectType": "point",
21
- "bbox": null,
22
- "startLod": 2,
23
- "endLod": 30,
24
- "continuousLOD": true,
25
- "MVTXYZName": "hd_seyp",
26
- "rasterize": false,
27
- }
28
-
29
-
30
- export default class RangeRingAngleText {
31
- constructor(globe, id, { style = null, flatCompassMode = COMPASS_MODES.REAL, hideAll = false, opacity = 1 } = {}) {
32
- this.globe = globe;
33
- this.ObjectArray = globe.ObjectArray;
34
- this.id = id;
35
- this._flatCompassMode = flatCompassMode;
36
- this._lastImplicitCompassMode = this.__implicitCompassMode();
37
-
38
- this._hideAll = hideAll;
39
- this._opacity = opacity;
40
- const style_ = style !== null ? style : this.getDefaultStyle();
41
- this.object = Object.assign({}, object, { style: style_, id: this.id });
42
-
43
- this._centerCollection = new Map();
44
- // new inner MAP params
45
- // hide
46
- // textHide
47
-
48
- this.ObjectArray.Add(this.object);
49
-
50
- }
51
-
52
- getDefaultStyle() {
53
- const style = this.ObjectArray.GetDefaultStyle();
54
- style.fidKey = fidKey;
55
- const { labels } = style;
56
- const label = labels[0];
57
- label.offset = { x: 0, y: 0 };
58
- label.fontFamily.hollowWidth = 1;
59
- label.vAlignment = 2;
60
- label.hAlignment = 2;
61
- label.size = 17;
62
- label.text = "`${aci}`"
63
-
64
- return style;
65
- }
66
-
67
-
68
- setStyle(style) {
69
- if (style === null) return;
70
- style.opacity = this._opacity;
71
- this.object.style = style;
72
- this.ObjectArray.StyleChanged(this.object);
73
- }
74
-
75
-
76
- setOpacity(opacity) {
77
- this._opacity = opacity;
78
- const { style } = this.object;
79
- style.opacity = opacity;
80
- this.ObjectArray.StyleChanged(this.object);
81
- }
82
-
83
- setCompass(mode) {
84
- if (mode === this._flatCompassMode) return;
85
- this._flatCompassMode = mode;
86
- this.__onCompassChange();
87
- }
88
-
89
-
90
- free() {
91
- this.flush();
92
- this.ObjectArray.Delete(this.id);
93
- }
94
-
95
-
96
- /**
97
- * @param {Array<{centerID,stepAngle, x, y, rings>} ringDatas
98
- * centerID: string | ObjectArray fidKey de kullanilir
99
- * stepAngle: number | 0-360 arasinda
100
- * x, y: number | merkez koordinatlari lat long radian. Globe icin dereceye iceride cevrilir
101
- * rings: Array<{radius: number}> | En buyuk halkaya centik acilari yazilir, Sonraki adim yaricaplarin uzunlugunu yazdirmak
102
- *
103
- * eger bir centerID zaten var ise: Onceki noktalar dusurulur ve yeniden eklenir
104
- *
105
- * */
106
- insertBulk(ringDatas) {
107
- const { _hideAll } = this;
108
- const addBucket = {
109
- coords: [],
110
- coordsZ: [],
111
- attribs: []
112
- }
113
-
114
- const deleteBucket = {
115
- coords: [],
116
- coordsZ: [],
117
- attribs: []
118
- }
119
-
120
- for (const { centerID, x, y, rings, stepAngle, hide = ENUM_HIDE.SHOW, textHide = ENUM_TEXT_HIDE.SHOW } of ringDatas) {
121
- if (this._centerCollection.has(centerID)) {
122
- this._fillDeleteBucket(centerID, deleteBucket);
123
- }
124
- const maxRadius = rings.reduce((acc, { radius }) => Math.max(acc, radius), 0);
125
- const textHide_ = _hideAll ? ENUM_TEXT_HIDE.HIDE : textHide;
126
- const show = hide !== ENUM_HIDE.HIDE && textHide_ === ENUM_TEXT_HIDE.SHOW;
127
- if (show) this._appendCircle(x, y, maxRadius, stepAngle, centerID, addBucket);
128
- this._centerCollection.set(centerID,
129
- new Map([
130
- ["stepAngle", stepAngle],
131
- ["maxRadius", maxRadius],
132
- ["x", x],
133
- ["y", y],
134
- ["hide", hide],
135
- ["textHide", textHide_]
136
- ]));
137
- }
138
- if (this._hideAll) return;
139
- if (deleteBucket.coords.length > 0) this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
140
- if (addBucket.coords.length > 0) this._updateData(addBucket, CSObjectArrayUpdateTypes.ADD);
141
-
142
- }
143
-
144
- /**
145
- * @param {Array<{centerID, x,y}>} centerDatas
146
- * aci ve radiuslarin tutulmasi gereklidir.
147
- * */
148
- updateCentersXY(centerDatas) {
149
- const updateBucket = {
150
- coords: [],
151
- coordsZ: [],
152
- attribs: []
153
- }
154
- for (const { centerID, x, y } of centerDatas) {
155
- if (this._centerCollection.has(centerID)) {
156
- const centerMap = this._centerCollection.get(centerID);
157
- centerMap.set("x", x);
158
- centerMap.set("y", y);
159
- const hide = centerMap.get("hide");
160
- const textHide = centerMap.get("textHide");
161
- const isHidden = hide === ENUM_HIDE.HIDE || textHide === ENUM_TEXT_HIDE.HIDE;
162
- if (isHidden) continue;
163
- const maxRadius = centerMap.get("maxRadius");
164
- const stepAngle = centerMap.get("stepAngle");
165
- // long, lat, radius, step, centerID, outBucket
166
- this._appendCircle(x, y, maxRadius, stepAngle, centerID, updateBucket);
167
-
168
- }
169
- }
170
- // for (const attribs of updateBucket.attribs) {
171
- // delete attribs["aci"];
172
- // }
173
- if (updateBucket.coords.length > 0) {
174
- this._updateData(updateBucket, CSObjectArrayUpdateTypes.UPDATE);
175
- }
176
- }
177
-
178
-
179
-
180
- /**
181
- *
182
- * @param {Array<{centerID:string, hide: bool}} centerHides
183
- */
184
- updateCentersHide(centerHides) {
185
- if (this._hideAll) {
186
- console.warn("Tum mesafe halkasi yazilari gizli durum. Islem yapilamaz");
187
- return;
188
- };
189
- const addBucket = {
190
- coords: [],
191
- coordsZ: [],
192
- attribs: []
193
- };
194
- const deleteBucket = {
195
- coords: [],
196
- coordsZ: [],
197
- attribs: []
198
- };
199
- for (const { centerID, textHide = null, hide = null } of centerHides) {
200
- if (!this._centerCollection.has(centerID)) continue;
201
- const centerMap = this._centerCollection.get(centerID);
202
-
203
- const isHidden = centerMap.get("hide") === ENUM_HIDE.HIDE || centerMap.get("textHide") === ENUM_TEXT_HIDE.HIDE;
204
-
205
- const _hide = hide !== null ? hide : centerMap.get("hide");
206
- const _textHide = textHide !== null ? textHide : centerMap.get("textHide");
207
-
208
- const show = _hide !== ENUM_HIDE.HIDE && _textHide === ENUM_TEXT_HIDE.SHOW;
209
- if (!isHidden && !show) {
210
- this._fillDeleteBucket(centerID, deleteBucket);
211
- } else if (isHidden && show) {
212
- this._appendCircle(centerMap.get("x"), centerMap.get("y"), centerMap.get("maxRadius"), centerMap.get("stepAngle"), centerID, addBucket);
213
- }
214
- if (hide !== null) centerMap.set("hide", hide);
215
- if (textHide !== null) centerMap.set("textHide", textHide);
216
- }
217
- if (deleteBucket.coords.length > 0) this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
218
- if (addBucket.coords.length > 0) this._updateData(addBucket, CSObjectArrayUpdateTypes.ADD);
219
- }
220
-
221
-
222
- // TODO : Implement this
223
- removeCenters(centerIDs) {
224
- const deleteBucket = {
225
- coords: [],
226
- coordsZ: [],
227
- attribs: []
228
- }
229
- for (const centerID of centerIDs) {
230
- if (this._centerCollection.has(centerID)) {
231
- this._fillDeleteBucket(centerID, deleteBucket);
232
- this._centerCollection.delete(centerID);
233
- }
234
- }
235
- this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
236
- }
237
-
238
-
239
- hideAll() {
240
- this._hideAll = true;
241
- const deleteBucket = {
242
- coords: [],
243
- coordsZ: [],
244
- attribs: []
245
- }
246
- for (const [centerID, centerMap] of this._centerCollection) {
247
- const hide = centerMap.get("hide");
248
- const hideText = centerMap.get("textHide");
249
- centerMap.set("textHide", ENUM_TEXT_HIDE.HIDE);
250
- if (hide === ENUM_HIDE.HIDE) continue;
251
- const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
252
- if (!isHidden) this._fillDeleteBucket(centerID, deleteBucket);
253
- }
254
- this._updateData(deleteBucket, CSObjectArrayUpdateTypes.DELETE);
255
- }
256
-
257
- showAll() {
258
- this._hideAll = false;
259
- const addBucket = {
260
- coords: [],
261
- coordsZ: [],
262
- attribs: []
263
- }
264
- for (const [centerID, centerMap] of this._centerCollection) {
265
- const hide = centerMap.get("hide");
266
- if (hide === ENUM_HIDE.HIDE) continue;
267
- const hideText = centerMap.get("textHide");
268
- const isHidden = hideText === ENUM_TEXT_HIDE.HIDE;
269
- if (isHidden) {
270
- const x = centerMap.get("x");
271
- const y = centerMap.get("y");
272
- const maxRadius = centerMap.get("maxRadius");
273
- const stepAngle = centerMap.get("stepAngle");
274
- this._appendCircle(x, y, maxRadius, stepAngle, centerID, addBucket);
275
- centerMap.set("hide", ENUM_HIDE.SHOW);
276
- centerMap.set("textHide", ENUM_TEXT_HIDE.SHOW);
277
- }
278
- }
279
- if (addBucket.coords.length) this._updateData(addBucket, CSObjectArrayUpdateTypes.ADD);
280
- }
281
-
282
-
283
-
284
-
285
- flush() {
286
- const data = {
287
- coords: [],
288
- coordsZ: [],
289
- attribs: []
290
- };
291
- this._idCollector = new Set();
292
- this.ObjectArray.SetData(this.object, data);
293
- }
294
-
295
- //------------------GLOBE EVENTS------------------//
296
-
297
- setGeometry() {
298
- this.__onCompassChange();
299
- }
300
-
301
-
302
- //------------------PRIVATE METHODS------------------//
303
-
304
- __implicitCompassMode() {
305
- const is3D = this.globe.api_GetCurrentGeometry() === 0;
306
- if (is3D) {
307
- return COMPASS_MODES.REAL;
308
- } else {
309
- return this._flatCompassMode;
310
- }
311
- }
312
-
313
-
314
- __onCompassChange() {
315
- if (this._lastImplicitCompassMode === this.__implicitCompassMode()) return;
316
- this._lastImplicitCompassMode = this.__implicitCompassMode();
317
- this._updateAll();
318
- }
319
-
320
-
321
-
322
- // TODO: compass ve gercek mesafeye gore farkli hesaplamalar yapilacak __implicitCompassMode
323
- _appendCircle(long, lat, radius, step, centerID, outBucket) {
324
- const currentCompassMode = this.__implicitCompassMode();
325
- if (currentCompassMode == COMPASS_MODES.REAL) {
326
- this.__realCoords(long, lat, radius, step, centerID, outBucket);
327
- } else if (currentCompassMode == COMPASS_MODES.COMPASS) {
328
- // throw new Error("Not implemented yet");
329
- // this.__compassCoords(long, lat, radius, step, centerID, outBucket);
330
- }
331
-
332
- }
333
-
334
- __realCoords(long, lat, radius, stepAngle, centerID, outBucket) {
335
- const { coords, coordsZ, attribs } = outBucket;
336
-
337
- const coords_ = realCircle(this.globe, long, lat, radius, stepAngle);
338
- { // add 0
339
- const { long, lat } = coords_[0];
340
- coords.push(long, lat);
341
- coordsZ.push(0);
342
- const key = this._key(centerID, 0);
343
- // fidkey is the key
344
- attribs.push({
345
- "__fid__": key,
346
- "aci": "K"
347
- });
348
- }
349
- let aci = stepAngle;
350
- for (let i = 1; i < coords_.length; i++) {
351
- if (aci >= 360) break;
352
- const { long, lat } = coords_[i];
353
- coords.push(long, lat);
354
- coordsZ.push(0);
355
- const key = this._key(centerID, i);
356
- // fidkey is the key
357
- attribs.push({
358
- "__fid__": key,
359
- "aci": (360 - aci).toString().padStart(3, '0')
360
- })
361
- aci += stepAngle;
362
- }
363
- }
364
-
365
-
366
- __compassCoords(long, lat, radius, stepAngle, centerID, outBucket) {
367
-
368
- const Dlong = Degree * long;
369
- const Dlat = Degree * lat;
370
-
371
- const R = 6371.0 * 1000;
372
- const { coords, coordsZ, attribs } = outBucket;
373
- const { globe } = this;
374
- const radianRadius = radius / R;
375
- const scale = Math.cos(lat);
376
- { // add 0
377
- const x = Dlong + Degree * (radianRadius * Math.cos(Math.PI / 2));
378
- const y = Dlat + Degree * (radianRadius * Math.sin(Math.PI / 2) * scale);
379
- coords.push(x, y);
380
- coordsZ.push(0);
381
- const key = this._key(centerID, 0);
382
- attribs.push({
383
- "__fid__": key,
384
- "aci": "K"
385
- })
386
- }
387
- let aci = stepAngle;
388
- let i = 1;
389
- const RStep = stepAngle / Degree;
390
- for (let cstep = Math.PI / 2 - RStep; cstep > -Math.PI * 1.5; cstep -= RStep) {
391
- if (aci >= 360) break;
392
- const x = Dlong + Degree * (radianRadius * Math.cos(cstep));
393
- const y = Dlat + Degree * (radianRadius * Math.sin(cstep) * scale);
394
- coords.push(x, y);
395
- coordsZ.push(0);
396
- const key = this._key(centerID, i++);
397
- attribs.push({
398
- "__fid__": key,
399
- "aci": Math.floor(aci).toString()
400
- })
401
- aci += stepAngle;
402
- }
403
- }
404
-
405
-
406
- _updateData(bucket, mode) {
407
- this.ObjectArray.UpdateData(this.object, mode, [bucket], { attribs: false, icon: false, text: false });
408
- }
409
-
410
-
411
- _key(centerRingKey, limpIndex) {
412
- return `${centerRingKey}_${limpIndex}`;
413
- }
414
-
415
- _fillDeleteBucket(centerID, outDeleteBucket) {
416
-
417
- const centerMap = this._centerCollection.get(centerID);
418
- const stepAngle = centerMap.get("stepAngle");
419
- const { coords, coordsZ, attribs } = outDeleteBucket;
420
- let i = 0;
421
- for (let aci = 0; aci < 360; aci += stepAngle) {
422
- const key = this._key(centerID, i++);
423
- coords.push(0, 0);
424
- coordsZ.push(0);
425
- attribs.push({
426
- "__fid__": key,
427
- });
428
- }
429
- }
430
-
431
- _updateAll() {
432
- const updateBucket = {
433
- coords: [],
434
- coordsZ: [],
435
- attribs: []
436
- }
437
- for (const [centerID, centerMap] of this._centerCollection) {
438
- const isHidden = centerMap.get("hide") === ENUM_HIDE.HIDE || centerMap.get("textHide") === ENUM_TEXT_HIDE.HIDE;
439
- if (isHidden) continue;
440
- const x = centerMap.get("x");
441
- const y = centerMap.get("y");
442
- const maxRadius = centerMap.get("maxRadius");
443
- const stepAngle = centerMap.get("stepAngle");
444
- this._appendCircle(x, y, maxRadius, stepAngle, centerID, updateBucket);
445
- }
446
- this._updateData(updateBucket, CSObjectArrayUpdateTypes.UPDATE);
447
- }
448
-
449
- }
450
-
451
-
452
- const readCoords = (long, lat, radius, stepAngle) => {
453
-
454
- const result = []
455
- const degree = radius / R;
456
-
457
- return result;
458
- }
459
-
460
-
461
-
462
-
463
- const R = 6371.0;
464
-
465
- const flatCircle = (longitude, latitude, radius, paddingAngles) => {
466
- const degree = radius / R;
467
- const points = [];
468
-
469
- for (const angle of paddingAngles) {
470
- const x = longitude + degree * Math.cos(angle);
471
- const y = latitude + degree * Math.sin(angle);
472
- points.push({ long: x, lat: y });
473
- }
474
- return points;
475
- }
476
-
477
- const realCircle = (globe, longitude, latitude, radius, stepAngle) => {
478
- const pointsLongLat = globe.Math.GetEllipseGeo(
479
- longitude,
480
- latitude,
481
- radius,
482
- radius,
483
- 0,
484
- stepAngle);
485
- return pointsLongLat;
486
- }