This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bedrock_viz.js
3149 lines (2786 loc) · 107 KB
/
bedrock_viz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
var map = null, projection = null, extent = null;
var popover = null;
var globalMousePosition = null;
var pixelData = null, pixelDataName = '';
var layerRawIndex = 63;
var layerMain = null, srcLayerMain = null;
var layerSlimeChunks = null, srcLayerSlimeChunks = null;
var measureControl = null;
var mousePositionControl = null;
var globalDimensionId = -1;
var globalLayerMode = 0, globalLayerId = 0;
var globalStyleBlock = null, globalStyleBlockUp = null, globalStyleBlockDown = null, globalStyleBlockSame = null;
var listEntityToggle = [];
var listTileEntityToggle = [];
var listBlockToggle = [];
var spawnableEnableFlag = false;
var globalCORSWarning = 'If you are loading files from the local filesystem, your browser might not be allowing us to load additional files or examine pixels in maps. Firefox does not have this limitation. See README for more info...';
var globalCORSWarningFlag = false;
var globalItemStyleSelector = null;
var globalItemStyleCount = 0;
var globalWarnSlimeChunks = false;
var showChunkCoordinatesFlag = false;
var chunkGridFlag = false;
var showNetherCoordinatesFlag = false;
var doCheckPlayerDistanceFlag = false;
// this removes the hideous blurriness when zoomed in
var setCanvasSmoothingMode = function(evt) {
evt.context.mozImageSmoothingEnabled = false;
evt.context.webkitImageSmoothingEnabled = false;
evt.context.msImageSmoothingEnabled = false;
evt.context.imageSmoothingEnabled = false;
};
var resetCanvasSmoothingMode = function(evt) {
evt.context.mozImageSmoothingEnabled = true;
evt.context.webkitImageSmoothingEnabled = true;
evt.context.msImageSmoothingEnabled = true;
evt.context.imageSmoothingEnabled = true;
};
var disableLayerSmoothing = function(layer) {
layer.on('precompose', setCanvasSmoothingMode);
layer.on('postcompose', resetCanvasSmoothingMode);
};
function map_addLayer(layer) {
var a = map.getLayers();
var insertIndex = -1;
// todo - check for not defined myStackOrder
// current myStackOrder values:
// 000 map.addLayer(layerMain);
// 100 map.addLayer(layerShadedReliefStatic);
// 110 map.addLayer(layerElevation);
// 120 map.addLayer(layerElevationAlpha);
// 200 map.addLayer(layerChunkGrid);
// 210 map.addLayer(layerSlimeChunks);
// 300 map.addLayer(vectorPoints);
// 400 map.addLayer(layerDraw);
var layerStackOrder = +layer.get('myStackOrder');
a.forEach( function (el, index, arr) {
var elStackOrder = +el.get('myStackOrder');
if ( (elStackOrder > layerStackOrder) && (insertIndex < 0) ) {
insertIndex = index;
}
});
if ( insertIndex < 0 ) {
insertIndex = a.getLength();
}
map.getLayers().insertAt(insertIndex, layer);
// debug
if ( false ) {
a = map.getLayers();
a.forEach( function (el, index, arr) {
console.log('layer: index=' + index + ' myStackOrder=' + el.get('myStackOrder') + ' obj=' + el);
});
}
}
/**
* @constructor
* @param {ol.Map} xmap
*/
var MeasureTool = function(xmap) {
var this_ = this;
var map = xmap;
var sourceDraw = null;
var layerDraw = null;
var overlays = [];
/**
* Currently drawn feature.
* @type {ol.Feature}
*/
var sketch;
/**
* The help tooltip element.
* @type {Element}
*/
var helpTooltipElement;
/**
* Overlay to show the help messages.
* @type {ol.Overlay}
*/
var helpTooltip;
/**
* The measure tooltip element.
* @type {Element}
*/
var measureTooltipElement;
/**
* Overlay to show the measurement.
* @type {ol.Overlay}
*/
var measureTooltip;
/**
* Handle pointer move.
* @param {ol.MapBrowserEvent} evt
*/
var pointerMoveHandler = function(evt) {
if (evt.dragging) {
return;
}
/** @type {string} */
var helpMsg = 'Click to start drawing; Press ESC to quit measurement mode';
if (sketch) {
var geom = (sketch.getGeometry());
if (geom instanceof ol.geom.Polygon) {
helpMsg = 'Click to continue drawing the polygon; Double Click to complete';
} else if (geom instanceof ol.geom.LineString) {
helpMsg = 'Click to continue drawing the line; Double Click to complete';
} else if (geom instanceof ol.geom.Circle) {
helpMsg = 'Click to complete circle';
}
}
helpTooltipElement.innerHTML = helpMsg;
helpTooltip.setPosition(evt.coordinate);
$(helpTooltipElement).removeClass('hidden');
};
var hideHelpTooltip = function() {
$(helpTooltipElement).addClass('hidden');
};
/**
* format length output
* @param {ol.geom.LineString} line
* @return {string}
*/
var formatLength = function(line) {
var length = Math.round(line.getLength() * 100) / 100;
var output;
if (length > 1000) {
output = (Math.round(length / 1000 * 100) / 100) +
' ' + 'km';
} else {
output = (Math.round(length * 100) / 100) +
' ' + 'm';
}
return output;
};
/**
* format circle radius output
* @param {ol.geom.Circle} circle
* @return {string}
*/
var formatRadius = function(circle) {
var length = Math.round(circle.getRadius() * 100) / 100;
var output;
if (length > 1000) {
output = (Math.round(length / 1000 * 100) / 100) +
' ' + 'km';
} else {
output = (Math.round(length * 100) / 100) +
' ' + 'm';
}
return output;
};
/**
* format length output
* @param {ol.geom.Polygon} polygon
* @return {string}
*/
var formatArea = function(polygon) {
var area = polygon.getArea();
var output;
if (area > 10000) {
output = (Math.round(area / 1000000 * 100) / 100) +
' ' + 'km<sup>2</sup>';
} else {
output = (Math.round(area * 100) / 100) +
' ' + 'm<sup>2</sup>';
}
return output;
};
/**
* Creates a new help tooltip
*/
var createHelpTooltip = function() {
if (helpTooltipElement) {
helpTooltipElement.parentNode.removeChild(helpTooltipElement);
}
helpTooltipElement = document.createElement('div');
helpTooltipElement.className = 'measureTooltip hidden';
helpTooltip = new ol.Overlay({
element: helpTooltipElement,
offset: [15, 0],
positioning: 'center-left'
});
overlays.push(helpTooltip);
map.addOverlay(helpTooltip);
};
/**
* Creates a new measure tooltip
*/
var createMeasureTooltip = function() {
if (measureTooltipElement) {
measureTooltipElement.parentNode.removeChild(measureTooltipElement);
}
measureTooltipElement = document.createElement('div');
measureTooltipElement.className = 'measureTooltip measureTooltip-measure';
measureTooltip = new ol.Overlay({
element: measureTooltipElement,
offset: [0, -15],
positioning: 'bottom-center'
});
overlays.push(measureTooltip);
map.addOverlay(measureTooltip);
};
var drawType = 'LineString';
var draw;
var createInteraction = function() {
draw = new ol.interaction.Draw({
source: sourceDraw,
type: /** @type {ol.geom.GeometryType} */ (drawType)
/*
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 0.5)',
lineDash: [3, 3],
width: 2
}),
image: new ol.style.Circle({
radius: 5,
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 0.7)'
}),
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
})
})
})
*/
});
map.addInteraction(draw);
createMeasureTooltip();
createHelpTooltip();
var listener;
draw.on('drawstart',
function(evt) {
// set sketch
sketch = evt.feature;
/** @type {ol.Coordinate|undefined} */
var tooltipCoord = evt.coordinate;
listener = sketch.getGeometry().on('change', function(evt) {
var geom = evt.target;
var output;
if (geom instanceof ol.geom.Polygon) {
output = formatArea(/** @type {ol.geom.Polygon} */ (geom));
tooltipCoord = geom.getInteriorPoint().getCoordinates();
} else if (geom instanceof ol.geom.LineString) {
output = formatLength( /** @type {ol.geom.LineString} */ (geom));
tooltipCoord = geom.getLastCoordinate();
// we move the coordinate slightly (this avoids the "not able to continue line" problem)
var res = map.getView().getResolution() * 1.5;
tooltipCoord[0] += res;
tooltipCoord[1] += res;
} else if (geom instanceof ol.geom.Circle) {
output = formatRadius( /** @type {ol.geom.Circle} */ (geom));
tooltipCoord = geom.getLastCoordinate();
} else {
//console.log("unknown geom type in sketch listener");
}
measureTooltipElement.innerHTML = output;
measureTooltip.setPosition(tooltipCoord);
}, this_);
}, this_);
draw.on('drawend',
function(evt) {
measureTooltipElement.className = 'measureTooltip measureTooltip-static';
measureTooltip.setOffset([0, -7]);
// unset sketch
sketch = null;
// unset tooltip so that a new one can be created
measureTooltipElement = null;
createMeasureTooltip();
ol.Observable.unByKey(listener);
return true;
}, this_);
};
/**
* Let user change the geometry type.
* @param {string} dt LineString, Circle, etc
*/
this.setDrawTypeReal = function(dt) {
sketch = null;
drawType = dt;
map.removeInteraction(draw);
createInteraction();
};
var updateState = function() {
if ( this_.enabled ) {
sourceDraw = new ol.source.Vector();
var width = 3;
var color = '#f22929';
layerDraw = new ol.layer.Vector({
myStackOrder: 400,
source: sourceDraw,
style: [
new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({ color: '#ffffff', width: width + 2 }),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: color
})
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({ color: color, width: width })
})
]
});
map_addLayer(layerDraw);
map.on('pointermove', pointerMoveHandler);
$(map.getViewport()).on('mouseout', hideHelpTooltip);
createInteraction();
} else {
map.removeLayer(layerDraw);
map.un('pointermove', pointerMoveHandler);
$(map.getViewport()).off('mouseout', hideHelpTooltip);
map.removeInteraction(draw);
map.removeOverlay(helpTooltip);
map.removeOverlay(measureTooltip);
// destroy objects so that they are removed from map
draw = null;
layerDraw = null;
sourceDraw = null;
for (var i in overlays) {
map.removeOverlay(overlays[i]);
overlays[i] = null;
}
overlays = [];
}
};
this.toggleEnable = function() {
this_.enabled = !this_.enabled;
updateState();
};
this.forceStart = function() {
this_.enabled = true;
updateState();
};
this.forceStop = function() {
this_.enabled = false;
updateState();
};
};
/**
* @param {string} dt draw type (e.g. "LineString", "Circle", etc)
*/
MeasureTool.prototype.setDrawType = function(dt) {
this.setDrawTypeReal(dt);
};
/**
* @return {boolean} true if measure control is active
*/
MeasureTool.prototype.isEnabled = function() {
//console.log('mt enabled = ' + this.enabled);
return this.enabled;
};
/**
* @constructor
* @extends {ol.control.Control}
* @param {Object=} opt_options Control options.
*/
var MeasureControl = function(opt_options) {
var options = opt_options || {};
//this.enabled = false;
var this_ = this;
this.measureTool = null;
var setDrawType = function(dt) {
this_.measureTool.setDrawType(dt);
};
this.handleMeasure = function(e) {
if ( this_.measureTool === null ) {
this_.measureTool = new MeasureTool(this_.getMap());
}
this_.measureTool.toggleEnable();
if (this_.measureTool.isEnabled()) {
$('.measureSubcontrol').show();
} else {
$('.measureSubcontrol').hide();
}
};
var button = document.createElement('button');
button.innerHTML = 'M';
button.addEventListener('click', this.handleMeasure, false);
button.addEventListener('touchstart', this.handleMeasure, false);
$(button).addClass('mytooltip inline-block').attr('title', 'Measurement Tools - Press ESC to quit');
var btnLine = document.createElement('button');
btnLine.innerHTML = 'L';
btnLine.addEventListener('click', function() { setDrawType('LineString'); }, false);
btnLine.addEventListener('touchstart', function() { setDrawType('LineString'); }, false);
$(btnLine).addClass('mytooltip measureSubcontrol inline-block').attr('title', 'Lines - Hotkey L').hide();
var btnCircle = document.createElement('button');
btnCircle.innerHTML = 'C';
btnCircle.addEventListener('click', function() { setDrawType('Circle'); }, false);
btnCircle.addEventListener('touchstart', function() { setDrawType('Circle'); }, false);
$(btnCircle).addClass('mytooltip measureSubcontrol inline-block').attr('title', 'Circles - Hotkey C').hide();
var element = document.createElement('div');
element.className = 'measure ol-unselectable ol-control';
element.appendChild(button);
element.appendChild(btnLine);
element.appendChild(btnCircle);
ol.control.Control.call(this, {
element: element,
target: options.target
});
};
ol.inherits(MeasureControl, ol.control.Control);
/**
* @return {boolean} true if measure control is active
*/
MeasureControl.prototype.isEnabled = function() {
if ( this.measureTool !== null ) {
return this.measureTool.isEnabled();
}
return false;
};
/**
* force measurement control to stop
*/
MeasureControl.prototype.forceStop = function() {
if ( this.isEnabled() ) {
this.handleMeasure();
}
};
/**
* force measurement tool to start and be in a particular drawing mode
* @param {string} dt drawing type
*/
MeasureControl.prototype.forceDrawType = function(dt) {
if ( ! this.isEnabled() ) {
this.handleMeasure();
}
this.measureTool.setDrawType(dt);
};
function doGlobalQuit() {
// user has pressed ESC - we want to quit any special modes
if (measureControl.isEnabled()) {
measureControl.forceStop();
}
// make popover disappear
var element = popover.getElement();
$(element).popover('destroy');
// todo - is this too broad?
$('.mytooltip_dyn').tooltip('hide');
$('.mytooltip').tooltip('hide');
// clear village doors
srcVillageVectorPoints.clear();
// todo - others?
}
var loadEventCount = 0;
function updateLoadEventCount(delta) {
loadEventCount += delta;
if (loadEventCount < 0) { loadEventCount = 0; }
if (loadEventCount > 0) {
var pos = $('#map').offset();
var x1 = pos.left + 70;
var y1 = pos.top + 20;
$('#throbber')
.css({ position: 'absolute', left: x1, top: y1 })
.show();
var a = [];
if (loadEventCount > 0) {
a.push('Layers remaining: ' + loadEventCount);
}
$('#throbber-msg').html(a.join('; '));
} else {
$('#throbber').hide();
}
}
function doParsedItem(obj, sortFlag) {
var v = [];
var vold = [];
for (var j in obj) {
if (obj[j].Name === 'info_reserved6') {
// swallow this - it is the player's hot slots
} else {
var s = '';
var fnimg = 'images/unknown.png';
if ( obj[j].imgid !== undefined ) {
fnimg = imageIconLUT['' + obj[j].imgid];
}
var title = obj[j].Name;
if (obj[j].Enchantments !== undefined) {
var ench = obj[j].Enchantments;
title += ' (';
var i = ench.length;
for (var k in ench) {
title += ench[k].Name;
if (--i > 0) {
title += '; ';
}
}
title += ')';
}
if (obj[j].Count !== undefined) {
if ( obj[j].Count > 1 ) {
title += ' (Qty: ' + obj[j].Count + ')';
}
}
// debug
//title += ' (' + fnimg + ') (' + obj[j].imgid + ')' + ' (' + j + ')';
s += '<div class="col-xs-1 mytooltip_dyn inventory-grid" title="' + title + '">';
s += '<img class="pull-left inventory-item-image" height="32" width="32" src="' + fnimg + '" />';
if (obj[j].Count !== undefined) {
s += '<span class="inventory-item-count">' + obj[j].Count + '</span>';
// s += obj[j].Count;
}
s += '</div>';
v.push(s);
// old version:
s = '<li>' + obj[j].Name;
if (obj[j].Count !== undefined) {
s += ' (' + obj[j].Count + ')';
}
if (obj[j].Enchantments !== undefined) {
var ench = obj[j].Enchantments;
s += ' (';
var i = ench.length;
for (var k in ench) {
s += ench[k].Name;
if (--i > 0) {
s += '; ';
}
}
s += ')';
}
s += '</li>';
vold.push(s);
}
}
// we sort the items, yay
if (sortFlag) {
v.sort();
vold.sort();
}
var ct = globalItemStyleCount++;
var ret = '<div class="myTabsContainer">' +
'<div role="group">' +
'<ul class="nav nav-pills btn-group myTabs" role="tablist">' +
'<li role="presentation"><a href="#itemsIcon' + ct + '" data-id="itemsIcon" class="itemsViewToggle itemsIcon" aria-controls="itemsIcon' + ct + '" role="tab" data-toggle="tab">Icons</a></li>' +
'<li role="presentation"><a href="#itemsText' + ct + '" data-id="itemsText" class="itemsViewToggle itemsText" aria-controls="itemsText' + ct + '" role="tab" data-toggle="tab">Text</a></li>' +
'</ul>' +
'</div>' +
'<div class="tab-content">';
// icon version
ret += '<div role="tabpanel" class="tab-pane" id="itemsIcon' + ct + '">';
ret += '<div class="container-fluid"><div class="row-fluid">';
for (var i = 0; i < v.length; i++) {
ret += v[i];
if ( ((i + 1) % 8) == 0 ) {
ret += '</div><div class="row-fluid">';
}
}
ret += '</div></div></div>';
// text list version
ret += '<div role="tabpanel" class="tab-pane" id="itemsText' + ct + '">';
ret += '<div class="container-fluid"><ul>';
ret += vold.join('\n');
ret += '</ul></div></div>';
ret += '</div></div>';
return ret;
}
// adapted from: http://openlayers.org/en/v3.9.0/examples/vector-layer.html
// todo - this does not work?
var highlightStyleCache = {};
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
map: map,
style: function(feature, resolution) {
var text = resolution < 5000 ? feature.get('Name') : '';
if (!highlightStyleCache[text]) {
highlightStyleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#f00',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.1)'
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#f00',
width: 3
})
})
})];
}
return highlightStyleCache[text];
}
});
// given coords in mcpe world, return coords for openlayers
function mcpeToOpenlayers(tx, ty, adjustToCenterFlag) {
var px = tx - dimensionInfo[globalDimensionId].globalOffsetX;
var py = (dimensionInfo[globalDimensionId].worldHeight - 1 - ty) + dimensionInfo[globalDimensionId].globalOffsetY;
if ( adjustToCenterFlag ) {
px += 0.5;
py += 0.5;
}
return [ px, py ];
}
// given coords in openlayers, return coords for mcpe world
function openlayersToMcpe(tx, ty, adjustToCenterFlag) {
var px = tx + dimensionInfo[globalDimensionId].globalOffsetX;
// todo - is this correct?
var py = (dimensionInfo[globalDimensionId].worldHeight - 1 - ty) + dimensionInfo[globalDimensionId].globalOffsetY;
if ( adjustToCenterFlag ) {
px += 0.5;
py += 0.5;
}
return [ px, py ];
}
function correctGeoJSONName(feature) {
var name = feature.get('Name');
if (name == 'MobSpawner') {
// rename spawner so that feature shows spawner type
var props = feature.getProperties();
name = props[name].Name + ' Spawner';
}
else if (name == 'NetherPortal') {
name = 'Nether Portal';
}
else if (name == 'Dropped item') {
// rename dropped item so that it is visible in map
var props = feature.getProperties();
name = 'Drop: ' + props.Item.Name;
// todo - highlight interesting drops? e.g. armor / weapons (i.e. indication of a player death spot)
}
else if (name == 'SignNonBlank' || name == 'SignBlank') {
// rename sign so that it is visible in map
var props = feature.getProperties();
var a = [];
var pushTrimmedString = function(a, str) {
if (str) {
var s = str.trim();
if (s.length > 0 ) {
a.push(s);
}
}
};
pushTrimmedString(a, props[name].Text1);
pushTrimmedString(a, props[name].Text2);
pushTrimmedString(a, props[name].Text3);
pushTrimmedString(a, props[name].Text4);
if ( a.length > 0 ) {
name = 'Sign: ' + a.join(' / ');
} else {
name = 'Sign';
}
}
else if (name == 'The Player') {
var props = feature.getProperties();
if ( props.playerType === 'Local Player' ) {
name = 'Local Player';
} else {
if ( props.playerName !== undefined ) {
name = props.playerType + ': ' + props.playerName;
} else {
name = props.playerType + ': ' + props.playerId;
}
}
}
return name;
}
function doParsedDoors(doors) {
// {"idx":0,"idz":-2,"ts":54461602,"Pos":[118,76,-45]},
var a = [];
for (var d in doors) {
var s = '';
s += '' + '<a href="#" class="layerGoto_dyn mytooltip_dyn" data-id="' + doors[d]['Pos'][1] + '" title="Click to go to layer">' + JSON.stringify(doors[d]['Pos'], null, 2) + '</a>';
s += ' : ' + doors[d]['ts'] + ' : ' + doors[d]['idx'] + ' ' + doors[d]['idz'];
// make "Pos" clickable if we have raw layers
a.push(s);
}
return a.join('<br/>');
}
function doFeaturePopover(features, id, coordinate) {
var feature = features[id];
var element = popover.getElement();
// todo - is this too broad?
$('.mytooltip_dyn').tooltip('hide');
$(element).popover('destroy');
var props = feature.getProperties();
var name = correctGeoJSONName(feature);
var stitle = '<div class="mob">';
// prev/next buttons
if ( features.length > 1 ) {
var enabled;
stitle += '<div class="btn-group btn-group-xs">';
enabled = (id > 0) ? '' : ' disabled';
stitle += '<a href="#" class="btn btn-primary btn-xs mytooltip_dyn featurePrev' + enabled + '" title="Previous"><strong><</strong></a>';
enabled = (id < (features.length - 1)) ? '' : ' disabled';
stitle += '<a href="#" class="btn btn-primary btn-xs mytooltip_dyn featureNext' + enabled + '" title="Next"><strong>></strong></a>';
stitle += '</div> ';
}
// mob/item title
if (props.Entity !== undefined) {
stitle += '<span class="mob_name">' + name + '</span> <span class="mob_id">(id=' + props.id + ')</span>';
} else {
stitle += '<span class="mob_name">' + name + '</span>';
}
stitle += '</div>';
if (name === 'Village') {
// remove old items
srcVillageVectorPoints.clear();
// add doors to map
for (var d in props['Doors']) {
var door = props['Doors'][d];
// adjust point to ol coordinates
var pts = mcpeToOpenlayers(door.Pos[0], door.Pos[2], true);
var pt = new ol.geom.Point( pts );
var feature = new ol.Feature({
name: 'Village Door',
geometry: pt
});
// copy properties (for popup)
for (var dp in door) {
feature.set(dp, door[dp], true);
}
feature.set('Name', 'Village Door');
featuresVillageVectorPoints.push(feature);
}
// add a bounding circle for the village
var cpts = mcpeToOpenlayers(props.Pos[0], props.Pos[2], true);
var fcircle = new ol.Feature({
name: 'Village Radius',
radius: props['radius'],
geometry: new ol.geom.Point( cpts ),
Pos: props.Pos,
Name: 'Village Radius'
});
featuresVillageVectorPoints.push(fcircle);
// todobig todohere - how to remove this?! (currently only escape key will do it)
}
var s = '<div class="container-fluid my-scrollable">';
for (var i in props) {
// skip geometry property because it contains circular refs; skip others that are uninteresting
if (i !== 'geometry' &&
i !== 'TileEntity' &&
i !== 'Entity' &&
i !== 'Block' &&
i !== 'pairchest' &&
i !== 'player' &&
i !== 'Name' &&
i !== 'id' &&
i !== 'etype' &&
i !== 'Dimension'
) {
if (typeof(props[i]) === 'object') {
if (i === 'Armor') {
var armor = props[i];
s += 'Armor:' + doParsedItem(armor, false);
}
else if (i === 'Items') {
// items in a chest
var items = props[i];
s += 'Items:' + doParsedItem(items, true);
}
else if (i === 'Inventory') {
var inventory = props[i];
s += 'Inventory:' + doParsedItem(inventory, true);
}
else if (i === 'EnderChest') {
var inventory = props[i];
s += 'Ender Chest Inventory:' + doParsedItem(inventory, true);
}
else if (i === 'ItemInHand') {
var itemInHand = props[i];
s += 'In Hand:' + doParsedItem([itemInHand], false);
}
else if (i === 'Item') {
var item = props[i];
s += 'Item:' + doParsedItem([item], false);
}
else if (i === 'Sign') {
s += '<div class="mycenter">' +
props[i].Text1 + '<br/>' +
props[i].Text2 + '<br/>' +
props[i].Text3 + '<br/>' +
props[i].Text4 + '<br/>' +
'</div>';
}
else if (i === 'Notes') {
for (var n in props[i]) {
s += 'Note: <b>' + props[i][n] + '</b><br/>';
}
}
else if (i === 'MobSpawner') {
s += '' +
'Name: <b>' + props[i].Name + '</b><br/>' +
'entityId: <b>' + props[i].entityId + '</b><br/>';
}
// Village-specific stuff
else if ( i === 'APos' ) {
// hide it
}
else if ( i === 'Doors' ) {
s += 'Door Count: <b>' + props[i].length + '</b><br/>';
s += 'Doors (Pos : TS : IDX IDZ):<br/><div class="my-indent">' + doParsedDoors(props[i]) + '</div>';
}
else if ( i === 'Players' ) {
// todo - more info here? i've never seen this filled
s += 'Players Count: <b>' + props[i].length + '</b><br/>';
}
else if ( i === 'Villagers' ) {
s += 'Villager Count: <b>' + props[i].length + '</b><br/>';
}
else if (i === 'Pos') {
// make "Pos" clickable if we have raw layers
s += '' + i + ': <a href="#" class="layerGoto_dyn mytooltip_dyn" data-id="' + props[i][1] + '" title="Click to go to layer">' + JSON.stringify(props[i], null, 2) + '</a><br/>';
}
else {
s += '' + i + ': ' + JSON.stringify(props[i], null, 2) + '<br/>';
}
} else {
s += '' + i + ': <b>' + props[i].toString() + '</b><br/>';
}
}
}
s += '</div>';
popover.setPosition(coordinate);
$(element).popover({
'placement': 'auto right',
'viewport': {selector: '#map', padding: 0},
'animation': false,
'trigger': 'click focus',
'html': true,
'title': stitle,