Draw lines, points, polygons with mouse click


I was wondering if there was an easy way to draw features in Cesium via mouseclick, rather than hard coding it?

I presume if this hasn’t been done then just playing with mouse events and getting coords from earth to do this is prob the easiest way.



I was thinking we need to add a Sandcastle demo that lets you draw primitives like this. Is anyone already working on one?


Jonah did something similar:


However, it uses OpenLayers (with Cesium underneath). This could be a useful addition to the picking example.



Hey Guys,

Thanks for the pointer. I should maybe explain more what I’m doing. I’ve actually been looking at exactly that example quite a bit and taken a copy of the code and messed around with it. A couple of problems (and none of which Jonah’s fault, I am very grateful he went as far as he did):

The version of cesium he uses is an old one which doesn’t support the WMS Imagery Layer type, which I need desperately.

He created a .js file in which he overrides the OL methods to call the Cesium API (or the other way around, can’t remember), and in which he has covered the drawing of features and navigation (which is great) but that’s where it ends.

I am now wanting to get WFS-T (or at least some sort of implementation of draw vectors - ship to DB, consume as WMS thing) implemented, which is probably quite a large leap, so I was thinking where I should do this. Either draw everything in cesium, calling some PHP webservice that will write the WKT / geoJSON to DB and then pull in a WMS into cesium. Or try and override all the functions I may need from OL to Cesium and do all the work in OL.

I am much more confident in OL, and if it were just OL (2D) I had to do this in I could do it in a heartbeat, but I have to do it in webGL, and cesium is the sexiest one out there… :slight_smile:

I’ve just found the CesiumWidget.onLeftMouseUp et al events, and am playing with those but if this is the wrong way to do it do shout.



Thanks for the kind words about Cesium. Yeap, I believe those are the events you should be looking at.


Hey Toby, those examples are old, but the code in the repo is less old. We have an updated verison of the OL adapter and we have wfs working. You should be able to create a wfs vector layer like you do in openlayers and just treat the map as if it is openlayers. There is also an OLTileProvider implementation in our build of Cesium which adapts OpenLayers.Layer.WMS and other imagery layers to provide image urls to Cesium. But all that is needed is to create an openlayers wms and add it to the overriden openlayers map.


Branch is latestvega. I can update my Openlayers repo with the latest O2C.js adapter as well. You’re more than welcome to reinvent all of this for cesium as well if you would like to.

How are you listening for the mouseEvents? I looked through the editingtoolbar example before, but wasn’t able to find where the lines were being created.