It looks like this question has been asked before but I have been unable to find a proper example. I am familiar with PHP, but new to Javascript, and cannot figure out how to stream CZML.
I want to show about 6.500 assets on a map. To prevent the webpage from showing up AFTER everything is loaded (and testing the users' patience), I want it to show and then load the assets in the background.
Can somebody point me to an example on how to do this?
I can manage to load the czml file like this:
var czmlDataSource = new Cesium.CzmlDataSource();
viewer.dataSources.add(czmlDataSource);
czmlDataSource.loadUrl('some_file.czml');
But that's as far as I got :-( I know I should .processUrl somewhere and I understood I should use different packets in the CZML file so my CZML file looks like this:
[
event: czml
data: {
"id":"document",
"version":"1.0"
}
event: czml
data: {
"id":"1",
"billboard":{
"image":"label.png",
"verticalOrigin":"BOTTOM",
"show":true
},
"position":{
"cartographicDegrees":[
20.0, 50.0, 0
]
}
}
event: czml
data: {
"id":"2",
"billboard":{
"image":"label.png",
"verticalOrigin":"BOTTOM",
"show":true
},
"position":{
"cartographicDegrees":[
10.0, 52.0, 0
]
}
}
]
It would be great if somebody can provide a working sample, so a .czml file and a .js file. Thank you!
If have a streaming CZML network source then the client JavaScript code must call process() rather than load() to setup streaming a source.
var czmlStream = new Cesium.CzmlDataSource();
var czmlEventSource = new EventSource('some_url_to_czml');
czmlEventSource.addEventListener('czml', function(czmlUpdate) {
try {
var json = JSON.parse(czmlUpdate.data);
console.log('czml event id=', json.id);
//process the 'data:' coming across as JSON into the datasource
czmlStream.process(json);
} catch (t) {
console.error(t)
}
}, false);
//put the streaming datasource into Cesium
viewer.dataSources.add(czmlStream);
Note for the above code to work, the streaming source must set the content-type in HTTP response to text/event-stream.
To cancel a stream from the client, simply call:
czmlEventSource.close();
To cancel a stream from the server, respond with a non "text/event-stream" Content-Type or return an HTTP status other than 200 OK (e.g. 404 Not Found).
If you're loading from a static CZML file then call load() with the URL or relative file reference.
var dataSource = Cesium.CzmlDataSource.load('some_file.czml');
viewer.dataSources.add(dataSource);
One part of the question that is not answered is in regard to the format of the czml file. The example posted in the question has a few errors/misunderstandings. Your JSON data must all be on a single line for each data field, or you can add a data field for each line as I have. You must also have two return characters after each packet otherwise the stream will not know where to end, this is true of the last packet at the end of the file too! I struggled with this recently as well and the reason you do not find anything on the Cesium site is because this is technically part of the definition of Event Stream Formats rather than czml. You can find more info on the format here. Below is a proper example of your czml formatted correctly (Note: the snippet removed the last two return characters after the final packet, don't forget those!):
event: czml
data: {
data: "id":"document",
data: "version":"1.0"
data: }
event: czml
data: {"id":"1",
data: "billboard":{
data: "image":"label.png",
data: "verticalOrigin":"BOTTOM",
data: "show":true
data: },
data: "position":{
data: "cartographicDegrees":[
data: 20.0, 50.0, 0
data: ]
data: }
data: }
event: czml
data: {"id":"me",
data: "billboard":{
data: "image":"label.png",
data: "verticalOrigin":"BOTTOM",
data: "show":true
data: },
data: "position":{
data: "cartographicDegrees":[
data: 10.0, 50.0, 0
data: ]
data: }
data: }
Related
I am trying to figure out how to plot data from a local '.JSON' file using angular2-highcharts example.
I followed the example in 'https://www.npmjs.com/package/angular2-highcharts' to first understand how to plot .JSON data and it worked. I took the data available for the example and created a local .JSON file (copied the content from 'https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=JSONP_CALLBACK' in notepad and saved it with UTF-8 encoding as a .JSON file), and replaced the file path for the JSON request to this. When I do this though, I get an error - response with status 200.
constructor(jsonp : Jsonp) {
//jsonp.get('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=JSONP_CALLBACK').subscribe(res => {
jsonp.get('./data.json').subscribe(res => {
this.options = {
title : { text : 'AAPL Stock Price' },
series : [{
name : 'AAPL',
data : res.json(),
tooltip: {
valueDecimals: 2
}
}]
};
});
}
options: Object;
};
Since I am not super familiar with json data/ Javascript or angular2 I am not sure if I am missing something very basic here. Any help is appreciated.
as far as I know, Response Status 200 specifies that request was successful. i.e. your request was successfully handled. perhaps you want to try checking response data.
check your callback for response data.
Using http instead of json helped. I made use of the suggestion in this answer https://stackoverflow.com/a/36305814/4567096.
I'm a newbie about Ajax but I'm trying to do this:
I've got a local Json file and I have to do some Ajax calls to read the Json file and insert the values in the HTML file. My Json file is:
{
"item": {
"name": "blabla",
"details": "blablablabla",
"composition": "blablablabla",
"modelDetails": [
"blablablabla",
"blablablabla",
"blablablabla"
],
"images": [
"http://...jpg",
"http://...jpg",
"http://...jpg",
"http://...jpg"
]
}
}
What is the best way to do this? I would like that pushing the button number one will call the first json file, with button two the second json file,...
Thank you
Edit:
The links are very usefull! Thank you!
Here's a nice example of ajax call to retreive JSON data from file and parse JSON data. Hope it helps :)
http://code.runnable.com/UhY_jE3QH-IlAAAP/how-to-parse-a-json-file-using-jquery
IF link doesnt work :) Then try this script
$(document).ready(function() {
//after button is clicked we download the data
$('.button').click(function(){
//start ajax request
$.ajax({
url: "data.json",
//force to handle it as text
dataType: "text",
success: function(data) {
//data downloaded so we call parseJSON function
//and pass downloaded data
var json = $.parseJSON(data);
//now json variable contains data in json format
//Now you can get your data like json.name, json.object
}
});
});
});
I am playing with the ExtJs4 cartracker application written by existdisolve. I was able to change his queries from rest requests to ajax requests. I also modified the api calls to use ajax to make ajax requests for updates.
I am not getting form or url data passed to my cfc. Instead, in firebug I see JSON passed. I am confused if it is not passed in the form or the url, how is this passed and how do I get to the data? I have tried deserialized the form and url and dumping these after the deserialize and I am told that it is not json.
Where would I find the json?
I am not allowed to post a picture. But it looks like this in the xhr window:
JSON
Active true
ColorID null
Shortname red
Longname Blood Red
So if it is being passed why can I not get to it?
Edit:
#existdissolve - I replaced the rest.js with ajax.js which looks like this:
/**
* Abstract REST proxy
*/
Ext.define('CarTracker6.proxy.Ajax', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.baseajax',
/*format: 'json',*/
limitParam: 'max',
startParam: 'offset',
sortParam: 'sortorder',
writer : {
type : 'ajax',
encode : false,
writeAllFields : true,
root : 'data',
allowSingle : true,
batch : false,
method: 'post',
params: { record: 'record' },
writeRecords : function(request, data) {
request.jsonData = data;
return request;
}
},
reader: {
type: 'json',
root: 'data',
totalProperty: 'count'
},
api: {
read: 'api/option/colors.cfc?method=getcolors',
create: 'api/option/colors.cfc?method=addcolors',
update: 'api/option/colors.cfc?method=updatecolors',
destroy: 'api/option/colors.cfc?method=deletecolors'
}
});
My read works perfectly and I can call the correct cfcs for colors, statuses, etc. and retrieve the requisite data. I am looking to pass parameters to the CFCs and that is not working.
see http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.writer.Json-cfg-encode:
if the encode property of your writer is set to false, all data is sent as raw post body. Instead, you can use
encode: true,
root: 'data', // must be set if encode is true
We have an internal API that was specifically built to be used with a new piece of software I'm building that runs on Backbone. The API has a single URL and takes JSON as input to determine what it needs to return. It essentially allows me to build custom queries with JSON that return exactly what I'm looking for.
Thing is this JSON can get pretty verbose and is often 3–4 levels deep, but sometimes may just be a few lines and just 1 level deep.
First question first: How do I send a string of JSON along with the ID when I do a fetch()? Do I have to set these parameters as the model or collection's defaults?
Here is an example of a really simple string to get a specific user's info
{
"which" : "object",
"object" : {
"type" : "customer",
"place" : "store",
"customerID" : "14"
}
}
As others have suggested it will likely be challenging to work with SOAP, but it shouldn't be impossible. Backbone models and collections communicate with the server through the sync operation; you should be able to customize that. I think something along these lines might get the ball rolling (for models):
Backbone.SoapyModel = Backbone.Model.extend({
sync: function(method, model, options) {
// force POST for all SOAP calls
method = 'create';
options = _.extend(options, {
// Setting the data property will send the model's state
// to the server. Add whatever complexity is needed here:
data: JSON.stringify({
"which" : "object",
"object" : model.toJSON()
}),
// Set the request's content type
contentType: 'application/json'
});
// Defer the rest to Backbone
return Backbone.sync.apply(this, [method, model, options]);
}
});
var SoapyModelImpl = Backbone.SoapyModel.extend({
url: '/test'
});
var soapTest = new SoapyModelImpl({
id: 42,
name: 'bob',
address: '12345 W Street Dr',
phone: '867 5304'
});
soapTest.fetch();
I try to display some data in my Sencha touch application, but it doesn't work... and i can't find what I'm doing wrong.
My webSiste return a json object who look like this
[{"name":"a","id":1}]
the script is getting the Json and display it:
Ext.regApplication({ name: 'Command',
phoneStartupScreen: 'phone-startup.png',
phoneIcon: 'apple-touch-icon.png',
launch: function(){
this.viewport = new Ext.Panel(
{
layout: 'fit',
fullscreen: true,
items: [{xtype: 'list',
itemTpl: new Ext.XTemplate('<div>{name}</div>'),
store: stores
}],
dockedItems: [{xtype: "toolbar",
dock: "top",
title: 'MovieCommand',
items: [{ui: 'back',text: 'back',handler: function(){}}]
}]
});
}
});
Ext.regModel('Commands', {
fields: ['name', 'id' ]
});
var stores = new Ext.data.Store(
{model: 'Commands',
proxy: {type: 'scripttag',
url: 'http://localhost:8080/GTI710/commandes/liste.htm',
format: 'sencha',
reader: new Ext.data.JsonReader ({
type: 'json',
})
},
});
stores.load();
I don't have any error in the java script but nothing is displayed.
I just want to have the "a" displayed but it doesn't work, I don't know why...
The ScriptTagProxy, which you are using, requires a response from server that's composed of legitimate Javascript code.
Specifically, the code is a callback function with the desired JSON data you what as the its first argument:
someCallback([{"name":"a","id":1}]);
The name of someCallback is generated dynamically by Sencha Touch when the request is sent. In other words, your attempt to store the response with a static file will not work.
The name of someCallback is passed as a parameter in the GET request sent by Sencha Touch, the key of which defaults to callback.
If you don't want to have a web server as the data source, checkout Ext.util.JSONP.