using 3D models in CZML file to move an object - cesiumjs

I am creating a CZML file, I have a path that I want my object to follow that path and move on it location by location (I defined positions based on time epoch.)
It works perfectly with billboard with an image, but when I change my code to have a model, for example one of the 3D models in sandcastle, instead of billboard it is not working. It does not even show the model. I just have a label, moving around the path, but no sign of model.
What is the problem? I deeply want to use 3D model in CZML files, not in javaScript. I will be delighted if someone could help me with it.
I saved the my data in .czml file and then I will load them in html by javaScript as follow:
viewer.dataSources.add(Cesium.CzmlDataSource.load('../../SampleData/fstsp_solution.czml'));
and a copy of my czml file is:
[
{
"id":"document",
"version":"1.0"
},
{
"id":"Vehicle",
"availability":"2012-08-04T16:00:00Z/2012-08-04T17:04:54.9962195740191Z",
"model":{
"show":true,
"gltf":"../../SampleData/models/CesiumMilkTruck/CesiumMilkTruck.bgltf",
"scale":2,
"minimumPixelSize":25
},
"oriantation":{
"interpolationAlgorithm":"LAGRANGE",
"interpolationDegree":1,
"epoch":"2012-08-04T16:00:00Z",
"unitQuaternion":[some numbers, I am working on it]
},
"position":{
"interpolationAlgorithm":"LAGRANGE",
"interpolationDegree":1,
"epoch":"2012-08-04T16:00:00Z",
"cartographicDegrees":[time,long,lat,height,time,long,lat,height,time,long,lat,height]
}
}
]
Thanks

There's an oddity where ModelGraphics calls for a uri parameter, but the CzmlDataSource loader looks for this property by the name gltf in the CZML file. Not sure if this is/was intentional. In any case, if you use the right name, you can get the model to show up in a CZML file. My example below lacks the correct model orientation, but shows a model has loaded.
Try loading up Sandcastle and pasting the following into the code editor, then hit Run (F8).
var viewer = new Cesium.Viewer('cesiumContainer');
var builtInCzml = [{
"id" : "document",
"version" : "1.0",
"clock" : {
"interval" : "2012-08-04T16:00:00Z/2012-08-04T16:02:00Z",
"currentTime" : "2012-08-04T16:00:00Z",
"multiplier" : 1,
"range" : "LOOP_STOP",
"step" : "SYSTEM_CLOCK_MULTIPLIER"
}
}, {
"id" : "Vehicle",
"availability" : "2012-08-04T16:00:00Z/2012-08-04T16:02:00Z",
"model" : {
"show" : true,
"gltf" : "../../SampleData/models/CesiumGround/Cesium_Ground.bgltf"
},
"billboard" : {
"eyeOffset" : {
"cartesian" : [0.0, 0.0, 0.0]
},
"horizontalOrigin" : "CENTER",
"image" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEISURBVEhLvVXBDYQwDOuojHKj8LhBbpTbpBCEkZsmIVTXq1RVQGrHiWlLmTTqPiZBlyLgy/KSZQ5JSHDQ/mCYCsC8106kDU0AdwRnvYZArWRcAl0dcYJq1hWCb3hBrumbDAVMwAC82WoRvgMnVMDBnB0nYZFTbE6BBvdUGqVqCbjBIk3PyFFR/NU7EKzru+qZsau3ryPwwCRLKYOzutZuCL6fUmWeJGzNzL/RxAMrUmASSCkkAayk2IxPlwhAAYGpsiHQjbLccfdOY5gKkCXAMi7SscAwbQpAnKyctWyUZ6z8ja3OGMepwD8asz+9FnSvbhU8uVOHFIwQsI3/p0CfhuqCSQuxLqsN6mu8SS+N42MAAAAASUVORK5CYII=",
"pixelOffset" : {
"cartesian2" : [0.0, 0.0]
},
"scale" : 0.8,
"show" : true,
"verticalOrigin" : "BOTTOM"
},
"label" : {
"fillColor" : {
"rgba" : [255, 255, 0, 255]
},
"font" : "bold 10pt Segoe UI Semibold",
"horizontalOrigin" : "LEFT",
"outlineColor" : {
"rgba" : [0, 0, 0, 255]
},
"pixelOffset" : {
"cartesian2" : [10.0, 0.0]
},
"scale" : 1.0,
"show" : true,
"style" : "FILL",
"text" : "Vehicle",
"verticalOrigin" : "CENTER"
},
"path" : {
"material" : {
"solidColor" : {
"color" : {
"rgba" : [255, 255, 0, 255]
}
}
},
"width" : 5.0,
"show" : true
},
"position" : {
"interpolationAlgorithm" : "LAGRANGE",
"interpolationDegree" : 1,
"epoch" : "2012-08-04T16:00:00Z",
"cartesian" : [0.0, 1254962.0093268978, -4732330.528380746, 4074172.505865612,
120.0, 1256995.7322857284, -4732095.2154790815, 4073821.2249589274]
}
}];
var czmlDataSource = new Cesium.CzmlDataSource();
czmlDataSource.load(builtInCzml, 'Sample CZML with 3D model');
viewer.dataSources.add(czmlDataSource);
viewer.trackedEntity = czmlDataSource.entities.getById('Vehicle');

I found the problem, I didn't give it the right place to find the model on my computer, when I was using my local host, I actually should give it the full address form my localhost or Cesium address, so I should enter it as
"gltf":"../../Apps/SampleData/models/CesiumMilkTruck/CesiumMilkTruck.bgltf",
rather than just give it the address of
"../../SampleData/models/CesiumMilkTruck/CesiumMilkTruck.bgltf",
so it works now, thanks everyone who helped!

FYI - If you are going the uri route, you must include https

Related

Try to create random json for firebase with json generator without success

I try to build a json for me to test my firebase application. I need a couple of hundred entries and for that reason try to build me json with the JSON Generator from https://www.json-generator.com/
How ever I have problems to get random IDs as keys (and not as values). I tried all I can think of with {{objectId()}} but this seem to work only for values.
Does anybody have an idea how I could build a RANDOM JSON like the example below with the JSON Generator I used or any other generator? Again the problem is the random KEYS! As values this works great.
here an example of the JSON i need at the end.
{
"-f2zawhcNgh6vcHIQOCq" : {
"cat_id" : 1,
"created_at" : 1516206514529,
"edited_at" : 1516206514529,
"groups" : {
"-L2zawhcNgh6vcHIQOCq" : true,
"-L2zaxyBs-9AfQJii47k" : true
},
"local" : true,
"owner_id" : "MyaNhS4Qy6foMYkSIt0tpRQFneI3",
"private" : false
},
"-fghgajhgfkjhkQOCq" : {
"cat_id" : 1,
"created_at" : 1516206514529,
"edited_at" : 1516206514529,
"groups" : {
"-L2zawkjhfkjhkjgQOCq" : true
},
"local" : true,
"owner_id" : "hgfjhYkSIt0tpRQFneI3",
"private" : false
}
}
JSON.stringify(new Array(200).fill('something').reduce(mock => {
mock[Math.random()] = {
"cat_id" : 1,
"created_at" : Date.now()*Math.random() | 0,
"edited_at" : Date.now(),
"groups" : {
[Math.random()] : true
},
"local" : true,
"owner_id" : Math.random(),
"private" : false
}
return mock
}, {}), undefined, 2)
Paste this in chrome js console or node.js
Is that what you are looking for?

Updating a CZML property after the property is declared

I'm trying to update some properties (namely "semiMinorAxis" and "semiMajorAxis") from a packet previously declared in a czml file.
The way I attempt to do this, is by overwriting the values of "semiMinorAxis" and "semiMajorAxis".
That is: between 12:00:00 and 13:00:00, ellipse_1 has a size of 300000, and between 13:00:00 and 14:00:00, it has a size of 600000.
Here is how I'm trying to do this in a simple csml:
[
{
"id" : "document",
"name" : "name",
"version" : "1.0",
"clock":
{
"interval": "2010-02-04T12:00:00Z/2010-02-04T14:00:00Z",
"currentTime": "2010-02-04T12:00:00Z",
"multiplier": 100
}
},
// I create ellipse_1
{
"id" : "ellipse_1",
"name" : "ellipse_1 (61.0666922, -107.9917071)",
"availability" : "2010-02-04T12:00:00Z/2010-02-04T13:00:00ZZ",
"position" : {
"cartographicDegrees" : [-107.9917071,61.0666922, 0.0]
},
"ellipse" : {
"semiMinorAxis" : 300000,
"semiMajorAxis" : 300000,
"height" : 0.0,
"material" : {
"solidColor" : {
"color" : {
"rgba" :[151,20,150, 255]
}
}
}
}
},
// I reuse the id and only change the values that I want the change
{
"id" : "ellipse_1"
},
"ellipse" : {
"interval" : "2010-02-04T13:00:00Z/2010-02-04T14:00:00ZZ",
"semiMinorAxis" : 600000,
"semiMajorAxis" : 600000
}
}
]
another option seems to be doing it this way:
{
"id" : "ellipse_1",
"name" : "ellipse_1 (61.0666922, -107.9917071)",
"availability" : "2010-02-04T12:00:00.00Z/2010-02-04T14:00:00.00Z",
"position" : {
"cartographicDegrees" : [-137.9917071,51.0666922, 0.0]
},
"ellipse" : [
{
"interval" : "2010-02-04T12:00:00.00Z/2010-02-04T13:00:00.00Z",
"semiMinorAxis" : 300000,
"semiMajorAxis" : 300000,
"height" : 200000.0,
"material" : {
"solidColor" : {
"color" : {
"rgba" :[253,152,38, 255]
}
}
}
},
{
"interval" : "2010-02-04T13:00:00.00Z/2010-02-04T14:00:00.00Z",
"semiMinorAxis" : 600000,
"semiMajorAxis" : 600000,
"height" : 200000.0,
"material" : {
"solidColor" : {
"color" : {
"rgba" :[253,152,38, 255]
}
}
}
}
]
}
By the way, here is the script to view it:
<script>
var viewer = new Cesium.Viewer('cesiumContainer', {
imageryProvider : new Cesium.ArcGisMapServerImageryProvider({url : 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer'
}),
baseLayerPicker : false,
animation : true,
timeline : true,
});
var dataSourcePromise = Cesium.CzmlDataSource.load('../Apps/oscar.czml');
viewer.dataSources.add(dataSourcePromise);
viewer.flyTo(dataSourcePromise).then(function(result){
});
</script>
Unfortunately, these are clearly not the way to update values of an object in a csml file. Am I missing something obvious?
Thanks!

MongoDB Change/Update Subdocument Field

I currently have a Mongo DB database with one collection ('locations') with one document:
{
"_id" : ObjectId("5875653b89513c8328416522"),
"name" : "Starcups",
"address" : "125 High Street, Reading, RG6 1PS",
"rating" : 3,
"facilities" : [
"Hot drinks",
"Food",
"Premium wifi"
],
"coords" : [
-0.9690884,
51.455041
],
"openingTimes" : [
{
"days" : "Monday - Friday",
"opening" : "7:00am",
"closing" : "7:00pm",
"closed" : false
},
{
"days" : "Saturday",
"opening" : "8:00am",
"closing" : "5:00pm",
"closed" : false
},
{
"days" : "Sunday",
"closed" : true
}
],
"reviews" : [
{
"author" : "Simon Holmes",
"id" : ObjectId("5875663389513c8328416523"),
"rating" : 5,
"timestamp" : ISODate("2013-07-15T23:00:00Z"),
"reviewText" : "What a great place. I can't say enough good things about it."
}
]
}
I need to alter the field "id" (part of the subdocument reviews) to "_id". I have tried, using other similar examples on StackExchange, the following code to no avail:
db.locations.update({}, {$rename:{"reviews.id":"reviews._id"}}, false, true);
But I receive the following error:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "cannot use the part (reviews of reviews.id) to traverse the element ({reviews: [ { author: \"Simon Holmes\", id: ObjectId('5875663389513c8328416523'), rating: 5.0, timestamp: new Date(1373929200000), reviewText: \"What a great place. I can't say enough good things about it.\" } ]})"
}
})
I get the same error when I try to alter any other field. Could someone point me in the right direction?
Update:
This seems to be a problem assessing the subdocument field as the following code executes fine:
db.locations.update({}, {$rename:{"name":"names"}}, false, true);
I have also tried searching through the relevant documentation: https://docs.mongodb.com/manual/reference/operator/update/rename/
That's because Reviews is an Array
You cannot $rename to do that , instead you need to $set the new name and $unset the old one

Popover is not working for json multiple values

[
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : [{
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
},
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
},
{
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
}],
}]
This is my json file. When ever i mouse over "info.name"[abc, def, ghi] popover will display "name", "size" and "used".
but my issue is "abc" is the first value , when ever i mouseover it display value as expected. but when i mouseover "def" and "ghi" nothing is happened :(.
<ul type="none">
<li>
<label id="vol-label" class="muted">Info :</label>
{{#info}}
<span id="value"><a><u>{{name}}</u></a></span>
<span id="info-popover-title" class="hide">{{name}}</span>
<div id="info-popover-content" class="hide">
<p>Size : {{size}}</p> <p> Used : {{used}}</p><p> Status : {{status}}</p>
</div>
{{/info}}
</li>
</ul>
This is my template(mustache).
following is my view part(backbone.js)
events: {
"mouseenter #value" : "showDetails",
"mouseleave #value" : "hideDetails" ,
},
showDetails : function() {
this.$("#value").popover({
html : true,
title: function() {
return $("#info-popover-title").html();
},
content: function() {
return $("#info-popover-content").html();
}
});
this.$("#value").popover('show');
},
hideDetails : function() {
this.$("#value").popover('hide');
},
Please see my both screen shot to understand the issue. In fist screens hot see am getting all json info values "abc" "def" and "ghi" . in 2nd screen shot if i mouse over am getting "abc" values. but "def" and "ghi" value is not at all displaying. am not figure it out what is the issue :(.
I need to popove "def" and "ghi" values also. But i think something is wrong in my logic. Thanks in advance. This is really a rare issue for me might be others also.
If i use class insted of id following is the screen shot :(
2 things that you need to change here. First, is to use class to define for popovers instead of id. And the second is to abstract each <li> into its own view. Currently, you have one view that loops through the entire collection. All your events are currently tied to this one view. Doing those things I mentioned should fix this issue.
You can do something like this to have the become its own view which carries it's own sub-element. Just wrote this quickly and haven't tested but the idea is something like this. I'm not really sure which popover library you're using but the idea is generally the same.
Edit: Didn't realized you were using Mustache/Handlebars, so here's the JS Fiddle. Code
Now if you try to call each object it should work.
var abc =
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : {
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
}
};
var def =
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
};
var ghi = {
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
};
var output =
{
show : function()
{
return abc["info"];
}
};
console.log(output.show());

JSON hierarchical objects to reduce duplicate data

I'm using a .json file to hold font/text information for an application. Now that I'm adding different languages I need to be able to specify different sizes for certain fonts due to the varying sizes of the words in that language for example German words tend to be longer than English, so I might want a smaller font.
My problem is that there will be a ton of duplicate data in my .json file, as most fonts will remain the same for each language. Here's an example of the duplicate data that I want to reduce somehow, I just don't know how to format my .json file to do so (note that I've stripped out a lot of details so this will read easier):
"styles":
{
"en":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
"fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
}
}
Notice that in the above example that I have three languages, and all use identical font information with the exception of deutsche using a smaller "heading" font. What I'd like to do is something like this:
"styles":
{
"en", "de", "fr":
{
"main_title" :
{
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de":
{
"heading" :
{
"font" : "font://verdana-bold.ttf",
"size" : 16,
},
},
}
In this example I have all three languages use the same information, but am able to define one change in the deutsche language font. Obviously my second example won't read properly because it's not correct syntax, but hopefully this gets across what I'm trying to achieve. Is there any syntax in JSON that will allow me to do something like this?
I don't believe that JSON will do this, but you could have a 'default' object which consumers of this data can look at for any values missing from other language objects:
"styles": {
"default": {
"main_title" : {
"font" : "font://verdana-bold.ttf",
"size" : 25,
},
"heading" : {
"font" : "font://verdana-bold.ttf",
"size" : 18,
},
},
"de": {
"heading" : {
"size" : 16,
}
}
}
If you need to specify which languages are permissible, just add that as another attribute on the object:
"styles": {
"languages": ["en", "de", "fr"],
...
}