bruce-cesium 0.2.0 → 0.2.1

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.
@@ -717,6 +717,10 @@
717
717
  if (!displayType) {
718
718
  displayType = bruceModels.ZoomControl.EDisplayType.Hidden;
719
719
  }
720
+ // Backwards compatibility.
721
+ else if (displayType == "polygon") {
722
+ displayType = bruceModels.ZoomControl.EDisplayType.Geometry;
723
+ }
720
724
  if (displayType != bruceModels.ZoomControl.EDisplayType.Hidden) {
721
725
  newRenderId = getRenderGroupId(zoomItem);
722
726
  existing = getExistingCEntity(id, params.menuItemId, zoomItem, params.visualRegister);
@@ -1663,7 +1667,7 @@
1663
1667
  }
1664
1668
  }
1665
1669
  }
1666
- function updateEntity(viewer, entityRegos) {
1670
+ function updateEntity(viewer, entityRegos, addons) {
1667
1671
  var highestPriority = null;
1668
1672
  for (var i = 0; i < entityRegos.length; i++) {
1669
1673
  var rego = entityRegos[i];
@@ -1673,7 +1677,14 @@
1673
1677
  }
1674
1678
  for (var i = 0; i < entityRegos.length; i++) {
1675
1679
  var rego = entityRegos[i];
1676
- updateEntityShow(viewer, rego.visual, rego === highestPriority);
1680
+ var show = rego === highestPriority;
1681
+ updateEntityShow(viewer, rego.visual, show);
1682
+ }
1683
+ if (addons) {
1684
+ for (var j = 0; j < addons.length; j++) {
1685
+ var addon = addons[j];
1686
+ addon.Render(entityRegos.map(function (x) { return x.visual; }));
1687
+ }
1677
1688
  }
1678
1689
  }
1679
1690
  function markEntity(register, rego, visual) {
@@ -1777,6 +1788,7 @@
1777
1788
  this.rego = {};
1778
1789
  this.onUpdate = null;
1779
1790
  this.selectedIds = [];
1791
+ this.addons = {};
1780
1792
  this.viewer = viewer;
1781
1793
  }
1782
1794
  Object.defineProperty(Register.prototype, "Id", {
@@ -1796,6 +1808,40 @@
1796
1808
  enumerable: false,
1797
1809
  configurable: true
1798
1810
  });
1811
+ Register.prototype.AddAddon = function (entityId, addon) {
1812
+ if (!this.addons[entityId]) {
1813
+ this.addons[entityId] = [];
1814
+ }
1815
+ this.addons[entityId].push(addon);
1816
+ var regos = this.rego[entityId];
1817
+ if (regos) {
1818
+ addon.Render(regos.map(function (x) { return x.visual; }));
1819
+ }
1820
+ };
1821
+ Register.prototype.GetAddons = function (entityId) {
1822
+ return this.addons[entityId] || [];
1823
+ };
1824
+ Register.prototype.RemoveAddon = function (entityId, addonId) {
1825
+ var addons = this.addons[entityId];
1826
+ if (addons) {
1827
+ for (var i = 0; i < addons.length; i++) {
1828
+ if (addons[i].Id === addonId) {
1829
+ addons[i].Dispose();
1830
+ addons.splice(i, 1);
1831
+ break;
1832
+ }
1833
+ }
1834
+ }
1835
+ };
1836
+ Register.prototype.RemoveAddons = function (entityId) {
1837
+ var addons = this.addons[entityId];
1838
+ if (addons) {
1839
+ for (var i = 0; i < addons.length; i++) {
1840
+ addons[i].Dispose();
1841
+ }
1842
+ }
1843
+ this.addons[entityId] = [];
1844
+ };
1799
1845
  Register.prototype.Select = function (id) {
1800
1846
  if (this.selectedIds.indexOf(id) === -1) {
1801
1847
  this.selectedIds.push(id);
@@ -1845,7 +1891,7 @@
1845
1891
  entityRegos.push(rego);
1846
1892
  this.rego[entityId] = entityRegos;
1847
1893
  markEntity(this, rego, rego.visual);
1848
- updateEntity(this.viewer, this.rego[entityId]);
1894
+ updateEntity(this.viewer, this.rego[entityId], this.GetAddons(entityId));
1849
1895
  if (this.selectedIds.includes(entityId)) {
1850
1896
  select(rego.visual);
1851
1897
  }
@@ -1899,7 +1945,7 @@
1899
1945
  var doesInclude = this.rego[entityId].find(function (r) { return r.menuItemId === id; });
1900
1946
  if (doesInclude) {
1901
1947
  this.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== id; });
1902
- updateEntity(this.viewer, this.rego[entityId]);
1948
+ updateEntity(this.viewer, this.rego[entityId], this.GetAddons(entityId));
1903
1949
  }
1904
1950
  }
1905
1951
  }
@@ -1919,7 +1965,7 @@
1919
1965
  removeEntity(this.viewer, rego.visual);
1920
1966
  this.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId; });
1921
1967
  if (_doUpdate) {
1922
- updateEntity(this.viewer, this.rego[entityId]);
1968
+ updateEntity(this.viewer, this.rego[entityId], this.GetAddons(entityId));
1923
1969
  }
1924
1970
  };
1925
1971
  /**
@@ -3703,7 +3749,179 @@
3703
3749
  ViewRenderEngine.Render = Render;
3704
3750
  })(exports.ViewRenderEngine || (exports.ViewRenderEngine = {}));
3705
3751
 
3752
+ function createContainer(viewer) {
3753
+ if (!viewer.canvas.parentElement) {
3754
+ return null;
3755
+ }
3756
+ var container = document.createElement("div");
3757
+ container.setAttribute("style", "\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n ");
3758
+ viewer.canvas.parentElement.appendChild(container);
3759
+ return container;
3760
+ }
3761
+ function destroyContainer(container) {
3762
+ if ((container === null || container === void 0 ? void 0 : container.parentElement) && container.parentElement.contains(container)) {
3763
+ container.parentElement.removeChild(container);
3764
+ }
3765
+ }
3766
+ var MPolyline;
3767
+ (function (MPolyline) {
3768
+ function Render(container, viewer, entity) {
3769
+ var _a;
3770
+ var items = [];
3771
+ if ((_a = entity.polyline) === null || _a === void 0 ? void 0 : _a.positions) {
3772
+ var pointsUnk = entity.polyline.positions;
3773
+ if (pointsUnk.getValue) {
3774
+ pointsUnk = pointsUnk.getValue(viewer.scene.lastRenderTime);
3775
+ }
3776
+ var points = pointsUnk;
3777
+ if (points && points.length) {
3778
+ var totalLength = 0;
3779
+ for (var i = 0; i < points.length; i++) {
3780
+ var p1 = points[i];
3781
+ var p2 = points[i + 1];
3782
+ if (p1 && p2) {
3783
+ totalLength += Cesium.Cartesian3.distance(p1, p2);
3784
+ }
3785
+ }
3786
+ if (totalLength <= 0) {
3787
+ return items;
3788
+ }
3789
+ var center = DrawingUtils.PointAcrossPolyline(viewer, points, totalLength / 2);
3790
+ var screenPos = viewer.scene.cartesianToCanvasCoordinates(center);
3791
+ if (screenPos) {
3792
+ var element = document.createElement("div");
3793
+ element.setAttribute("style", "\n position: absolute;\n top: " + screenPos.y + "px;\n left: " + screenPos.x + "px;\n color: white;\n font-size: 14px;\n z-index: 1;\n padding: 4px 6px;\n border-radius: 3px;\n background-color: black;\n color: white;\n ");
3794
+ var text = bruceModels.MathUtils.Round(totalLength, 3) + "m";
3795
+ element.innerText = text;
3796
+ var bounds = element.getBoundingClientRect();
3797
+ element.style.marginLeft = (-bounds.width / 2) + "px";
3798
+ element.style.marginTop = (-bounds.height - 10) + "px";
3799
+ container.appendChild(element);
3800
+ items.push({ element: element, text: text });
3801
+ }
3802
+ }
3803
+ }
3804
+ return items;
3805
+ }
3806
+ MPolyline.Render = Render;
3807
+ })(MPolyline || (MPolyline = {}));
3808
+ var MPoint;
3809
+ (function (MPoint) {
3810
+ function Render(container, viewer, entity) {
3811
+ var items = [];
3812
+ if (entity === null || entity === void 0 ? void 0 : entity.position) {
3813
+ var posUnk = entity.position;
3814
+ if (posUnk.getValue) {
3815
+ posUnk = posUnk.getValue(viewer.scene.lastRenderTime);
3816
+ }
3817
+ var pos = posUnk;
3818
+ if (!(pos === null || pos === void 0 ? void 0 : pos.x)) {
3819
+ return items;
3820
+ }
3821
+ var screenPos = viewer.scene.cartesianToCanvasCoordinates(pos);
3822
+ if (screenPos) {
3823
+ var element = document.createElement("div");
3824
+ element.setAttribute("style", "\n position: absolute;\n top: " + screenPos.y + "px;\n left: " + screenPos.x + "px;\n color: white;\n font-size: 14px;\n z-index: 1;\n padding: 4px 6px;\n border-radius: 3px;\n background-color: black;\n color: white;\n ");
3825
+ var point = Cesium.Cartographic.fromCartesian(pos);
3826
+ var lat = bruceModels.MathUtils.Round(Cesium.Math.toDegrees(point.latitude), 4);
3827
+ var lon = bruceModels.MathUtils.Round(Cesium.Math.toDegrees(point.longitude), 4);
3828
+ var alt = bruceModels.MathUtils.Round(Cesium.Math.toDegrees(point.height), 3);
3829
+ var text = lat + ", " + lon + ", " + alt;
3830
+ element.innerText = text;
3831
+ var bounds = element.getBoundingClientRect();
3832
+ element.style.marginLeft = (-bounds.width / 2) + "px";
3833
+ element.style.marginTop = (-bounds.height - 30) + "px";
3834
+ container.appendChild(element);
3835
+ items.push({ element: element, text: text });
3836
+ }
3837
+ }
3838
+ return items;
3839
+ }
3840
+ MPoint.Render = Render;
3841
+ })(MPoint || (MPoint = {}));
3842
+ function findVisual(visuals) {
3843
+ visuals.sort(function (a, b) {
3844
+ if (a.show && !b.show) {
3845
+ return -1;
3846
+ }
3847
+ if (!a.show && b.show) {
3848
+ return 1;
3849
+ }
3850
+ return 0;
3851
+ });
3852
+ for (var i = 0; i < visuals.length; i++) {
3853
+ var visual = visuals[i];
3854
+ if (visual instanceof Cesium.Entity) {
3855
+ return visual;
3856
+ }
3857
+ }
3858
+ return null;
3859
+ }
3860
+ /**
3861
+ * Measure addon will render measurement details on the position of the 3d object.
3862
+ * For example it will add lengths to the line segments of a polyline.
3863
+ */
3864
+ var MeasureAddon = /** @class */ (function () {
3865
+ function MeasureAddon(viewer) {
3866
+ var _this = this;
3867
+ this.Id = bruceModels.ObjectUtils.UId();
3868
+ this.visual = null;
3869
+ this.items = [];
3870
+ this.container = null;
3871
+ this.viewer = viewer;
3872
+ this.cRenderListener = this.viewer.scene.postRender.addEventListener(function () {
3873
+ _this.updateQueue.Call();
3874
+ });
3875
+ this.updateQueue = new bruceModels.DelayQueue(function () {
3876
+ _this.doUpdate();
3877
+ }, 1000 / 60);
3878
+ }
3879
+ MeasureAddon.prototype.doUpdate = function () {
3880
+ if (!this.container) {
3881
+ this.container = createContainer(this.viewer);
3882
+ }
3883
+ this.Remove();
3884
+ if (!this.container) {
3885
+ return;
3886
+ }
3887
+ var visual = this.visual;
3888
+ if (visual instanceof Cesium.Entity) {
3889
+ var entity = visual;
3890
+ if (entity.polyline) {
3891
+ this.items = MPolyline.Render(this.container, this.viewer, entity);
3892
+ }
3893
+ else if (entity.point) {
3894
+ this.items = MPoint.Render(this.container, this.viewer, entity);
3895
+ }
3896
+ }
3897
+ };
3898
+ MeasureAddon.prototype.Render = function (visuals) {
3899
+ var newVisual = findVisual(visuals);
3900
+ if (newVisual != this.visual) {
3901
+ this.Remove();
3902
+ }
3903
+ this.visual = newVisual;
3904
+ this.updateQueue.Call(true);
3905
+ };
3906
+ MeasureAddon.prototype.Remove = function () {
3907
+ var _a;
3908
+ for (var i = 0; i < this.items.length; i++) {
3909
+ var item = this.items[i];
3910
+ if (((_a = item.element) === null || _a === void 0 ? void 0 : _a.parentElement) && item.element.parentElement.contains(item.element)) {
3911
+ item.element.parentElement.removeChild(item.element);
3912
+ }
3913
+ }
3914
+ this.items = [];
3915
+ };
3916
+ MeasureAddon.prototype.Dispose = function () {
3917
+ this.cRenderListener();
3918
+ destroyContainer(this.container);
3919
+ };
3920
+ return MeasureAddon;
3921
+ }());
3922
+
3706
3923
  exports.CesiumViewMonitor = CesiumViewMonitor;
3924
+ exports.MeasureAddon = MeasureAddon;
3707
3925
 
3708
3926
  Object.defineProperty(exports, '__esModule', { value: true });
3709
3927