{"_id":"@cesium-extends-cang/measure","name":"@cesium-extends-cang/measure","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.2":{"name":"@cesium-extends-cang/measure","version":"1.1.2","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/hongfaqiu/cesium-extends.git","directory":"packages/measure"},"scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c --watch"},"keywords":["cesium","measure"],"author":{"name":"hongfaqiu"},"license":"MIT","peerDependencies":{"cesium":"*"},"devDependencies":{"cesium":"^1.104.0"},"dependencies":{"@cesium-extends/drawer":"^1.2.2","@cesium-extends/subscriber":"^1.0.1","@cesium-extends/tooltip":"^1.2.1","@turf/area":"^6.5.0","@turf/helpers":"^6.5.0","@turf/intersect":"^6.5.0","@turf/random":"^6.5.0","@turf/voronoi":"^6.5.0"},"_id":"@cesium-extends-cang/measure@1.1.2","gitHead":"3be103ad327d9be32216febc7c3b1746ccff0187","description":"@cesium-extends/measure is a measurement tool based on Cesium, which supports distance and area measurement and is easy to use.\r [中文 Readme](./README_CN.md)","bugs":{"url":"https://github.com/hongfaqiu/cesium-extends/issues"},"homepage":"https://github.com/hongfaqiu/cesium-extends#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-m6IlSDlH/G6Nv9YV02onlrda9ARvXotYjQBzRHGURCVBDiJOaG0WNevWPK8wwYT3g7HXgWQJqCkfM9jp2SU1wQ==","shasum":"96ec9f63bf9f962296441804044b2890da137399","tarball":"https://registry.npmjs.org/@cesium-extends-cang/measure/-/measure-1.1.2.tgz","fileCount":4,"unpackedSize":29071,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDzaFpPNqasEyd9TFKFzA65jBIzEFaJKXPuRQaSXYFzRgIgX/F8sKLzb3XArQBBs+oHsdrF5nIEvSdYxLYw+JqIyJU="}]},"_npmUser":{"name":"wucanghao","email":"360119203@qq.com"},"directories":{},"maintainers":[{"name":"wucanghao","email":"360119203@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/measure_1.1.2_1722243098408_0.9249387037654753"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-29T08:51:38.339Z","1.1.2":"2024-07-29T08:51:38.543Z","modified":"2024-07-29T08:51:38.781Z"},"maintainers":[{"name":"wucanghao","email":"360119203@qq.com"}],"description":"@cesium-extends/measure is a measurement tool based on Cesium, which supports distance and area measurement and is easy to use.\r [中文 Readme](./README_CN.md)","homepage":"https://github.com/hongfaqiu/cesium-extends#readme","keywords":["cesium","measure"],"repository":{"type":"git","url":"git+https://github.com/hongfaqiu/cesium-extends.git","directory":"packages/measure"},"author":{"name":"hongfaqiu"},"bugs":{"url":"https://github.com/hongfaqiu/cesium-extends/issues"},"license":"MIT","readme":"# @cesium-extends/measure\r\n\r\n@cesium-extends/measure is a measurement tool based on Cesium, which supports distance and area measurement and is easy to use.\r\n[中文 Readme](./README_CN.md)\r\n\r\n## Installation\r\n\r\nInstall via npm:\r\n\r\n```bash\r\nnpm install @cesium-extends/measure --save\r\n```\r\n\r\n## Usage\r\n\r\nImport the `@cesium-extends/measure` module in your project, then instantiate the corresponding measuring class for measurement.\r\n\r\n### AreaMeasure\r\n\r\nUsed for non-ground area measurement.\r\n\r\n```typescript\r\nimport { Viewer } from \"cesium\";\r\nimport { AreaMeasure } from \"@cesium-extends/measure\";\r\n\r\nconst viewer = new Viewer(\"cesiumContainer\");\r\nconst areaMeasure = new AreaMeasure(viewer, {\r\n  onEnd: (entity) => {\r\n    console.log(entity); // The callback function when the measurement is completed, returning the measurement result\r\n  },\r\n});\r\n\r\n// Start drawing\r\nareaMeasure.start();\r\n```\r\n\r\n### AreaSurfaceMeasure\r\n\r\nUsed for ground area measurement.\r\n\r\n```typescript\r\nimport { Viewer } from \"cesium\";\r\nimport { AreaSurfaceMeasure } from \"@cesium-extends/measure\";\r\n\r\nconst viewer = new Viewer(\"cesiumContainer\");\r\nconst areaSurfaceMeasure = new AreaSurfaceMeasure(viewer, {\r\n  onEnd: (entity) => {\r\n    console.log(entity); // The callback function when the measurement is completed, returning the measurement result\r\n  },\r\n});\r\n\r\n// Start drawing\r\nareaSurfaceMeasure.start();\r\n```\r\n\r\n### DistanceMeasure\r\n\r\nUsed for non-ground distance measurement.\r\n\r\n```typescript\r\nimport { Viewer } from \"cesium\";\r\nimport { DistanceMeasure } from \"@cesium-extends/measure\";\r\n\r\nconst viewer = new Viewer(\"cesiumContainer\");\r\nconst distanceMeasure = new DistanceMeasure(viewer, {\r\n  onEnd: (entity) => {\r\n    console.log(entity); // The callback function when the measurement is completed, returning the measurement result\r\n  },\r\n});\r\n\r\n// Start drawing\r\ndistanceMeasure.start();\r\n```\r\n\r\n### DistanceSurfaceMeasure\r\n\r\nUsed for ground distance measurement.\r\n\r\n```typescript\r\nimport { Viewer } from \"cesium\";\r\nimport { DistanceSurfaceMeasure } from \"@cesium-extends/measure\";\r\n\r\nconst viewer = new Viewer(\"cesiumContainer\");\r\nconst distanceSurfaceMeasure = new DistanceSurfaceMeasure(viewer, {\r\n  onEnd: (entity) => {\r\n    console.log(entity); // The callback function when the measurement is completed, returning the measurement result\r\n  },\r\n});\r\n\r\n// Start drawing\r\ndistanceSurfaceMeasure.start();\r\n```\r\n\r\n## API\r\n\r\n### MeasureOptions\r\n\r\n| Parameter     | Type     | Description                                         |\r\n| ------------- | -------- | --------------------------------------------------- |\r\n| labelStyle    | object   | Label style                                         |\r\n| units         | string   | Unit of measure, default is 'kilometers'            |\r\n| locale        | object   | Custom locale                                       |\r\n| onEnd         | function | Callback function when the measurement is completed |\r\n| drawerOptions | object   | Drawing tool options                                |\r\n\r\n### Measure\r\n\r\nThe base class for measurement. Other measuring classes inherit from this class.\r\n\r\n#### Constructor\r\n\r\n##### `constructor(viewer: Viewer, options?: MeasureOptions)`\r\n\r\nCreate a measurement tool instance.\r\n\r\nParameters:\r\n\r\n- `viewer`: Cesium.Viewer object.\r\n- `options` (optional): Configuration item with type `MeasureOptions`.\r\n\r\n#### Properties\r\n\r\n##### `destroyed: boolean`\r\n\r\nReturns whether the current measurement tool has been destroyed.\r\n\r\n##### `mouseTooltip: MouseTooltip`\r\n\r\nMouse tooltip tool instance.\r\n\r\n##### `drawer: Drawer`\r\n\r\nDrawing tool instance.\r\n\r\n#### Methods\r\n\r\n##### `start(): void`\r\n\r\nStart measuring.\r\n\r\n##### `end(): void`\r\n\r\nEnd measuring and clear the measurement result.\r\n\r\n##### `destroy(): void`\r\n\r\nDestroy the measurement tool.\r\n\r\n### AreaMeasure\r\n\r\nUsed for non-ground area measurement.\r\n\r\n#### Constructor\r\n\r\n##### `constructor(viewer: Viewer, options?: MeasureOptions)`\r\n\r\nCreate an `AreaMeasure` instance.\r\n\r\nParameters:\r\n\r\n- `viewer`: Cesium.Viewer object.\r\n- `options` (optional): Configuration item with type `MeasureOptions`.\r\n\r\n#### Methods\r\n\r\n##### `getArea(positions: Cartesian3[]): number`\r\n\r\nCalculate the area of a polygon.\r\n\r\nParameters:\r\n\r\n- `positions`: An array of positions, with each position being of type `Cartesian3`.\r\n\r\nReturn value: The area, with the unit specified by the configuration item, defaulting to meters.\r\n\r\n### AreaSurfaceMeasure\r\n\r\nUsed for ground area measurement.\r\n\r\n#### Constructor\r\n\r\n##### `constructor(viewer: Viewer, options?: MeasureOptions)`\r\n\r\nCreate an `AreaSurfaceMeasure` instance.\r\n\r\nParameters:\r\n\r\n- `viewer`: Cesium.Viewer object.\r\n- `options` (optional): Configuration item with type `MeasureOptions`.\r\n\r\n#### Methods\r\n\r\n##### `getArea(positions: Cartesian3[]): number`\r\n\r\nCalculate the ground area of a polygon.\r\n\r\nParameters:\r\n\r\n- `positions`: An array of positions, with each position being of type `Cartesian3`.\r\n\r\nReturn value: The area, with the unit specified by the configuration item, defaulting to meters.\r\n\r\n### DistanceMeasure\r\n\r\nUsed for non-ground distance measurement.\r\n\r\n#### Constructor\r\n\r\n##### `constructor(viewer: Viewer, options?: MeasureOptions)`\r\n\r\nCreate a `DistanceMeasure` instance.\r\n\r\nParameters:\r\n\r\n- `viewer`: Cesium.Viewer object.\r\n- `options` (optional): Configuration item with type `MeasureOptions`.\r\n\r\n#### Methods\r\n\r\n##### `getDistance(start: Cartesian3, end: Cartesian3): number`\r\n\r\nCalculate the distance between two points.\r\n\r\nParameters:\r\n\r\n- `start`: The starting point coordinates, as a `Cartesian3`.\r\n- `end`: The ending point coordinates, as a `Cartesian3`.\r\n\r\nReturn value: The distance between the two points, with the unit specified by the configuration item, defaulting to meters.\r\n\r\n### DistanceSurfaceMeasure\r\n\r\nUsed for ground distance measurement.\r\n\r\n#### Constructor\r\n\r\n##### `constructor(viewer: Viewer, options?: MeasureOptions & {splitNum?: number})`\r\n\r\nCreate a `DistanceSurfaceMeasure` instance.\r\n\r\nParameters:\r\n\r\n- `viewer`: Cesium.Viewer object.\r\n- `options` (optional): Configuration item with type `MeasureOptions`, also supports an additional `splitNum` parameter, indicating how many segments to divide the line for surface distance calculation. When this parameter is not passed, it defaults to 10.\r\n\r\n#### Methods\r\n\r\n##### `getDistance(pos1: Cartesian3, pos2: Cartesian3): number`\r\n\r\nCalculate the ground distance between two points.\r\n\r\nParameters:\r\n\r\n- `pos1`: The starting point coordinates, as a `Cartesian3`.\r\n- `pos2`: The ending point coordinates, as a `Cartesian3`.\r\n\r\nReturn value: The distance between the two points, with the unit specified by the configuration item, defaulting to meters.\r\n\r\n## Notes\r\n\r\n- This tool is based on Cesium and requires the Cesium library to be imported into the project.\r\n- Please make sure you understand the basics of Cesium and how to create a Viewer before using the measuring tool.\r\n- Before using the measuring tool, other operations that may affect the interaction, such as camera roaming and scene rotation, should be stopped.\r\n- Please be aware of the performance of the browser during use. Excessive drawing may cause the browser to crash or freeze.\r\n- The current version only supports distance and area measurement. If you need to implement other functions, you can extend it yourself.\r\n- The tool code is open source. If you have any questions or suggestions, please submit an issue or PR on the GitHub project page.\r\n","readmeFilename":"README.md"}