Giter Site home page Giter Site logo

cesium-draw's Introduction

Cesium-Draw

基于Vue 3.x开发的Cesium基础标绘插件,支持交互式添加BillBoard、Polyline、Polygon、Label和Model

Vue 2.x请访问 https://github.com/xtfge/cesium-draw/tree/cesium-draw-vue2

核心功能:

  • 鼠标交互绘图
  • 对于Billboard、Label、Model支持图标,名称的编辑,图标可以任意扩展.
  • 对于Polyline和Polygon支持顶点、颜色等常见图形属性的编辑.
  • 支持导入、导出功能
  • 可以通过图层管理器管理通过该插件添加的所有图形.

兼容性

安装

npm i cesium-draw

4.0.0及以上版本为Vue3.x版本,4.0.0以下的版本为Vue2.x的版本

使用

<template>
    <div>
     <div id='map'></div>
     <cesium-draw ref='drawManager' :viewer="viewer" v-if="viewer"></cesium-draw>
    </div>
</template>
<script>
import * as Cesium from "cesium";
import "cesium/Build/Cesium/Widgets/widgets.css";
import cesiumDraw from 'cesium-draw'
import 'cesium-draw/dist/theme/default.css' // 白色主题
//import 'cesium-draw/dist/theme/dark.css' // 暗色主题
export default{
    name:'your-component',
    data(){
        return {
            viewer:null
        }
    }
    components:{cesiumDraw},
    mounted(){
        this.viewer = new Cesium.Viewer('map')
    }
}
</script>

如果您是在html中通过script引用的Cesium,您需要额外配置webpack 您需要修改vue.config.js, 添加以下内容

module.exports = defineConfig({
  // ...
  configureWebpack: {
    externals: {
        cesium: 'Cesium'
    }
  },
  // ...
});

如果您使用的构建工具是vite,请了解vite相关配置。

扩展图片标记的图标

<cesium-draw ref='drwaManager' :extend-marker-image="images"></cesium-draw>
data(){
    return{
        images:["./static/images/markers/1.png",
                "./static/images/markers/2.png",
                "./static/images/markers/3.png",
                "./static/images/markers/4.png",
                "./static/images/markers/5.png"
      ]
    }
}

启用模型标记

你必须通过extendMarkerModel属性定义用于标记的模型,才可以使用模型标记。

比如:

<cesium-draw ref='drwaManager' :extend-marker-model="models"></cesium-draw>
data(){
    return{
        models:[
            { id: "model0",
            name: "木塔",
            thumb:'thumb.png', // 定义模型的缩略图,如果未定义,则使用默认图片
            url: "static/model/Wood_Tower.gltf" },
          {
              id: "model1",
              name: "小人",
              url: "static/model/Cesium_Man.gltf" }]
    }
}

如何使用喜欢的主题

import 'cesium-draw/dist/theme/default.css'

import 'cesium-draw/dist/theme/dark.css'

更多主题敬请期待。

完整示例

<template>
  <div>
   <div id='map'></div>
   <cesium-draw ref='drwaManager' :extendMarkerImage="images" :extendMarkerModel='model' ></cesium-draw>
 </div>
</template>
<script>
import cesiumDraw from 'cesium-draw'
//You can use theme
import 'cesium-draw/dist/theme/dark.css'
//import 'cesium-draw/dist/theme/default.css'
export default{
    name:'your-component',
    data(){
        return {
            images:["./static/images/markers/1.png",
                "./static/images/markers/2.png",
                "./static/images/markers/3.png",
                "./static/images/markers/4.png",
                "./static/images/markers/5.png"
                ],
            model:[
                { id: "model0",
                name: "tower",
                url: "static/model/Wood_Tower.gltf" },
                {
                id: "model1",
                name: "people",
                url: "static/model/Cesium_Man.gltf"
                }]
        }
    }
    components:{cesiumDraw},
    mounted(){
        const viewer=new Cesium.Viewer('map')
    }
}
</script>

Methods

  • getById(mid) 根据id返回图形要素

Events

事件 说明 回调
deleteEvent 要素删除事件 参数为删除要素的id
locateEvent 要素定位事件 定位要素的id
editEvent 要素编辑事件 要素的id
renameEvent 要素重命名事件 两个参数,依次为要素id,要素更新前的名称
selectEvent checkbox点击事件 两个参数,依次为要素id,checkbox状态
closeEvent 标绘面板关闭事件

开发&打包

npm install
npm run build

打包成组件

npm run lib

效果

avatar avatar avatar

Cesium交流群

加入QQ群 加入QQ群

捐赠

如果您觉得这个项目帮助到了您,您可以请作者喝一杯咖啡表示鼓励

微信收款码

cesium-draw's People

Contributors

xtfge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cesium-draw's Issues

Cannot read properties of undefined (reading 'prototype')

cesium版本1.96.0
cesium-draw版本3.4.5
按照readme.md的操作引入到自己的cesium文件中,报以下错误:
TypeError: Cannot read properties of undefined (reading 'prototype')
at 5924 (cesiumdrawViewer.umd.min.js:25:1)
at i (cesiumdrawViewer.umd.min.js:1:1)
at 4b26 (cesiumdrawViewer.umd.min.js:25:1)
at i (cesiumdrawViewer.umd.min.js:1:1)
at 5128 (cesiumdrawViewer.umd.min.js:25:1)
at i (cesiumdrawViewer.umd.min.js:1:1)
at Object.e974 (cesiumdrawViewer.umd.min.js:40:1)
at i (cesiumdrawViewer.umd.min.js:1:1)
at Object.eval (cesiumdrawViewer.umd.min.js:25:1)
at i (cesiumdrawViewer.umd.min.js:25:1)
image

cesium v1.83,import cesiumDraw from 'cesium-draw' 报错Cesium is not defined

引用代码如下:
//Cesium1.6及以上版本 cesium不支持import的方式引入 ,改用require引入
var Cesium = require("cesium/Cesium");
var widgets = require("cesium/Widgets/widgets.css");

import cesiumDraw from 'cesium-draw'
import 'cesium-draw/dist/theme/default.css'
//import 'cesium-draw/dist/theme/dark.css'

在import cesium-draw之前,先引入了Cesium,为何还报Cesium is not defined?

npm install cesium

能不能不使用npm install cesium下载cesium 而把编译好的cesium放在static中直接引用

Compile Error

This relative module was not found:

  • ./editPanel in ./src/js/drawHanlder.js
    anyone knows what happen?

yarn build出错

Error: Conflict: Multiple chunks emit assets to the same filename theme/default.css (chunks 143 and 998)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4625:12
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:93:5
at Hook.eval [as callAsync] (eval at create (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)
at Cache.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:75:18)
at ItemCacheFacade.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\CacheFacade.js:111:15)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4571:22
at arrayEach (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2405:9)
at Object.each (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2846:9)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4560:14
at symbolIterator (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3482:9)
at done (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3527:9)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2830:7
at done (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2865:11)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2818:7
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4665:18
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\HookWebpackError.js:68:3
at Hook.eval [as callAsync] (eval at create (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)
at Cache.store (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:107:20)
at ItemCacheFacade.store (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\CacheFacade.js:137:15)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4662:25
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:93:5
at Hook.eval [as callAsync] (eval at create (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)
at Cache.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:75:18)
at ItemCacheFacade.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\CacheFacade.js:111:15)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4571:22
at arrayEach (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2405:9)
at Object.each (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2846:9)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4560:14
at symbolIterator (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3482:9)
at timesSync (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2297:7)
at Object.eachLimit (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3463:5)
at Compilation.createChunkAssets (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:4537:12)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3108:14
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3288:6
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:2818:7
at done (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3522:9)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3251:8
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3360:32
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\HookWebpackError.js:68:3
at Hook.eval [as callAsync] (eval at create (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)
at Cache.store (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:107:20)
at ItemCacheFacade.store (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\CacheFacade.js:137:15)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3360:11
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:93:5
at Hook.eval [as callAsync] (eval at create (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\tapable\lib\HookCodeFactory.js:33:10), :6:1)
at Cache.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Cache.js:75:18)
at ItemCacheFacade.get (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\CacheFacade.js:111:15)
at Compilation._codeGenerationModule (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3330:9)
at D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\webpack\lib\Compilation.js:3237:11
at arrayIterator (D:\My_Prj\cesium-draw\node_modules.store\[email protected]\node_modules\neo-async\async.js:3467:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

性能问题,画多个图形后帧率明显下降

您好,我在尝试cesium地图上实现绘制/加载标注,基于您的drawhandler.js实现了功能,但在绘制多个图形时出现了明显的帧率下降和卡顿(没有使用您包装好的组件,也没有将生成的cesium viewer instance放入vue的data)。
这是加载了29个标注图形的结果,移动和缩放基本会卡死,体验非常差。想请问下,可能是什么原因导致的卡顿?单纯的添加entity应该不至于这样,可能是eventhandler或者collection里用map维护的graph instance导致的吗?

image
image

多谢!

我想把这个拉成一个vue组件用到我的项目中,按方法操作报错

These dependencies were not found:

  • cesium/Cesium in ./src/js/utils.js, ./src/js/Convert.js and 1 other
  • file-saver in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/se
    lector.js?type=script&index=0!./src/components/marker.vue, ./src/js/drawHandler.
    js
  • shapefile in ./src/js/utils.js
  • xlsx in ./src/js/utils.js

To install them, you can run: npm install --save cesium/Cesium file-saver shapef
ile xlsx

These relative modules were not found:

  • ../../static/images/markers/markPanel/download.png in ./node_modules/css-loade
    r?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"i
    d":"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-l
    oader/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue
  • ../../static/images/markers/markPanel/marker.png in ./node_modules/css-loader?
    {"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id"
    :"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-loa
    der/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue
  • ../../static/images/markers/markPanel/polygon.png in ./node_modules/css-loader
    ?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id
    ":"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-lo
    ader/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue
  • ../../static/images/markers/markPanel/polyline.png in ./node_modules/css-loade
    r?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"i
    d":"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-l
    oader/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue
  • ../../static/images/markers/markPanel/remove.png in ./node_modules/css-loader?
    {"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id"
    :"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-loa
    der/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue
  • ../../static/images/markers/markPanel/upload.png in ./node_modules/css-loader?
    {"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id"
    :"data-v-ae3f28f4","scoped":true,"hasInlineConfig":false}!./node_modules/vue-loa
    der/lib/selector.js?type=styles&index=0!./src/components/drawViewer.vue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.