@ino-cesium/analysis 0.0.10 → 0.0.12

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +3 -2
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{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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ino-cesium/analysis",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "author": "koino",
6
6
  "keywords": [
7
7
  "cesium",
@@ -31,7 +31,8 @@
31
31
  "cesium": "*"
32
32
  },
33
33
  "dependencies": {
34
- "@ino-cesium/common": "0.0.10"
34
+ "@ino-cesium/common": "0.0.12",
35
+ "@turf/turf": "^7.0.0"
35
36
  },
36
37
  "types": "./dist/index.d.ts",
37
38
  "scripts": {