Initial knowledge cesium----loading different JSON format examples

Source: Internet
Author: User

Recently studied a few days cesium.js, some entry-level harvest, readily recorded, convenient to consult later!

Cesium supports Topojson,geojson and normal JSON formats, and the following shows examples of three different formats

first, Topojson

<Body>    <DivID= "cesiumcontainer"></Div>    <Script>    //Load Topojson    varViewer= NewCesium.viewer ('Cesiumcontainer'); varPromise=Viewer.dataSources.add (Cesium.GeoJsonDataSource.load ('.. /.. /apps/china.topojson', {stroke:Cesium.Color.BLACK, fill:Cesium.Color.RED, strokewidth:3, Markersymbol:'?'    }));    Viewer.flyto (promise); </Script></Body>

second, GEOjson

<Body>    <DivID= "cesiumcontainer"></Div>    <Script>    varViewer= NewCesium.viewer ('Cesiumcontainer'); //Seed the random number generator for repeatable results.Cesium.Math.setRandomNumberSeed (0); varPromise=Cesium.GeoJsonDataSource.load ('.. /.. /apps/testone.json'); Promise.then (function(dataSource) {viewer.dataSources.add (dataSource); varentities=dataSource.entities.values; varColorhash= {};  for (varI= 0; I<entities.length; i++) {            varEntity=entities[i]; varname=entity.name; varColor=colorhash[name]; if (!Color) {color=Cesium.Color.fromRandom ({alpha:1.0                }); colorhash[name]=color; } entity.polygon.material=color; Entity.polygon.outline= false; Entity.polygon.extrudedHeight=5000.0;        }        });    Viewer.flyto (promise); </Script></Body>

third, Ordinary JSON

<Body>  <DivID= "cesiumcontainer"></Div>  <Script>    varViewer= NewCesium.viewer ('Cesiumcontainer'); Cesium.Math.setRandomNumberSeed (0); Cesium.loadjson ('/.. /apps/points.json'). Then (function(jsondata) { for (varI=0; I<=JsonData.features.length-Ten; I++) {              varifeature=jsondata.features[i];  for (vark= 0; k<ifeature.geometry.paths[0].length-Ten; k++) {               if(ifeature.geometry.paths[0][k].length==2) {viewer.entities.add ({position:Cesium.Cartesian3.fromDegrees (ifeature.geom etry.paths[0][k][0],ifeature.geometry.paths[0][k][1]), point: {pixelsize:Ten, color:Cesium.Color.YELLOW}}); }}}). otherwise (function(error) {}); </Script></Body>

Normal JSON to Geojson reference http://blog.csdn.net/liyan_gis/article/details/50540842

Initial knowledge cesium----loading different JSON format examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.