bruce-cesium 6.9.2 → 6.9.4

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,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, HeightReference, ColorBlendMode, HeadingPitchRoll, Math as Math$1, Transforms, ShadowMode, Cartesian3, ClassificationType, Model, ArcType, CornerType, ConstantPositionProperty, JulianDate, Quaternion, Matrix4, HorizontalOrigin, VerticalOrigin, Cartesian2, SceneTransforms, NearFarScalar, Matrix3, Rectangle, KmlDataSource, PolygonHierarchy, PolylineGraphics, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, OrthographicFrustum, EasingFunction, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, Cesium3DTileset, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, Cesium3DTileColorBlendMode, PolygonPipeline, CesiumInspector, ClockRange, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere, GeometryInstance, Fullscreen, Intersect, CzmlDataSource } from 'cesium';
3
- import { Cartes, Entity as Entity$1, ENVIRONMENT, Calculator, ClientFile, EntityLod, EntityTag, EntityType, LRUCache, ObjectUtils, Style, Carto, Geometry, Api, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, BruceEvent, EntityCoords, Bounds, DataLab, DelayQueue, EntityHistoricData, BruceApi, EntityRelation, ProgramKey, EntitySource, ProjectViewLegacyTile, ProjectViewTile, Camera, AccountConcept, RecordChangeFeed, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, Session, EntityRelationType } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, HeightReference, ColorBlendMode, HeadingPitchRoll, Math as Math$1, Transforms, ShadowMode, Cartesian3, ClassificationType, Model, ArcType, CornerType, ConstantPositionProperty, HorizontalOrigin, VerticalOrigin, JulianDate, Quaternion, Matrix4, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Cartesian2, SceneTransforms, NearFarScalar, Matrix3, Rectangle, KmlDataSource, GeoJsonDataSource, SceneMode, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, OrthographicFrustum, EasingFunction, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, CesiumInspector, ClockRange, BoundingSphere, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, Intersect, CzmlDataSource } from 'cesium';
3
+ import { Cartes, Entity as Entity$1, ENVIRONMENT, Calculator, ClientFile, EntityLod, EntityTag, EntityType, LRUCache, ObjectUtils, Style, Carto, Geometry, Api, Bounds, Color as Color$1, MenuItem, ProjectView, ProjectViewBookmark, Tileset, ZoomControl, BruceEvent, EntityCoords, DataLab, DelayQueue, EntityHistoricData, AccountConcept, RecordChangeFeed, BruceApi, EntityRelation, ProgramKey, EntitySource, Camera, ProjectViewTile, ProjectViewLegacyTile, Session, EntityAttachment, EntityAttachmentType, EntityAttribute, MathUtils, EntityRelationType } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -36664,7 +36664,7 @@ function getHeightRef$2(style, defaultStyle) {
36664
36664
 
36665
36665
  var EntityRenderEnginePolygon;
36666
36666
  (function (EntityRenderEnginePolygon) {
36667
- function Render(params) {
36667
+ async function Render(params) {
36668
36668
  var _a, _b;
36669
36669
  const entity = params.entity;
36670
36670
  const pRings = Entity$1.GetValue({
@@ -36675,9 +36675,26 @@ var EntityRenderEnginePolygon;
36675
36675
  return null;
36676
36676
  }
36677
36677
  const style = params.style;
36678
+ const fillType = style.fillType || Style.EPolygonFillType.Color;
36678
36679
  const fillColorTrace = style.fillColor ? Calculator.TraceGetColor(style.fillColor, entity, params.tags) : { value: null, effective: null };
36679
36680
  const bFillColor = fillColorTrace.value;
36680
36681
  const cFillColor = bFillColor ? ColorToCColor(bFillColor) : Color.fromCssColorString("rgba(139, 195, 74, 0.8)");
36682
+ let textureDataUri = null;
36683
+ let textureTraceEffective = null;
36684
+ if (fillType === Style.EPolygonFillType.Texture) {
36685
+ const resolved = await resolveTexturedFill({
36686
+ api: params.api,
36687
+ style,
36688
+ entity,
36689
+ tags: params.tags
36690
+ });
36691
+ textureDataUri = resolved.dataUri;
36692
+ textureTraceEffective = resolved.effective;
36693
+ }
36694
+ const hasFill = fillType === Style.EPolygonFillType.Texture ? Boolean(textureDataUri) : cFillColor.alpha > 0;
36695
+ const fillMaterial = textureDataUri
36696
+ ? new ImageMaterialProperty({ image: textureDataUri, transparent: true })
36697
+ : cFillColor;
36681
36698
  const lineColorTrace = style.lineColor ? Calculator.TraceGetColor(style.lineColor, entity, params.tags) : { value: null, effective: null };
36682
36699
  const bLineColor = lineColorTrace.value;
36683
36700
  const cLineColor = bLineColor ? ColorToCColor(bLineColor) : Color.fromCssColorString("rgba(80, 80, 80, 0.8)");
@@ -36696,7 +36713,7 @@ var EntityRenderEnginePolygon;
36696
36713
  }
36697
36714
  // If both outline and fill is not available then don't render anything.
36698
36715
  if ((width <= 0 || cLineColor.alpha <= 0) &&
36699
- cFillColor.alpha <= 0) {
36716
+ !hasFill) {
36700
36717
  return null;
36701
36718
  }
36702
36719
  let heightRef = getHeightRef$3(style);
@@ -36751,7 +36768,7 @@ var EntityRenderEnginePolygon;
36751
36768
  id: ObjectUtils.UId(15),
36752
36769
  polygon: {
36753
36770
  hierarchy: new PolygonHierarchy(posses, holePosses.map(x => new PolygonHierarchy(x))),
36754
- material: cFillColor,
36771
+ material: fillMaterial,
36755
36772
  extrudedHeight: extrusion.value,
36756
36773
  extrudedHeightReference: extrusion.exHeightRef,
36757
36774
  shadows: ShadowMode.ENABLED,
@@ -36816,15 +36833,21 @@ var EntityRenderEnginePolygon;
36816
36833
  cEntity.polygon.distanceDisplayCondition = new ConstantProperty(EntityRenderEngine.GetDisplayCondition(params.minDistance, params.maxDistance, width <= 0 || !cLineColor || units == "m" ? size : null, true));
36817
36834
  cEntity.polygon.shadows = new ConstantProperty(ShadowMode.ENABLED);
36818
36835
  cEntity.polygon.classificationType = new ConstantProperty(classification);
36819
- // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
36820
- // WARNING: polygon does not support animation (yet?).
36821
- CesiumEntityStyler.SetDefaultColor({
36822
- color: cFillColor,
36823
- entity: cEntity,
36824
- viewer: params.viewer,
36825
- override: true,
36826
- requestRender: false
36827
- });
36836
+ // TODO: animate the texture!
36837
+ if (textureDataUri) {
36838
+ cEntity.polygon.material = fillMaterial;
36839
+ }
36840
+ else {
36841
+ // We'll use "SetDefaultColor" to updating the internal reference and to allow for an animation.
36842
+ // WARNING: polygon does not support animation (yet?).
36843
+ CesiumEntityStyler.SetDefaultColor({
36844
+ color: cFillColor,
36845
+ entity: cEntity,
36846
+ viewer: params.viewer,
36847
+ override: true,
36848
+ requestRender: false
36849
+ });
36850
+ }
36828
36851
  cEntity.show = true;
36829
36852
  }
36830
36853
  if (hasOutline) {
@@ -36972,6 +36995,7 @@ var EntityRenderEnginePolygon;
36972
36995
  }
36973
36996
  cEntity.styleEffective = StyleEffective.Combine([
36974
36997
  { key: "color", effective: fillColorTrace.effective },
36998
+ { key: "texture", effective: textureTraceEffective },
36975
36999
  { key: "lineColor", effective: lineColorTrace.effective },
36976
37000
  { key: "lineWidth", effective: lineWidthTrace.effective }
36977
37001
  ]);
@@ -37023,11 +37047,12 @@ var EntityRenderEnginePolygon;
37023
37047
  }
37024
37048
  }
37025
37049
  const pStyle = (_b = style === null || style === void 0 ? void 0 : style.polygonStyle) !== null && _b !== void 0 ? _b : {};
37026
- const cEntity = Render({
37050
+ const cEntity = await Render({
37027
37051
  entity: entity,
37028
37052
  style: pStyle,
37029
37053
  tags: tags,
37030
37054
  viewer: params.viewer,
37055
+ api,
37031
37056
  maxDistance: zoomItem.MaxZoom,
37032
37057
  minDistance: zoomItem.MinZoom,
37033
37058
  // Temporarily disabling re-using graphics for polygons as they have some bugs, and
@@ -37145,6 +37170,101 @@ async function getStyle$4(api, entity, styleId) {
37145
37170
  }
37146
37171
  return style;
37147
37172
  }
37173
+ // Cache of tinted texture data URIs, keyed by resolved url + color mask, so repeated renders of the
37174
+ // same polygon (or multiple polygons sharing a texture) don't refetch/reprocess the same image.
37175
+ const _textureCache = new LRUCache(50);
37176
+ /**
37177
+ * Returns if a resolved texture value looks like a URL rather than a client file ID.
37178
+ * @param value
37179
+ */
37180
+ function looksLikeTextureUrl(value) {
37181
+ return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value) || value.startsWith("//") || value.startsWith("data:");
37182
+ }
37183
+ /**
37184
+ * Resolves a polygon style's texture field and if a color ask is needed it tints the resulting image.
37185
+ * @param params
37186
+ */
37187
+ async function resolveTexturedFill(params) {
37188
+ const { api, style, entity, tags } = params;
37189
+ let textureRows = style.texture == null ? [] : style.texture;
37190
+ textureRows.forEach((row) => {
37191
+ if (row.type == Calculator.EValueType.Color) {
37192
+ row.type = Calculator.EValueType.Input;
37193
+ }
37194
+ });
37195
+ const textureTrace = textureRows.length ? Calculator.TraceGetString(textureRows, entity, tags) : { value: null, effective: null };
37196
+ const raw = textureTrace.value;
37197
+ if (!raw || typeof raw != "string" || !api) {
37198
+ return { dataUri: null, effective: textureTrace.effective };
37199
+ }
37200
+ let url = raw;
37201
+ if (!looksLikeTextureUrl(raw)) {
37202
+ await api.Loading;
37203
+ url = ClientFile.GetUrl({
37204
+ api,
37205
+ fileId: raw,
37206
+ viaCdn: true
37207
+ });
37208
+ }
37209
+ const mask = style.textureColorMask;
37210
+ const cacheKey = "texture-" + url + "-" + (mask ? mask.type + "-" + mask.minColor + "-" + mask.maxColor : "none");
37211
+ let prom = _textureCache.Get(cacheKey);
37212
+ if (!prom) {
37213
+ prom = buildTintedTextureDataUri(url, mask).catch(() => null);
37214
+ _textureCache.Set(cacheKey, prom);
37215
+ }
37216
+ return { dataUri: await prom, effective: textureTrace.effective };
37217
+ }
37218
+ /**
37219
+ * Fetches an image and, if a color mask is provided, remaps its (assumed grayscale) pixel values
37220
+ * into a gradient between the mask's minColor/maxColor, preserving source alpha.
37221
+ * @param url
37222
+ * @param mask
37223
+ */
37224
+ async function buildTintedTextureDataUri(url, mask) {
37225
+ const response = await fetch(url);
37226
+ const blob = await response.blob();
37227
+ const objectUrl = URL.createObjectURL(blob);
37228
+ let image;
37229
+ try {
37230
+ image = await loadImage(objectUrl);
37231
+ }
37232
+ finally {
37233
+ URL.revokeObjectURL(objectUrl);
37234
+ }
37235
+ const canvas = document.createElement("canvas");
37236
+ canvas.width = image.width;
37237
+ canvas.height = image.height;
37238
+ const context = canvas.getContext("2d");
37239
+ context.drawImage(image, 0, 0);
37240
+ if (mask && mask.type === Style.ETextureColorMaskType.BlackWhite) {
37241
+ const minColor = Color$1.ColorFromStr(mask.minColor) || { red: 0, green: 0, blue: 0, alpha: 1 };
37242
+ const maxColor = Color$1.ColorFromStr(mask.maxColor) || { red: 255, green: 255, blue: 255, alpha: 1 };
37243
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
37244
+ const data = imageData.data;
37245
+ for (let i = 0; i < data.length; i += 4) {
37246
+ // The texture is rendered black-to-white server-side, so any channel carries the value.
37247
+ const t = data[i] / 255;
37248
+ data[i] = Math.round(minColor.red + (maxColor.red - minColor.red) * t);
37249
+ data[i + 1] = Math.round(minColor.green + (maxColor.green - minColor.green) * t);
37250
+ data[i + 2] = Math.round(minColor.blue + (maxColor.blue - minColor.blue) * t);
37251
+ // Preserve source transparency (eg unrasterized pixels) blended with the mask's own alpha.
37252
+ const srcAlpha = data[i + 3] / 255;
37253
+ const maskAlpha = minColor.alpha + (maxColor.alpha - minColor.alpha) * t;
37254
+ data[i + 3] = Math.round(srcAlpha * maskAlpha * 255);
37255
+ }
37256
+ context.putImageData(imageData, 0, 0);
37257
+ }
37258
+ return canvas.toDataURL("image/png");
37259
+ }
37260
+ function loadImage(src) {
37261
+ return new Promise((res, rej) => {
37262
+ const image = new Image();
37263
+ image.onload = () => res(image);
37264
+ image.onerror = (e) => rej(e);
37265
+ image.src = src;
37266
+ });
37267
+ }
37148
37268
  /**
37149
37269
  * Compares two color materials.
37150
37270
  * Returns if they are equal.
@@ -38445,7 +38565,7 @@ var StyleUtils;
38445
38565
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
38446
38566
  })(StyleUtils || (StyleUtils = {}));
38447
38567
 
38448
- const VERSION = "6.9.2";
38568
+ const VERSION = "6.9.4";
38449
38569
  /**
38450
38570
  * Updates the environment instance used by bruce-cesium to one specified.
38451
38571
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.