I hope this isn’t considered off topic here. It does have to
do with using Cesium. I’m kind of a novice when it comes to modern html
(HTML5/JQuery/CSS, etc).
All of the implementations I am finding on the Cesium web site involve
running cesium as a widget in a div container.
I have a need for a small text search form that exists outside
of this div container.
It consists of one form input and a couple of buttons. This
form allows a user to enter search terms that I run against a database, and
pull out associated coordinates that I am creating pins to place on the Cesium
app.
I would like this form
to sit on top (overlay) the div container that contains the cesium widget.
I would like it to only take up a small section in the upper
left corner, overlaying the cesium widget. It would be great if the background,
underneath the form input field and buttons were transparent.
I just figured other people in this group may have had to do
something similar. Any helpful hints on slick ways for doing this (including likes to widgets) would be
appreciated.
As you allude to in your post the sort of thing you’re trying to do really has nothing to do with Cesium but just involved JavaScript and HTML. The Cesium “Viewer” and the Cesium “Widget” (which are actually two different things need to be provided with an HTML DIV element when instantiated. This canvas that is used by Cesium is created in this DIV.
But the DIV is still just an HTML element, and you can add other HTML elements to it and position and style them however you like. Below is some code you can paste into the “JavaScript code” section of Sandcastle. This code creates a DIV called “divUpperLeft” and adds it to the upper left corner of the “cesiumContainer” DIV. It then adds a DIV called “divSearchContainer” to the “divUpperLeft” element. There are all sorts of approaches that could be used for adding these DIVs and other elements. This is just one quick method to give you an idea and something to start experimenting with.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
function addUpperLeftDiv() {
var divUL = document.getElementById(‘divUpperLeft’);
if (!divUL) {
divUL = document.createElement(‘div’);
divUL.id = ‘divUpperLeft’;
divUL.style.position = “absolute”;
divUL.style.background = “rgba(0,0,0,0)”;
divUL.style.left = “10px”;
divUL.style.top = “10px”;
divUL.innerHTML = “”;
divUL.style.zIndex = 2000;
document.getElementById(“cesiumContainer”).appendChild(divUL);
}
}
function includeSearchWidget() {
var divContainer = document.createElement(“div”);
divContainer.id = “divSearchContainer”;
divContainer.style.top = “20px”;
var txtField = document.createElement("input");
txtField.id = "txtSearchField";
txtField.type = "text";
txtField.style.border = "0px solid";
txtField.style.width = "150px";
txtField.onkeydown = function(e) {
// Enter Key
var keycode = e.which ? e.which : e.keyCode;
if (keycode === 13) {
window.alert("You hit the enter key while focus was on the search text field!");
}
};
divContainer.appendChild(txtField);
var btnSearch = document.createElement("input");
btnSearch.id = "btnSearch";
btnSearch.type = "button";
btnSearch.value = "Go";
btnSearch.style.width = "50px";
btnSearch.style.marginLeft = "10px";
btnSearch.onclick = function() {
window.alert("You clicked the search button!");
};
divContainer.appendChild(btnSearch);
document.getElementById("divUpperLeft").appendChild(divContainer);