@ino-cesium/analysis 0.0.13 → 0.0.14

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Viewer } from 'cesium';
3
2
 
4
3
  interface IBaseAnalysis<T, R> {
5
4
  set: (options: T) => R;
@@ -137,3 +136,4 @@ declare const createProfileAnalysis: (viewer: Cesium.Viewer) => IProFile<IProFil
137
136
  declare const createModelProfileAnalysis: (viewer: Viewer) => IProFile<IModelProFileOptions>;
138
137
 
139
138
  export { types as Analysis, createClipPlaneAnalysis, createClipPolygonAnalysis, createFillAndDigAnalysis, createFloodAnalysis, createModelProfileAnalysis, createProfileAnalysis };
139
+ export type { IBaseAnalysis, IClipPlane, IClipPlaneOPtions, IClipPolygon, IClipPolygonItem, IClipPolygonPtions, IFillDig, IFillDigItem, IFillDigOptions, IFlood, IFloodItem, IFloodOptions, IModelProFileOptions, IProFile, IProFileItem, IProFileItemData, IProFileOptions };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import*as e from"cesium";import{PrimitiveCollection as o,VerticalOrigin as t,Cartographic as i,EllipsoidTerrainProvider as n}from"cesium";import{makePositionsForClockwise as r,makePositionsForAntiClockwise as a,makeLnglatsToPositions as s,makePositionsToLnglats as l,numberId as c,makePositionsClose as d,makeLnglatToPosition as m,calcGeodesicDistances as p,calcLerpPosition as g,calcGeodesicDistance as h,makePositiontoLnglat as y}from"@ino-cesium/common";import*as u from"@turf/turf";const C=o=>{const t=new e.ClippingPlaneCollection({edgeColor:e.Color.YELLOW,enabled:!0,modelMatrix:e.Matrix4.IDENTITY,edgeWidth:2});o.scene.globe.clippingPlanes=t,o.scene.globe.backFaceCulling=!1,o.scene.globe.showSkirts=!1;return{set:o=>{Object.assign(o,{unionClippingRegions:!1,...o}),t.unionClippingRegions=o.unionClippingRegions||!1,t.removeAll();let i=o?.positions;i=o.unionClippingRegions?r(i):a(i),i.forEach((o,n)=>{const r=(n+1)%i.length,a=i[r];let s=e.Cartesian3.add(o,a,new e.Cartesian3);s=e.Cartesian3.multiplyByScalar(s,.5,s);const l=e.Cartesian3.normalize(s,new e.Cartesian3);let c=e.Cartesian3.subtract(a,s,new e.Cartesian3);c=e.Cartesian3.normalize(c,c);let d=e.Cartesian3.cross(c,l,new e.Cartesian3);d=e.Cartesian3.normalize(d,d);const m=new e.Plane(d,0),p=e.Plane.getPointDistance(m,s);t.add(new e.ClippingPlane(d,p))})},remove:()=>{t.removeAll()},removeAll:()=>{t.removeAll()},destroy:()=>{}}},v=o=>{const t=new e.ClippingPolygonCollection;o.scene.globe.clippingPolygons=t;const i=new e.CustomDataSource("clipPolygon");o.dataSources.add(i),o.scene.globe.backFaceCulling=!1,o.scene.globe.showSkirts=!1;return{set:o=>{o={inverse:!1,...o};const n=o?.positions,r=new e.ClippingPolygon({positions:n});t.add(r);const a=s(l(n).map(e=>(e.height=-o.depth,e))),d=i.entities.add({polygon:{hierarchy:a,perPositionHeight:!0,material:new e.ImageMaterialProperty({image:"/icons/terrain/poly-soil.jpg"})}});i.entities.add({polygon:{hierarchy:a,perPositionHeight:!0,extrudedHeight:o.depth,material:new e.ImageMaterialProperty({image:"/icons/terrain/poly-soil.jpg"})}});return{id:c(),polygon:r,bottomEntity:d}},remove:()=>{t.isDestroyed()||t.removeAll(),o.scene.globe.clippingPolygons=new e.ClippingPolygonCollection,i.entities.removeAll()},removeAll:()=>{t.isDestroyed()||t.removeAll(),o.scene.globe.clippingPolygons=new e.ClippingPolygonCollection,i.entities.removeAll()},destroy:()=>{}}},f=o=>{const t=new e.CustomDataSource("flood-analysis");o.dataSources.add(t);return{set:e=>{const{positions:o,type:t,speed:i}=e;return console.log(o,e,t,i),{id:c()}},remove:()=>{},removeAll:()=>{t.entities.removeAll()},destroy:()=>{o.dataSources.remove(t)}}},w=o=>{const t=new e.PrimitiveCollection({destroyPrimitives:!1}),i=new e.PrimitiveCollection({destroyPrimitives:!1}),n=new e.PointPrimitiveCollection,r=new e.LabelCollection;i.add(n),t.add(r),t.add(i),o.scene.primitives.add(t);const a=(o,t)=>{o.forEach(o=>{t.add({position:o,color:e.Color.TRANSPARENT})})},s=(o,t)=>{const i=new e.GroundPolylineGeometry({positions:o,width:3}),n=new e.GeometryInstance({geometry:i});t.add(new e.GroundPolylinePrimitive({geometryInstances:n,asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#ff00ff").withAlpha(.5)})})}))},l=(o,t)=>{const i=new e.WallGeometry({positions:o}),n=e.WallGeometry.createGeometry(i),r=new e.GeometryInstance({geometry:n});t.add(new e.Primitive({geometryInstances:[r],asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#00ff00").withAlpha(.5)})})}))},m=(o,t,i)=>{const n=new e.PolygonGeometry({polygonHierarchy:new e.PolygonHierarchy(o),height:t}),r=new e.GeometryInstance({geometry:n});i.add(new e.Primitive({geometryInstances:[r],asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#0088ff").withAlpha(.5)})})}))},p=(o,t,i,n,r)=>{const a=o.map(o=>e.Cartographic.fromCartesian(o).height),s=Math.min(...a),l=Math.max(...a);let c=0;for(let e=0;e<a.length;e++)c+=(a[e]-s)*t*t;const d=e.Cartesian3.fromDegrees(i.geometry.coordinates[0],i.geometry.coordinates[1],l),m={},p=r*l;c?m["挖方体积"]=`${h(c)}方\n`:c=0,p&&(m["填方体积"]=`${h(p-c)}方\n`),r&&(m["横切面积"]=`${h(r)}平方米\n`),s&&(m["最小高程"]=`${h(s)}米\n`),l&&(m["最大高程"]=`${h(l)}米\n`),s&&(m["基准面高程"]=`${h(s)}米`);let g="";Object.keys(m).forEach(e=>{g+=`${e}:${m[e]}`}),n.add({position:d,text:g,font:"16px sans-serif",fillColor:e.Color.WHITE,showBackground:!0,style:e.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:Number.POSITIVE_INFINITY})},g=(o,t,i)=>{o.forEach((o,n)=>{i.add({position:o,text:`高程:${h(t[n].height)}米`,font:"14px sans-serif",fillColor:e.Color.WHITE,showBackground:!0,style:e.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:Number.POSITIVE_INFINITY})})},h=e=>{const o=["","万","百万","千万","亿"];let t=0;for(;e>=1e4&&t<o.length-1;)e/=1e4,t++;return`${e.toFixed(2).replace(/\.?0+$/,"")}${o[t]}`};return{set:h=>{const y=d(h.positions),C=y.map(o=>{const t=e.Cartographic.fromCartesian(o);return{lng:e.Math.toDegrees(t.longitude),lat:e.Math.toDegrees(t.latitude),height:t.height}}),v=Math.min(...C.map(e=>e.height)),f=u.polygon([C.map(e=>[e.lng,e.lat])]),w=u.area(f),P=Math.sqrt(u.area(f)/200),I=u.envelope(f),T=u.centroid(f),b=u.bbox(I),A=u.pointGrid(b,P,{units:"meters"}),M=u.pointsWithinPolygon(A,f).features.map(o=>e.Cartesian3.fromDegrees(o.geometry.coordinates[0],o.geometry.coordinates[1]));return o.scene.clampToHeightMostDetailed(M).then(e=>{a(e,n),m(y,v,t),s(y,i),l(y,t),p(e,P,T,r,w),g(y,C,r)}),{id:c()}},remove:()=>{},removeAll:()=>{r.removeAll(),n.removeAll(),i.removeAll(),t.removeAll(),i.add(n),t.add(i),t.add(r)},destroy:()=>{}}},P=o=>{const t=new e.PrimitiveCollection({destroyPrimitives:!1});let i,n="/icons/markers/mark-icon.png";const r=[];o.scene.primitives.add(t);const a=t=>{if(!t)return i&&o.entities.remove(i),void(i=void 0);i||(i=o.entities.add({position:m(new e.Cartographic(t.longitude,t.latitude,t.height)),billboard:{image:n,scale:.5,verticalOrigin:e.VerticalOrigin.BOTTOM,heightReference:e.HeightReference.CLAMP_TO_GROUND,disableDepthTestDistance:Number.POSITIVE_INFINITY}})),i.position=m(new e.Cartographic(t.longitude,t.latitude,t.height))};return{set:async e=>{e.tipMarkerUrl&&(n=e.tipMarkerUrl);const{positions:t}=e;let i=p(t);const a=Math.floor(i/e.pointDistance);let s=g(t,a);s=await o.scene.clampToHeightMostDetailed(s),i=0;const l=s.map((e,o)=>{let t=0;o>0&&(t=h(s[o-1],e),i+=t);return{...y(e),distance:t,allDistance:i}}),d={id:c(),datas:l};return r.push(d),d},remove:e=>{const o=r.findIndex(o=>o.id===e.id);-1!==o&&r.splice(o,1),a()},removeAll:()=>{t.removeAll(),a()},destroy:()=>{o.scene.primitives.remove(t)},changeTipPoint:a}},I=e=>{const r=new o({destroyPrimitives:!1});let a=null,s="";const l=[];e.scene.primitives.add(r);const d=async(o,t,i)=>{const n=JSON.parse(JSON.stringify(o));await e.scene.clampToHeightMostDetailed(n)},h=o=>{if(!o)return a&&e.entities.remove(a),void(a=void 0);a||(a=e.entities.add({position:m(new i(o.longitude,o.latitude,o.height)),billboard:{image:s,scale:.5,verticalOrigin:t.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}})),a.position=m(new i(o.longitude,o.latitude,o.height))};return{set:async o=>{o.tipMarkerUrl&&(s=o.tipMarkerUrl);const t=o.layers;return e.terrainProvider instanceof n||(e.terrainProvider,e.terrainProvider=new n),t.forEach(e=>{e.visible=!1}),new Promise(e=>{setTimeout(()=>{const{positions:t}=o,i=p(t),n=Math.floor(i/o.pointDistance),r=g(t,n).filter(e=>e&&e.x&&e.y&&e.z),a={id:c(),datas:[]};d(r),e(a)},500)})},remove:e=>{const o=l.findIndex(o=>o.id===e.id);-1!==o&&l.splice(o,1),h(void 0)},removeAll:()=>{r.removeAll(),h(void 0)},destroy:()=>{e.scene.primitives.remove(r)},changeTipPoint:h}};export{C as createClipPlaneAnalysis,v as createClipPolygonAnalysis,w as createFillAndDigAnalysis,f as createFloodAnalysis,I as createModelProfileAnalysis,P as createProfileAnalysis};
1
+ import*as e from"cesium";import{makePositionsForClockwise as o,makePositionsForAntiClockwise as t,makeLnglatsToPositions as i,makePositionsToLnglats as n,numberId as r,makePositionsClose as a,makeLnglatToPosition as s,calcGeodesicDistances as l,calcLerpPosition as c,calcGeodesicDistance as d,makePositiontoLnglat as p}from"@ino-cesium/common";import*as m from"@turf/turf";const g=i=>{const n=new e.ClippingPlaneCollection({edgeColor:e.Color.YELLOW,enabled:!0,modelMatrix:e.Matrix4.IDENTITY,edgeWidth:2});i.scene.globe.clippingPlanes=n,i.scene.globe.backFaceCulling=!1,i.scene.globe.showSkirts=!1;return{set:i=>{Object.assign(i,{unionClippingRegions:!1,...i}),n.unionClippingRegions=i.unionClippingRegions||!1,n.removeAll();let r=i?.positions;r=i.unionClippingRegions?o(r):t(r),r.forEach((o,t)=>{const i=(t+1)%r.length,a=r[i];let s=e.Cartesian3.add(o,a,new e.Cartesian3);s=e.Cartesian3.multiplyByScalar(s,.5,s);const l=e.Cartesian3.normalize(s,new e.Cartesian3);let c=e.Cartesian3.subtract(a,s,new e.Cartesian3);c=e.Cartesian3.normalize(c,c);let d=e.Cartesian3.cross(c,l,new e.Cartesian3);d=e.Cartesian3.normalize(d,d);const p=new e.Plane(d,0),m=e.Plane.getPointDistance(p,s);n.add(new e.ClippingPlane(d,m))})},remove:()=>{n.removeAll()},removeAll:()=>{n.removeAll()},destroy:()=>{}}},h=o=>{const t=new e.ClippingPolygonCollection;o.scene.globe.clippingPolygons=t;const a=new e.CustomDataSource("clipPolygon");o.dataSources.add(a),o.scene.globe.backFaceCulling=!1,o.scene.globe.showSkirts=!1;return{set:o=>{o={inverse:!1,...o};const s=o?.positions,l=new e.ClippingPolygon({positions:s});t.add(l);const c=i(n(s).map(e=>(e.height=-o.depth,e))),d=a.entities.add({polygon:{hierarchy:c,perPositionHeight:!0,material:new e.ImageMaterialProperty({image:"/icons/terrain/poly-soil.jpg"})}});a.entities.add({polygon:{hierarchy:c,perPositionHeight:!0,extrudedHeight:o.depth,material:new e.ImageMaterialProperty({image:"/icons/terrain/poly-soil.jpg"})}});return{id:r(),polygon:l,bottomEntity:d}},remove:()=>{t.isDestroyed()||t.removeAll(),o.scene.globe.clippingPolygons=new e.ClippingPolygonCollection,a.entities.removeAll()},removeAll:()=>{t.isDestroyed()||t.removeAll(),o.scene.globe.clippingPolygons=new e.ClippingPolygonCollection,a.entities.removeAll()},destroy:()=>{}}},y=o=>{const t=new e.CustomDataSource("flood-analysis");o.dataSources.add(t);return{set:e=>{const{positions:o,type:t,speed:i}=e;return console.log(o,e,t,i),{id:r()}},remove:()=>{},removeAll:()=>{t.entities.removeAll()},destroy:()=>{o.dataSources.remove(t)}}},u=o=>{const t=new e.PrimitiveCollection({destroyPrimitives:!1}),i=new e.PrimitiveCollection({destroyPrimitives:!1}),n=new e.PointPrimitiveCollection,s=new e.LabelCollection;i.add(n),t.add(s),t.add(i),o.scene.primitives.add(t);const l=(o,t)=>{o.forEach(o=>{t.add({position:o,color:e.Color.TRANSPARENT})})},c=(o,t)=>{const i=new e.GroundPolylineGeometry({positions:o,width:3}),n=new e.GeometryInstance({geometry:i});t.add(new e.GroundPolylinePrimitive({geometryInstances:n,asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#ff00ff").withAlpha(.5)})})}))},d=(o,t)=>{const i=new e.WallGeometry({positions:o}),n=e.WallGeometry.createGeometry(i),r=new e.GeometryInstance({geometry:n});t.add(new e.Primitive({geometryInstances:[r],asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#00ff00").withAlpha(.5)})})}))},p=(o,t,i)=>{const n=new e.PolygonGeometry({polygonHierarchy:new e.PolygonHierarchy(o),height:t}),r=new e.GeometryInstance({geometry:n});i.add(new e.Primitive({geometryInstances:[r],asynchronous:!1,appearance:new e.MaterialAppearance({translucent:!0,faceForward:!0,material:e.Material.fromType("Color",{color:e.Color.fromCssColorString("#0088ff").withAlpha(.5)})})}))},g=(o,t,i,n,r)=>{const a=o.map(o=>e.Cartographic.fromCartesian(o).height),s=Math.min(...a),l=Math.max(...a);let c=0;for(let e=0;e<a.length;e++)c+=(a[e]-s)*t*t;const d=e.Cartesian3.fromDegrees(i.geometry.coordinates[0],i.geometry.coordinates[1],l),p={},m=r*l;c?p["挖方体积"]=`${y(c)}方\n`:c=0,m&&(p["填方体积"]=`${y(m-c)}方\n`),r&&(p["横切面积"]=`${y(r)}平方米\n`),s&&(p["最小高程"]=`${y(s)}米\n`),l&&(p["最大高程"]=`${y(l)}米\n`),s&&(p["基准面高程"]=`${y(s)}米`);let g="";Object.keys(p).forEach(e=>{g+=`${e}:${p[e]}`}),n.add({position:d,text:g,font:"16px sans-serif",fillColor:e.Color.WHITE,showBackground:!0,style:e.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:Number.POSITIVE_INFINITY})},h=(o,t,i)=>{o.forEach((o,n)=>{i.add({position:o,text:`高程:${y(t[n].height)}米`,font:"14px sans-serif",fillColor:e.Color.WHITE,showBackground:!0,style:e.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:Number.POSITIVE_INFINITY})})},y=e=>{const o=["","万","百万","千万","亿"];let t=0;for(;e>=1e4&&t<o.length-1;)e/=1e4,t++;return`${e.toFixed(2).replace(/\.?0+$/,"")}${o[t]}`};return{set:y=>{const u=a(y.positions),C=u.map(o=>{const t=e.Cartographic.fromCartesian(o);return{lng:e.Math.toDegrees(t.longitude),lat:e.Math.toDegrees(t.latitude),height:t.height}}),v=Math.min(...C.map(e=>e.height)),w=m.polygon([C.map(e=>[e.lng,e.lat])]),f=m.area(w),P=Math.sqrt(m.area(w)/200),I=m.envelope(w),T=m.centroid(w),b=m.bbox(I),A=m.pointGrid(b,P,{units:"meters"}),M=m.pointsWithinPolygon(A,w).features.map(o=>e.Cartesian3.fromDegrees(o.geometry.coordinates[0],o.geometry.coordinates[1]));return o.scene.clampToHeightMostDetailed(M).then(e=>{l(e,n),p(u,v,t),c(u,i),d(u,t),g(e,P,T,s,f),h(u,C,s)}),{id:r()}},remove:()=>{},removeAll:()=>{s.removeAll(),n.removeAll(),i.removeAll(),t.removeAll(),i.add(n),t.add(i),t.add(s)},destroy:()=>{}}},C=o=>{const t=new e.PrimitiveCollection({destroyPrimitives:!1});let i,n="/icons/markers/mark-icon.png";const a=[];o.scene.primitives.add(t);const m=t=>{if(!t)return i&&o.entities.remove(i),void(i=void 0);i||(i=o.entities.add({position:s(new e.Cartographic(t.longitude,t.latitude,t.height)),billboard:{image:n,scale:.5,verticalOrigin:e.VerticalOrigin.BOTTOM,heightReference:e.HeightReference.CLAMP_TO_GROUND,disableDepthTestDistance:Number.POSITIVE_INFINITY}})),i.position=s(new e.Cartographic(t.longitude,t.latitude,t.height))};return{set:async e=>{e.tipMarkerUrl&&(n=e.tipMarkerUrl);const{positions:t}=e;let i=l(t);const s=Math.floor(i/e.pointDistance);let m=c(t,s);m=await o.scene.clampToHeightMostDetailed(m),i=0;const g=m.map((e,o)=>{let t=0;o>0&&(t=d(m[o-1],e),i+=t);return{...p(e),distance:t,allDistance:i}}),h={id:r(),datas:g};return a.push(h),h},remove:e=>{const o=a.findIndex(o=>o.id===e.id);-1!==o&&a.splice(o,1),m()},removeAll:()=>{t.removeAll(),m()},destroy:()=>{o.scene.primitives.remove(t)},changeTipPoint:m}},v=e=>{const o=new PrimitiveCollection({destroyPrimitives:!1});let t=null,i="";const n=[];e.scene.primitives.add(o);const a=async(o,t,i)=>{const n=JSON.parse(JSON.stringify(o));await e.scene.clampToHeightMostDetailed(n)},d=o=>{if(!o)return t&&e.entities.remove(t),void(t=void 0);t||(t=e.entities.add({position:s(new Cartographic(o.longitude,o.latitude,o.height)),billboard:{image:i,scale:.5,verticalOrigin:VerticalOrigin.BOTTOM,disableDepthTestDistance:Number.POSITIVE_INFINITY}})),t.position=s(new Cartographic(o.longitude,o.latitude,o.height))};return{set:async o=>{o.tipMarkerUrl&&(i=o.tipMarkerUrl);const t=o.layers;return e.terrainProvider instanceof EllipsoidTerrainProvider||(e.terrainProvider,e.terrainProvider=new EllipsoidTerrainProvider),t.forEach(e=>{e.visible=!1}),new Promise(e=>{setTimeout(()=>{const{positions:t}=o,i=l(t),n=Math.floor(i/o.pointDistance),s=c(t,n).filter(e=>e&&e.x&&e.y&&e.z),d={id:r(),datas:[]};a(s),e(d)},500)})},remove:e=>{const o=n.findIndex(o=>o.id===e.id);-1!==o&&n.splice(o,1),d(void 0)},removeAll:()=>{o.removeAll(),d(void 0)},destroy:()=>{e.scene.primitives.remove(o)},changeTipPoint:d}};export{g as createClipPlaneAnalysis,h as createClipPolygonAnalysis,u as createFillAndDigAnalysis,y as createFloodAnalysis,v as createModelProfileAnalysis,C as createProfileAnalysis};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ino-cesium/analysis",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "author": "koino",
6
6
  "keywords": [
7
7
  "cesium",
@@ -31,7 +31,7 @@
31
31
  "cesium": "*"
32
32
  },
33
33
  "dependencies": {
34
- "@ino-cesium/common": "0.0.13",
34
+ "@ino-cesium/common": "0.0.14",
35
35
  "@turf/turf": "^7.0.0"
36
36
  },
37
37
  "types": "./dist/index.d.ts",