From 7d2aa818986b880236a7b5f689dc32c0a15f4e89 Mon Sep 17 00:00:00 2001 From: Sam Dudley Date: Mon, 20 Feb 2017 18:01:50 +1030 Subject: [PATCH] Added WP numbers above WP markers in Cesium --- app/static/DST/js/core.js | 18 ++++++++++++------ app/static/DST/js/wp.js | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/static/DST/js/core.js b/app/static/DST/js/core.js index 913ad75..c54c0ce 100644 --- a/app/static/DST/js/core.js +++ b/app/static/DST/js/core.js @@ -5,10 +5,10 @@ $(function () { }) - var position = Cesium.Cartesian3.fromDegrees(136.861933, -35.370903, -2000.0); - var yaw = Cesium.Math.toRadians(45.0); - var pitch = Cesium.Math.toRadians(15.0); - var roll = Cesium.Math.toRadians(10.0); + var position = Cesium.Cartesian3.fromDegrees(0, 0, -2000.0); + var yaw = Cesium.Math.toRadians(0); + var pitch = Cesium.Math.toRadians(0); + var roll = Cesium.Math.toRadians(0); var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, yaw, pitch, roll); var vehicle_offset_x = 25 var vehicle_offset_y = 25 @@ -406,6 +406,7 @@ $(function () { var selected = { marker : null, alt_line : null, // line that joins the wp to the ground (has same id as marker) + label : null, // wp label (has same id as marker) dragging : false, camera_stored : false} // used for waypoint @@ -487,7 +488,11 @@ $(function () { cartographic.longitude, cartographic.latitude, - cartographic.height]) + cartographic.height]); + + selected.label.position = Cesium.Cartesian3.fromRadians(cartographic.longitude, + cartographic.latitude, cartographic.height+300); + } return // get out of the mouse movement function here if we are dragging and have a wp selected @@ -514,7 +519,8 @@ $(function () { // we dont select if we are dragging otherwise we can move wp's accidentally when panning the camera... document.getElementsByTagName("body")[0].style.cursor = "pointer" // change the pointer to a hand selected.marker.image= '/static/DST/wp_icons/ylw-blank.png' - selected.alt_line = get_by_id(alt_lines, selected.marker.id) // + selected.alt_line = get_by_id(alt_lines, selected.marker.id) // + selected.label = get_by_id(labels, selected.marker.id) } else { // we have not picked a wp clear_selected_marker() } diff --git a/app/static/DST/js/wp.js b/app/static/DST/js/wp.js index 60a7c94..3940307 100644 --- a/app/static/DST/js/wp.js +++ b/app/static/DST/js/wp.js @@ -1,5 +1,6 @@ var alt_lines = scene.primitives.add(new Cesium.PolylineCollection) var markers = scene.primitives.add(new Cesium.BillboardCollection) +var labels = scene.primitives.add(new Cesium.LabelCollection) var paths = scene.primitives.add(new Cesium.PolylineCollection) function create_wp(id, wp_data){ @@ -42,8 +43,18 @@ function create_wp(id, wp_data){ id : id, position : Cesium.Cartesian3.fromDegrees(wp_data.y, wp_data.x, wp_data.z+height_offset), image : '/static/DST/wp_icons/blu-blank.png', - verticalOrigin : Cesium.VerticalOrigin.BOTTOM + verticalOrigin : Cesium.VerticalOrigin.BOTTOM, + horizontalOrigin : Cesium.HorizontalOrigin.CENTER + }); + labels.add({ + id : id, + position : Cesium.Cartesian3.fromDegrees(wp_data.y, wp_data.x, wp_data.z+height_offset), + text : id, + font : '20px Arial', + pixelOffset : new Cesium.Cartesian2(0, -70), + horizontalOrigin : Cesium.HorizontalOrigin.CENTER, + verticalOrigin : Cesium.VerticalOrigin.BOTTOM }); } @@ -54,6 +65,8 @@ function destroy_wp(id){ alt_lines.remove(wp_alt_line) var wp_marker = get_by_id(markers, id) markers.remove(wp_marker) + var wp_label = get_by_id(labels, id) + labels.remove(wp_label) } function clear_mission(){