Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for cesiumb26 support #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 43 additions & 83 deletions Cesium/Cesium.js

Large diffs are not rendered by default.

76 changes: 38 additions & 38 deletions DrawHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var DrawHelper = (function() {
var scene = this._scene;
var _self = this;
// scene events
var handler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
function callPrimitiveCallback(name, position) {
if(_self._handlersMuted == true) return;
var pickedObject = scene.pick(position);
Expand Down Expand Up @@ -514,9 +514,9 @@ var DrawHelper = (function() {

// create one common billboard collection for all billboards
var b = new Cesium.BillboardCollection();
var a = this._scene.getContext().createTextureAtlas();
b.setTextureAtlas(a);
this._scene.getPrimitives().add(b);
var a = this._scene.context.createTextureAtlas();
b.textureAtlas = a;
this._scene.primitives.add(b);
this._billboards = b;
this._textureAtlas = a;
// keep an ordered list of billboards
Expand Down Expand Up @@ -548,7 +548,7 @@ var DrawHelper = (function() {
// if editable
if(callbacks) {
var _self = this;
var screenSpaceCameraController = this._scene.getScreenSpaceCameraController();
var screenSpaceCameraController = this._scene.screenSpaceCameraController;
function enableRotation(enable) {
screenSpaceCameraController.enableRotate = enable;
}
Expand All @@ -574,10 +574,10 @@ var DrawHelper = (function() {
callbacks.dragHandlers.onDragEnd && callbacks.dragHandlers.onDragEnd(getIndex(), position);
}

var handler = new Cesium.ScreenSpaceEventHandler(_self._scene.getCanvas());
var handler = new Cesium.ScreenSpaceEventHandler(_self._scene.canvas);

handler.setInputAction(function(movement) {
var cartesian = _self._scene.getCamera().controller.pickEllipsoid(movement.endPosition, ellipsoid);
var cartesian = _self._scene.camera.controller.pickEllipsoid(movement.endPosition, ellipsoid);
if (cartesian) {
onDrag(cartesian);
} else {
Expand All @@ -586,12 +586,12 @@ var DrawHelper = (function() {
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

handler.setInputAction(function(movement) {
onDragEnd(_self._scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid));
onDragEnd(_self._scene.camera.controller.pickEllipsoid(movement.position, ellipsoid));
}, Cesium.ScreenSpaceEventType.LEFT_UP);

enableRotation(false);

callbacks.dragHandlers.onDragStart && callbacks.dragHandlers.onDragStart(getIndex(), _self._scene.getCamera().controller.pickEllipsoid(position, ellipsoid));
callbacks.dragHandlers.onDragStart && callbacks.dragHandlers.onDragStart(getIndex(), _self._scene.camera.controller.pickEllipsoid(position, ellipsoid));
});
}
if(callbacks.onDoubleClick) {
Expand Down Expand Up @@ -657,7 +657,7 @@ var DrawHelper = (function() {
}

_.BillboardGroup.prototype.setOnTop = function() {
this._scene.getPrimitives().raiseToTop(this._billboards);
this._scene.primitives.raiseToTop(this._billboards);
}

_.prototype.startDrawingMarker = function(options) {
Expand All @@ -674,17 +674,17 @@ var DrawHelper = (function() {

var _self = this;
var scene = this._scene;
var primitives = scene.getPrimitives();
var primitives = scene.primitives;
var tooltip = this._tooltip;

var markers = new _.BillboardGroup(this, options);

var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

// Now wait for start
mouseHandler.setInputAction(function(movement) {
if(movement.position != null) {
var cartesian = scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(movement.position, ellipsoid);
if (cartesian) {
markers.addBillboard(cartesian);
_self.stopDrawing();
Expand All @@ -696,7 +696,7 @@ var DrawHelper = (function() {
mouseHandler.setInputAction(function(movement) {
var position = movement.endPosition;
if(position != null) {
var cartesian = scene.getCamera().controller.pickEllipsoid(position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(position, ellipsoid);
if (cartesian) {
tooltip.showAt(position, "<p>Click to add your marker. Position is: </p>" + getDisplayLatLngString(ellipsoid.cartesianToCartographic(cartesian)));
} else {
Expand Down Expand Up @@ -730,7 +730,7 @@ var DrawHelper = (function() {

var _self = this;
var scene = this._scene;
var primitives = scene.getPrimitives();
var primitives = scene.primitives;
var tooltip = this._tooltip;

var minPoints = isPolygon ? 3 : 2;
Expand All @@ -746,12 +746,12 @@ var DrawHelper = (function() {
var positions = [];
var markers = new _.BillboardGroup(this, defaultBillboard);

var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

// Now wait for start
mouseHandler.setInputAction(function(movement) {
if(movement.position != null) {
var cartesian = scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(movement.position, ellipsoid);
if (cartesian) {
// first click
if(positions.length == 0) {
Expand All @@ -776,7 +776,7 @@ var DrawHelper = (function() {
if(positions.length == 0) {
tooltip.showAt(position, "<p>Click to add first point</p>");
} else {
var cartesian = scene.getCamera().controller.pickEllipsoid(position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(position, ellipsoid);
if (cartesian) {
positions.pop();
// make sure it is slightly different
Expand All @@ -800,7 +800,7 @@ var DrawHelper = (function() {
if(positions.length < minPoints + 2) {
return;
} else {
var cartesian = scene.getCamera().controller.pickEllipsoid(position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(position, ellipsoid);
if (cartesian) {
_self.stopDrawing();
if(typeof options.callback == 'function') {
Expand Down Expand Up @@ -835,14 +835,14 @@ var DrawHelper = (function() {

var _self = this;
var scene = this._scene;
var primitives = this._scene.getPrimitives();
var primitives = this._scene.primitives;
var tooltip = this._tooltip;

var firstPoint = null;
var extent = null;
var markers = null;

var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

function updateExtent(value) {
if(extent == null) {
Expand All @@ -865,7 +865,7 @@ var DrawHelper = (function() {
// Now wait for start
mouseHandler.setInputAction(function(movement) {
if(movement.position != null) {
var cartesian = scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(movement.position, ellipsoid);
if (cartesian) {
if(extent == null) {
// create the rectangle
Expand All @@ -888,7 +888,7 @@ var DrawHelper = (function() {
if(extent == null) {
tooltip.showAt(position, "<p>Click to start drawing rectangle</p>");
} else {
var cartesian = scene.getCamera().controller.pickEllipsoid(position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(position, ellipsoid);
if (cartesian) {
var value = getExtent(firstPoint, ellipsoid.cartesianToCartographic(cartesian));
updateExtent(value);
Expand Down Expand Up @@ -917,18 +917,18 @@ var DrawHelper = (function() {

var _self = this;
var scene = this._scene;
var primitives = this._scene.getPrimitives();
var primitives = this._scene.primitives;
var tooltip = this._tooltip;

var circle = null;
var markers = null;

var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
var mouseHandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

// Now wait for start
mouseHandler.setInputAction(function(movement) {
if(movement.position != null) {
var cartesian = scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(movement.position, ellipsoid);
if (cartesian) {
if(circle == null) {
// create the circle
Expand Down Expand Up @@ -959,7 +959,7 @@ var DrawHelper = (function() {
if(circle == null) {
tooltip.showAt(position, "<p>Click to start drawing the circle</p>");
} else {
var cartesian = scene.getCamera().controller.pickEllipsoid(position, ellipsoid);
var cartesian = scene.camera.controller.pickEllipsoid(position, ellipsoid);
if (cartesian) {
circle.setRadius(Cesium.Cartesian3.distance(circle.getCenter(), cartesian));
markers.updateBillboardsPositions(cartesian);
Expand Down Expand Up @@ -988,7 +988,7 @@ var DrawHelper = (function() {
var _self = this;

function enableRotation(enable) {
drawHelper._scene.getScreenSpaceCameraController().enableRotate = enable;
drawHelper._scene.screenSpaceCameraController.enableRotate = enable;
}

setListener(billboard, 'leftDown', function(position) {
Expand All @@ -1004,10 +1004,10 @@ var DrawHelper = (function() {
_self.executeListeners({name: 'dragEnd', positions: position});
}

var handler = new Cesium.ScreenSpaceEventHandler(drawHelper._scene.getCanvas());
var handler = new Cesium.ScreenSpaceEventHandler(drawHelper._scene.canvas);

handler.setInputAction(function(movement) {
var cartesian = drawHelper._scene.getCamera().controller.pickEllipsoid(movement.endPosition, ellipsoid);
var cartesian = drawHelper._scene.camera.controller.pickEllipsoid(movement.endPosition, ellipsoid);
if (cartesian) {
onDrag(cartesian);
} else {
Expand All @@ -1016,7 +1016,7 @@ var DrawHelper = (function() {
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

handler.setInputAction(function(movement) {
onDragEnd(drawHelper._scene.getCamera().controller.pickEllipsoid(movement.position, ellipsoid));
onDragEnd(drawHelper._scene.camera.controller.pickEllipsoid(movement.position, ellipsoid));
}, Cesium.ScreenSpaceEventType.LEFT_UP);

enableRotation(false);
Expand All @@ -1040,7 +1040,7 @@ var DrawHelper = (function() {
if(this._editMode === true) {
return;
}
var primitives = scene.getPrimitives();
var primitives = scene.primitives;
// highlight by creating an outline polygon matching the polygon points
if(highlighted) {
// make sure all other shapes are not highlighted
Expand All @@ -1059,7 +1059,7 @@ var DrawHelper = (function() {
depthTest : {
enabled : true
},
lineWidth : Math.min(4.0, scene.getContext().getMaximumAliasedLineWidth())
lineWidth : Math.min(4.0, scene.context.getMaximumAliasedLineWidth())
}
})
}));
Expand Down Expand Up @@ -1174,7 +1174,7 @@ var DrawHelper = (function() {
editMarkers.addBillboards(halfPositions, handleEditMarkerChanges);
this._editMarkers = editMarkers;
// add a handler for clicking in the globe
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._globeClickhandler.setInputAction(
function (movement) {
var pickedObject = scene.pick(movement.position);
Expand Down Expand Up @@ -1339,7 +1339,7 @@ var DrawHelper = (function() {
markers.addBillboards(getCorners(extent.extent), handleMarkerChanges);
this._markers = markers;
// add a handler for clicking in the globe
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._globeClickhandler.setInputAction(
function (movement) {
var pickedObject = scene.pick(movement.position);
Expand Down Expand Up @@ -1431,7 +1431,7 @@ var DrawHelper = (function() {
markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
this._markers = markers;
// add a handler for clicking in the globe
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._globeClickhandler.setInputAction(
function (movement) {
var pickedObject = scene.pick(movement.position);
Expand Down Expand Up @@ -1520,7 +1520,7 @@ var DrawHelper = (function() {
markers.addBillboards(getMarkerPositions(), handleMarkerChanges);
this._markers = markers;
// add a handler for clicking in the globe
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.getCanvas());
this._globeClickhandler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
this._globeClickhandler.setInputAction(
function (movement) {
var pickedObject = scene.pick(movement.position);
Expand Down Expand Up @@ -1617,7 +1617,7 @@ var DrawHelper = (function() {
div.className = 'divider';
toolbar.appendChild(div);
addIcon('clear', options.clearIcon, 'Remove all primitives', function() {
scene.getPrimitives().removeAll();
scene.primitives.removeAll();
});

function addButton(button) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cesium-drawhelper

DrawHelper: A very early stage shape editor for Cesium. Currently limited to 2D and simple shapes.

Cesium version: Tested against b24.
Cesium version: Tested against b26.

License: Apache 2.0. Free for commercial and non-commercial use. See LICENSE.md.

Expand Down
14 changes: 7 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
loggingMessage('Marker created at ' + event.position.toString());
// create one common billboard collection for all billboards
var b = new Cesium.BillboardCollection();
var a = scene.getContext().createTextureAtlas();
b.setTextureAtlas(a);
scene.getPrimitives().add(b);
var a = scene.context.createTextureAtlas();
b.textureAtlas = a;
scene.primitives.add(b);
var image = new Image();
image.onload = function() {
a.addImage(image);
Expand All @@ -97,7 +97,7 @@
width: 5,
geodesic: true
});
scene.getPrimitives().add(polyline);
scene.primitives.add(polyline);
polyline.setEditable();
polyline.addListener('onEdited', function(event) {
loggingMessage('Polyline edited, ' + event.positions.length + ' points');
Expand All @@ -110,7 +110,7 @@
positions: event.positions,
material : Cesium.Material.fromType('Checkerboard')
});
scene.getPrimitives().add(polygon);
scene.primitives.add(polygon);
polygon.setEditable();
polygon.addListener('onEdited', function(event) {
loggingMessage('Polygon edited, ' + event.positions.length + ' points');
Expand All @@ -124,7 +124,7 @@
radius: event.radius,
material: Cesium.Material.fromType(Cesium.Material.RimLightingType)
});
scene.getPrimitives().add(circle);
scene.primitives.add(circle);
circle.setEditable();
circle.addListener('onEdited', function(event) {
loggingMessage('Circle edited: radius is ' + event.radius.toFixed(1) + ' meters');
Expand All @@ -137,7 +137,7 @@
extent: extent,
material: Cesium.Material.fromType(Cesium.Material.StripeType)
});
scene.getPrimitives().add(extentPrimitive);
scene.primitives.add(extentPrimitive);
extentPrimitive.setEditable();
extentPrimitive.addListener('onEdited', function(event) {
loggingMessage('Extent edited: extent is (N: ' + event.extent.north.toFixed(3) + ', E: ' + event.extent.east.toFixed(3) + ', S: ' + event.extent.south.toFixed(3) + ', W: ' + event.extent.west.toFixed(3) + ')');
Expand Down