@loaders.gl/i3s 3.1.0-alpha.3 → 4.0.0-alpha.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.
Files changed (39) hide show
  1. package/dist/i3s-attribute-loader.js +44 -14
  2. package/dist/i3s-attribute-loader.js.map +1 -1
  3. package/dist/i3s-building-scene-layer-loader.js +21 -0
  4. package/dist/i3s-building-scene-layer-loader.js.map +1 -0
  5. package/dist/i3s-content-loader.js +1 -1
  6. package/dist/i3s-content-worker.js +7549 -2
  7. package/dist/i3s-loader.js +5 -2
  8. package/dist/i3s-loader.js.map +1 -1
  9. package/dist/i3s-node-page-loader.js +1 -1
  10. package/dist/index.js +2 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/lib/helpers/i3s-nodepages-tiles.js +27 -20
  13. package/dist/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  14. package/dist/lib/parsers/constants.js +8 -0
  15. package/dist/lib/parsers/constants.js.map +1 -1
  16. package/dist/lib/parsers/parse-i3s-attribute.js +9 -1
  17. package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -1
  18. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +43 -0
  19. package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  20. package/dist/lib/parsers/parse-i3s-tile-content.js +49 -32
  21. package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  22. package/dist/lib/parsers/parse-i3s.js +4 -4
  23. package/dist/lib/parsers/parse-i3s.js.map +1 -1
  24. package/dist/lib/utils/url-utils.js +3 -3
  25. package/dist/lib/utils/url-utils.js.map +1 -1
  26. package/package.json +13 -11
  27. package/src/i3s-attribute-loader.ts +56 -19
  28. package/src/i3s-building-scene-layer-loader.ts +34 -0
  29. package/src/i3s-loader.ts +4 -1
  30. package/src/index.ts +2 -0
  31. package/src/lib/helpers/i3s-nodepages-tiles.ts +28 -12
  32. package/src/lib/parsers/constants.ts +22 -0
  33. package/src/lib/parsers/parse-i3s-attribute.ts +19 -1
  34. package/src/lib/parsers/parse-i3s-building-scene-layer.ts +57 -0
  35. package/src/lib/parsers/parse-i3s-tile-content.ts +51 -31
  36. package/src/types.ts +102 -6
  37. package/dist/dist.min.js +0 -2
  38. package/dist/dist.min.js.map +0 -1
  39. package/dist/i3s-content-worker.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { load } from '@loaders.gl/core';
2
2
  import { parseI3STileAttribute } from './lib/parsers/parse-i3s-attribute';
3
3
  import { getUrlWithToken } from './lib/utils/url-utils';
4
- const VERSION = typeof "3.1.0-alpha.3" !== 'undefined' ? "3.1.0-alpha.3" : 'latest';
4
+ const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'latest';
5
5
  const EMPTY_VALUE = '';
6
6
  const REJECTED_STATUS = 'rejected';
7
7
  export const I3SAttributeLoader = {
@@ -24,7 +24,8 @@ async function parse(data, options) {
24
24
  export async function loadFeatureAttributes(tile, featureId, options = {}) {
25
25
  const {
26
26
  attributeStorageInfo,
27
- attributeUrls
27
+ attributeUrls,
28
+ tilesetFields
28
29
  } = getAttributesData(tile);
29
30
 
30
31
  if (!attributeStorageInfo || !attributeUrls || !featureId) {
@@ -56,15 +57,19 @@ export async function loadFeatureAttributes(tile, featureId, options = {}) {
56
57
  return null;
57
58
  }
58
59
 
59
- return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId);
60
+ return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
60
61
  }
61
62
 
62
63
  function getAttributesData(tile) {
63
- const attributeStorageInfo = tile && tile.tileset && tile.tileset.tileset && tile.tileset.tileset.attributeStorageInfo;
64
- const attributeUrls = tile && tile.header && tile.header.attributeUrls;
64
+ var _tile$tileset, _tile$tileset$tileset, _tile$header, _tile$tileset2, _tile$tileset2$tilese;
65
+
66
+ const attributeStorageInfo = (_tile$tileset = tile.tileset) === null || _tile$tileset === void 0 ? void 0 : (_tile$tileset$tileset = _tile$tileset.tileset) === null || _tile$tileset$tileset === void 0 ? void 0 : _tile$tileset$tileset.attributeStorageInfo;
67
+ const attributeUrls = (_tile$header = tile.header) === null || _tile$header === void 0 ? void 0 : _tile$header.attributeUrls;
68
+ const tilesetFields = ((_tile$tileset2 = tile.tileset) === null || _tile$tileset2 === void 0 ? void 0 : (_tile$tileset2$tilese = _tile$tileset2.tileset) === null || _tile$tileset2$tilese === void 0 ? void 0 : _tile$tileset2$tilese.fields) || [];
65
69
  return {
66
70
  attributeStorageInfo,
67
- attributeUrls
71
+ attributeUrls,
72
+ tilesetFields
68
73
  };
69
74
  }
70
75
 
@@ -78,34 +83,48 @@ function getAttributeValueType(attribute) {
78
83
  return '';
79
84
  }
80
85
 
81
- function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId) {
82
- const objectIds = attributes.find(attribute => attribute.value.OBJECTID);
86
+ function getFeatureIdsAttributeName(attributeStorageInfo) {
87
+ const objectIdsAttribute = attributeStorageInfo.find(attribute => attribute.name.includes('OBJECTID'));
88
+ return objectIdsAttribute === null || objectIdsAttribute === void 0 ? void 0 : objectIdsAttribute.name;
89
+ }
90
+
91
+ function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
92
+ const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
93
+ const objectIds = attributes.find(attribute => attribute.value[objectIdsAttributeName]);
83
94
 
84
95
  if (!objectIds) {
85
96
  return null;
86
97
  }
87
98
 
88
- const attributeIndex = objectIds.value.OBJECTID.indexOf(featureId);
99
+ const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
89
100
 
90
101
  if (attributeIndex < 0) {
91
102
  return null;
92
103
  }
93
104
 
94
- return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo);
105
+ return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
95
106
  }
96
107
 
97
- function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo) {
108
+ function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
98
109
  const attributesObject = {};
99
110
 
100
111
  for (let index = 0; index < attributeStorageInfo.length; index++) {
101
112
  const attributeName = attributeStorageInfo[index].name;
113
+ const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
102
114
  const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
103
- attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex);
115
+ attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
104
116
  }
105
117
 
106
118
  return attributesObject;
107
119
  }
108
120
 
121
+ function getAttributeCodedValues(attributeName, tilesetFields) {
122
+ var _attributeField$domai;
123
+
124
+ const attributeField = tilesetFields.find(field => field.name === attributeName || field.alias === attributeName);
125
+ return (attributeField === null || attributeField === void 0 ? void 0 : (_attributeField$domai = attributeField.domain) === null || _attributeField$domai === void 0 ? void 0 : _attributeField$domai.codedValues) || [];
126
+ }
127
+
109
128
  function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
110
129
  const attributeObject = attributes[index];
111
130
 
@@ -116,7 +135,18 @@ function getAttributeByIndexAndAttributeName(attributes, index, attributesName)
116
135
  return attributeObject.value[attributesName];
117
136
  }
118
137
 
119
- function formatAttributeValue(attribute, featureIdIndex) {
120
- return attribute && attribute[featureIdIndex] ? attribute[featureIdIndex].toString().replace(/\u0000/g, '').trim() : EMPTY_VALUE;
138
+ function formatAttributeValue(attribute, featureIdIndex, codedValues) {
139
+ let value = EMPTY_VALUE;
140
+
141
+ if (attribute && featureIdIndex in attribute) {
142
+ value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, '').trim();
143
+ }
144
+
145
+ if (codedValues.length) {
146
+ const codeValue = codedValues.find(codedValue => codedValue.code === Number(value));
147
+ value = (codeValue === null || codeValue === void 0 ? void 0 : codeValue.name) || EMPTY_VALUE;
148
+ }
149
+
150
+ return value;
121
151
  }
122
152
  //# sourceMappingURL=i3s-attribute-loader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/i3s-attribute-loader.ts"],"names":["load","parseI3STileAttribute","getUrlWithToken","VERSION","EMPTY_VALUE","REJECTED_STATUS","I3SAttributeLoader","name","id","module","version","mimeTypes","parse","extensions","options","binary","data","loadFeatureAttributes","tile","featureId","attributeStorageInfo","attributeUrls","getAttributesData","attributes","attributeLoadPromises","index","length","url","i3s","token","attributeName","attributeType","getAttributeValueType","loadOptions","promise","push","Promise","allSettled","error","generateAttributesByFeatureId","tileset","header","attribute","hasOwnProperty","attributeValues","valueType","objectIds","find","value","OBJECTID","attributeIndex","indexOf","getFeatureAttributesByIndex","featureIdIndex","attributesObject","getAttributeByIndexAndAttributeName","formatAttributeValue","attributesName","attributeObject","status","toString","replace","trim"],"mappings":"AACA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,qBAAR,QAAoC,mCAApC;AACA,SAAQC,eAAR,QAA8B,uBAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AACA,MAAMC,WAAW,GAAG,EAApB;AACA,MAAMC,eAAe,GAAG,UAAxB;AAIA,OAAO,MAAMC,kBAAoC,GAAG;AAClDC,EAAAA,IAAI,EAAE,eAD4C;AAElDC,EAAAA,EAAE,EAAE,eAF8C;AAGlDC,EAAAA,MAAM,EAAE,KAH0C;AAIlDC,EAAAA,OAAO,EAAEP,OAJyC;AAKlDQ,EAAAA,SAAS,EAAE,CAAC,oBAAD,CALuC;AAMlDC,EAAAA,KANkD;AAOlDC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPsC;AAQlDC,EAAAA,OAAO,EAAE,EARyC;AASlDC,EAAAA,MAAM,EAAE;AAT0C,CAA7C;;AAYP,eAAeH,KAAf,CAAqBI,IAArB,EAA2BF,OAA3B,EAAoC;AAClCE,EAAAA,IAAI,GAAGf,qBAAqB,CAACe,IAAD,EAAOF,OAAP,CAA5B;AACA,SAAOE,IAAP;AACD;;AAUD,OAAO,eA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AzB;;AAEA,OAAK,IAAI7B,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGL,oBAAoB,CAACM,MAAjD,EAAyDD,KAAK,EAA9D,EAAkE;AAChE,UAAMK,aAAa,GAAGV,oBAAoB,CAACK,KAAD,CAApB,CAA4BlB,IAAlD;AACA,UAAMmC,SAAS,GAAGa,mCAAmC,CAAChC,UAAD,EAAaE,KAAb,EAAoBK,aAApB,CAArD;AACAwB,IAAAA,gBAAgB,CAACxB,aAAD,CAAhB,GAAkC0B,oBAAoB,CAACd,SAAD,EAAYW,cAAZ,CAAtD;AACD;;AAED,SAAOC,gBAAP;AACD;;AAQD,SAASC,mCAAT,CAA6ChC,UAA7C,EAAyDE,KAAzD,EAAgEgC,cAAhE,EAAgF;AAC9E,QAAMC,eAAe,GAAGnC,UAAU,CAACE,KAAD,CAAlC;;AAEA,MAAIiC,eAAe,CAACC,MAAhB,KAA2BtD,eAA/B,EAAgD;AAC9C,WAAO,IAAP;AACD;;AAED,SAAOqD,eAAe,CAACV,KAAhB,CAAsBS,cAAtB,CAAP;AACD;;AAQD,SAASD,oBAAT,CAA8Bd,SAA9B,EAAyCW,cAAzC,EAAyD;AACvD,SAAOX,SAAS,IAAIA,SAAS,CAACW,cAAD,CAAtB,GACHX,SAAS,CAACW,cAAD,CAAT,CACCO,QADD,GAGCC,OAHD,CAGS,SAHT,EAGoB,EAHpB,EAICC,IAJD,EADG,GAMH1D,WANJ;AAOD","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {load} from '@loaders.gl/core';\nimport {parseI3STileAttribute} from './lib/parsers/parse-i3s-attribute';\nimport {getUrlWithToken} from './lib/utils/url-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\nconst EMPTY_VALUE = '';\nconst REJECTED_STATUS = 'rejected';\n/**\n * Loader for I3S attributes\n */\nexport const I3SAttributeLoader: LoaderWithParser = {\n name: 'I3S Attribute',\n id: 'i3s-attribute',\n module: 'i3s',\n version: VERSION,\n mimeTypes: ['application/binary'],\n parse,\n extensions: ['bin'],\n options: {},\n binary: true\n};\n\nasync function parse(data, options) {\n data = parseI3STileAttribute(data, options);\n return data;\n}\n\n/**\n * Load attributes based on feature id\n * @param {Object} tile\n * @param {number} featureId\n * @param {Object} options\n * @returns {Promise}\n */\n// eslint-disable-next-line complexity\nexport async function loadFeatureAttributes(tile, featureId, options = {}) {\n const {attributeStorageInfo, attributeUrls} = getAttributesData(tile);\n\n if (!attributeStorageInfo || !attributeUrls || !featureId) {\n return null;\n }\n\n let attributes: object[] = [];\n const attributeLoadPromises: Promise<object>[] = [];\n\n for (let index = 0; index < attributeStorageInfo.length; index++) {\n // @ts-ignore\n const url = getUrlWithToken(attributeUrls[index], options.i3s?.token);\n const attributeName = attributeStorageInfo[index].name;\n const attributeType = getAttributeValueType(attributeStorageInfo[index]);\n const loadOptions = {...options, attributeName, attributeType};\n const promise = load(url, I3SAttributeLoader, loadOptions);\n\n attributeLoadPromises.push(promise);\n }\n try {\n attributes = await Promise.allSettled(attributeLoadPromises);\n } catch (error) {\n // do nothing\n }\n\n if (!attributes.length) {\n return null;\n }\n\n return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId);\n}\n\nfunction getAttributesData(tile) {\n const attributeStorageInfo =\n tile && tile.tileset && tile.tileset.tileset && tile.tileset.tileset.attributeStorageInfo;\n const attributeUrls = tile && tile.header && tile.header.attributeUrls;\n\n return {attributeStorageInfo, attributeUrls};\n}\n\n/**\n * Get attribute value type based on property names\n * @param {Object} attribute\n * @returns {String}\n */\nfunction getAttributeValueType(attribute) {\n if (attribute.hasOwnProperty('objectIds')) {\n return 'Oid32';\n } else if (attribute.hasOwnProperty('attributeValues')) {\n return attribute.attributeValues.valueType;\n }\n return '';\n}\n\n/**\n * Generates mapping featureId to feature attributes\n * @param {Array} attributes\n * @param {Object} attributeStorageInfo\n * @param {number} featureId\n * @returns {Object}\n */\nfunction generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId) {\n const objectIds = attributes.find((attribute) => attribute.value.OBJECTID);\n\n if (!objectIds) {\n return null;\n }\n\n const attributeIndex = objectIds.value.OBJECTID.indexOf(featureId);\n\n if (attributeIndex < 0) {\n return null;\n }\n\n return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo);\n}\n\n/**\n * Generates attribute object for feature mapping by feature id\n * @param {Array} attributes\n * @param {Number} featureIdIndex\n * @param {Object} attributeStorageInfo\n * @returns {Object}\n */\nfunction getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo) {\n const attributesObject = {};\n\n for (let index = 0; index < attributeStorageInfo.length; index++) {\n const attributeName = attributeStorageInfo[index].name;\n const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);\n attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex);\n }\n\n return attributesObject;\n}\n\n/**\n * Return attribute value if it presents in atrributes list\n * @param {array} attributes\n * @param {number} index\n * @param {string} attributesName\n */\nfunction getAttributeByIndexAndAttributeName(attributes, index, attributesName) {\n const attributeObject = attributes[index];\n\n if (attributeObject.status === REJECTED_STATUS) {\n return null;\n }\n\n return attributeObject.value[attributesName];\n}\n\n/**\n * Do formatting of attribute values or return empty string.\n * @param {Array} attribute\n * @param {Number} featureIdIndex\n * @returns {String}\n */\nfunction formatAttributeValue(attribute, featureIdIndex) {\n return attribute && attribute[featureIdIndex]\n ? attribute[featureIdIndex]\n .toString()\n // eslint-disable-next-line no-control-regex\n .replace(/\\u0000/g, '')\n .trim()\n : EMPTY_VALUE;\n}\n"],"file":"i3s-attribute-loader.js"}
1
+ {"version":3,"sources":["../src/i3s-attribute-loader.ts"],"names":["load","parseI3STileAttribute","getUrlWithToken","VERSION","EMPTY_VALUE","REJECTED_STATUS","I3SAttributeLoader","name","id","module","version","mimeTypes","parse","extensions","options","binary","data","loadFeatureAttributes","tile","featureId","attributeStorageInfo","attributeUrls","tilesetFields","getAttributesData","attributes","attributeLoadPromises","index","length","url","i3s","token","attributeName","attributeType","getAttributeValueType","loadOptions","promise","push","Promise","allSettled","error","generateAttributesByFeatureId","tileset","header","fields","attribute","hasOwnProperty","attributeValues","valueType","getFeatureIdsAttributeName","objectIdsAttribute","find","includes","objectIdsAttributeName","objectIds","value","attributeIndex","indexOf","getFeatureAttributesByIndex","featureIdIndex","attributesObject","codedValues","getAttributeCodedValues","getAttributeByIndexAndAttributeName","formatAttributeValue","attributeField","field","alias","domain","attributesName","attributeObject","status","String","replace","trim","codeValue","codedValue","code","Number"],"mappings":"AACA,SAAQA,IAAR,QAAmB,kBAAnB;AACA,SAAQC,qBAAR,QAAoC,mCAApC;AACA,SAAQC,eAAR,QAA8B,uBAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AACA,MAAMC,WAAW,GAAG,EAApB;AACA,MAAMC,eAAe,GAAG,UAAxB;AAIA,OAAO,MAAMC,kBAAoC,GAAG;AAClDC,EAAAA,IAAI,EAAE,eAD4C;AAElDC,EAAAA,EAAE,EAAE,eAF8C;AAGlDC,EAAAA,MAAM,EAAE,KAH0C;AAIlDC,EAAAA,OAAO,EAAEP,OAJyC;AAKlDQ,EAAAA,SAAS,EAAE,CAAC,oBAAD,CALuC;AAMlDC,EAAAA,KANkD;AAOlDC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPsC;AAQlDC,EAAAA,OAAO,EAAE,EARyC;AASlDC,EAAAA,MAAM,EAAE;AAT0C,CAA7C;;AAYP,eAAeH,KAAf,CAAqBI,IAArB,EAA2BF,OAA3B,EAAoC;AAClCE,EAAAA,IAAI,GAAGf,qBAAqB,CAACe,IAAD,EAAOF,OAAP,CAA5B;AACA,SAAOE,IAAP;AACD;;AAUD,OAAO,eAAeC,qBAAf,CAAqCC,IAArC,EAA2CC,SAA3C,EAAsDL,OAAO,GAAG,EAAhE,EAAoE;AACzE,QAAM;AAACM,I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,cAAhE,EAAgF;AAC9E,QAAMC,eAAe,GAAG7C,UAAU,CAACE,KAAD,CAAlC;;AAEA,MAAI2C,eAAe,CAACC,MAAhB,KAA2BjE,eAA/B,EAAgD;AAC9C,WAAO,IAAP;AACD;;AAED,SAAOgE,eAAe,CAACf,KAAhB,CAAsBc,cAAtB,CAAP;AACD;;AAQD,SAASL,oBAAT,CAA8BnB,SAA9B,EAAyCc,cAAzC,EAAyDE,WAAzD,EAAsE;AACpE,MAAIN,KAAK,GAAGlD,WAAZ;;AAEA,MAAIwC,SAAS,IAAKc,cAAc,IAAId,SAApC,EAAgD;AAE9CU,IAAAA,KAAK,GAAGiB,MAAM,CAAC3B,SAAS,CAACc,cAAD,CAAV,CAAN,CAAkCc,OAAlC,CAA0C,aAA1C,EAAyD,EAAzD,EAA6DC,IAA7D,EAAR;AACD;;AAGD,MAAIb,WAAW,CAACjC,MAAhB,EAAwB;AACtB,UAAM+C,SAAS,GAAGd,WAAW,CAACV,IAAZ,CAAiByB,UAAU,IAAIA,UAAU,CAACC,IAAX,KAAoBC,MAAM,CAACvB,KAAD,CAAzD,CAAlB;AACAA,IAAAA,KAAK,GAAG,CAAAoB,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAEnE,IAAX,KAAmBH,WAA3B;AACD;;AAED,SAAOkD,KAAP;AACD","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {load} from '@loaders.gl/core';\nimport {parseI3STileAttribute} from './lib/parsers/parse-i3s-attribute';\nimport {getUrlWithToken} from './lib/utils/url-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\nconst EMPTY_VALUE = '';\nconst REJECTED_STATUS = 'rejected';\n/**\n * Loader for I3S attributes\n */\nexport const I3SAttributeLoader: LoaderWithParser = {\n name: 'I3S Attribute',\n id: 'i3s-attribute',\n module: 'i3s',\n version: VERSION,\n mimeTypes: ['application/binary'],\n parse,\n extensions: ['bin'],\n options: {},\n binary: true\n};\n\nasync function parse(data, options) {\n data = parseI3STileAttribute(data, options);\n return data;\n}\n\n/**\n * Load attributes based on feature id\n * @param {Object} tile\n * @param {number} featureId\n * @param {Object} options\n * @returns {Promise}\n */\n// eslint-disable-next-line complexity\nexport async function loadFeatureAttributes(tile, featureId, options = {}) {\n const {attributeStorageInfo, attributeUrls, tilesetFields} = getAttributesData(tile);\n\n if (!attributeStorageInfo || !attributeUrls || !featureId) {\n return null;\n }\n\n let attributes: object[] = [];\n const attributeLoadPromises: Promise<object>[] = [];\n\n for (let index = 0; index < attributeStorageInfo.length; index++) {\n // @ts-ignore\n const url = getUrlWithToken(attributeUrls[index], options.i3s?.token);\n const attributeName = attributeStorageInfo[index].name;\n const attributeType = getAttributeValueType(attributeStorageInfo[index]);\n const loadOptions = {...options, attributeName, attributeType};\n const promise = load(url, I3SAttributeLoader, loadOptions);\n\n attributeLoadPromises.push(promise);\n }\n try {\n attributes = await Promise.allSettled(attributeLoadPromises);\n } catch (error) {\n // do nothing\n }\n\n if (!attributes.length) {\n return null;\n }\n\n return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);\n}\n\n/**\n * Gets attributes data from tile.\n * @param tile \n * @returns \n */\nfunction getAttributesData(tile) {\n const attributeStorageInfo = tile.tileset?.tileset?.attributeStorageInfo;\n const attributeUrls = tile.header?.attributeUrls;\n const tilesetFields = tile.tileset?.tileset?.fields || [];\n\n return {attributeStorageInfo, attributeUrls, tilesetFields};\n}\n\n/**\n * Get attribute value type based on property names\n * @param {Object} attribute\n * @returns {String}\n */\nfunction getAttributeValueType(attribute) {\n if (attribute.hasOwnProperty('objectIds')) {\n return 'Oid32';\n } else if (attribute.hasOwnProperty('attributeValues')) {\n return attribute.attributeValues.valueType;\n }\n return '';\n}\n\n/**\n * Find in attributeStorageInfo attribute name responsible for feature ids list.\n * @param attributeStorageInfo \n * @returns Feature ids attribute name\n */\nfunction getFeatureIdsAttributeName(attributeStorageInfo) {\n const objectIdsAttribute = attributeStorageInfo.find(attribute => attribute.name.includes('OBJECTID'));\n\n return objectIdsAttribute?.name;\n}\n\n/**\n * Generates mapping featureId to feature attributes\n * @param {Array} attributes\n * @param {Object} attributeStorageInfo\n * @param {number} featureId\n * @returns {Object}\n */\nfunction generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {\n const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);\n const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);\n\n if (!objectIds) {\n return null;\n }\n\n const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);\n\n if (attributeIndex < 0) {\n return null;\n }\n\n return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);\n}\n\n/**\n * Generates attribute object for feature mapping by feature id\n * @param {Array} attributes\n * @param {Number} featureIdIndex\n * @param {Object} attributeStorageInfo\n * @returns {Object}\n */\nfunction getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {\n const attributesObject = {};\n\n for (let index = 0; index < attributeStorageInfo.length; index++) {\n const attributeName = attributeStorageInfo[index].name;\n const codedValues = getAttributeCodedValues(attributeName, tilesetFields);\n const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);\n attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);\n }\n\n return attributesObject;\n}\n\n/**\n * Get coded values list from tileset.\n * @param attributeName \n * @param tilesetFields \n */\nfunction getAttributeCodedValues(attributeName, tilesetFields) {\n const attributeField = tilesetFields\n .find(field => field.name === attributeName || field.alias === attributeName);\n\n return attributeField?.domain?.codedValues || [];\n}\n\n/**\n * Return attribute value if it presents in atrributes list\n * @param {array} attributes\n * @param {number} index\n * @param {string} attributesName\n */\nfunction getAttributeByIndexAndAttributeName(attributes, index, attributesName) {\n const attributeObject = attributes[index];\n\n if (attributeObject.status === REJECTED_STATUS) {\n return null;\n }\n\n return attributeObject.value[attributesName];\n}\n\n/**\n * Do formatting of attribute values or return empty string.\n * @param {Array} attribute\n * @param {Number} featureIdIndex\n * @returns {String}\n */\nfunction formatAttributeValue(attribute, featureIdIndex, codedValues) {\n let value = EMPTY_VALUE;\n\n if (attribute && (featureIdIndex in attribute)) {\n // eslint-disable-next-line no-control-regex\n value = String(attribute[featureIdIndex]).replace(/\\u0000|NaN/g, '').trim();\n }\n\n // Check if coded values are existed. If so we use them.\n if (codedValues.length) {\n const codeValue = codedValues.find(codedValue => codedValue.code === Number(value));\n value = codeValue?.name || EMPTY_VALUE;\n }\n\n return value;\n}\n"],"file":"i3s-attribute-loader.js"}
@@ -0,0 +1,21 @@
1
+ import { parseBuildingSceneLayer } from './lib/parsers/parse-i3s-building-scene-layer';
2
+ const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'beta';
3
+ export const I3SBuildingSceneLayerLoader = {
4
+ name: 'I3S Building Scene Layer',
5
+ id: 'i3s-building-scene-layer',
6
+ module: 'i3s',
7
+ version: VERSION,
8
+ mimeTypes: ['application/json'],
9
+ parse,
10
+ extensions: ['json'],
11
+ options: {}
12
+ };
13
+
14
+ async function parse(data, options, context) {
15
+ if (!(context !== null && context !== void 0 && context.url)) {
16
+ throw new Error('Url is not provided');
17
+ }
18
+
19
+ return parseBuildingSceneLayer(data, context.url);
20
+ }
21
+ //# sourceMappingURL=i3s-building-scene-layer-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/i3s-building-scene-layer-loader.ts"],"names":["parseBuildingSceneLayer","VERSION","I3SBuildingSceneLayerLoader","name","id","module","version","mimeTypes","parse","extensions","options","data","context","url","Error"],"mappings":"AAGA,SAAQA,uBAAR,QAAsC,8CAAtC;AAKA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,MAAnE;AAIA,OAAO,MAAMC,2BAA6C,GAAG;AAC3DC,EAAAA,IAAI,EAAE,0BADqD;AAE3DC,EAAAA,EAAE,EAAE,0BAFuD;AAG3DC,EAAAA,MAAM,EAAE,KAHmD;AAI3DC,EAAAA,OAAO,EAAEL,OAJkD;AAK3DM,EAAAA,SAAS,EAAE,CAAC,kBAAD,CALgD;AAM3DC,EAAAA,KAN2D;AAO3DC,EAAAA,UAAU,EAAE,CAAC,MAAD,CAP+C;AAQ3DC,EAAAA,OAAO,EAAE;AARkD,CAAtD;;AAWP,eAAeF,KAAf,CACEG,IADF,EAEED,OAFF,EAGEE,OAHF,EAIsC;AACpC,MAAI,EAACA,OAAD,aAACA,OAAD,eAACA,OAAO,CAAEC,GAAV,CAAJ,EAAmB;AACjB,UAAM,IAAIC,KAAJ,CAAU,qBAAV,CAAN;AACD;;AAED,SAAOd,uBAAuB,CAACW,IAAD,EAAOC,OAAO,CAACC,GAAf,CAA9B;AACD","sourcesContent":["import type {LoaderWithParser, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';\nimport type {BuildingSceneLayerTileset} from './types';\n\nimport {parseBuildingSceneLayer} from './lib/parsers/parse-i3s-building-scene-layer';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\n\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'beta';\n/**\n * Loader for I3S - Building Scene Layer\n */\nexport const I3SBuildingSceneLayerLoader: LoaderWithParser = {\n name: 'I3S Building Scene Layer',\n id: 'i3s-building-scene-layer',\n module: 'i3s',\n version: VERSION,\n mimeTypes: ['application/json'],\n parse,\n extensions: ['json'],\n options: {}\n};\n\nasync function parse(\n data: ArrayBuffer,\n options?: LoaderOptions,\n context?: LoaderContext\n): Promise<BuildingSceneLayerTileset> {\n if (!context?.url) {\n throw new Error('Url is not provided');\n }\n\n return parseBuildingSceneLayer(data, context.url);\n}\n"],"file":"i3s-building-scene-layer-loader.js"}
@@ -1,5 +1,5 @@
1
1
  import { parseI3STileContent } from './lib/parsers/parse-i3s-tile-content';
2
- const VERSION = typeof "3.1.0-alpha.3" !== 'undefined' ? "3.1.0-alpha.3" : 'beta';
2
+ const VERSION = typeof "4.0.0-alpha.4" !== 'undefined' ? "4.0.0-alpha.4" : 'beta';
3
3
  export const I3SContentLoader = {
4
4
  name: 'I3S Content (Indexed Scene Layers)',
5
5
  id: 'i3s-content',