Country JSON File

346 views
Skip to first unread message

Megha Prajapati

unread,
Jun 21, 2019, 6:08:09 AM6/21/19
to cesium-dev
1. A concise explanation of the problem you're experiencing.

I need to load all countries JSON File in GeoJsonDataSource.load.How can I get this source file? Can you please provide the all counties JSON file?

I have downloaded the ne_10m_admin_0_countries2.json file from forums support but I am getting the below error in console.
An error occurred while rendering. Rendering has stopped. undefined DeveloperError: normalized result is not a number Error at new DeveloperError (http://localhost/Cesium-1.58/Source/Core/DeveloperError.js:43:19) at Function.Cartesian3.normalize (http://localhost/Cesium-1.58/Source/Core/Cartesian3.js:421:19) at Ellipsoid.geodeticSurfaceNormalCartographic (http://localhost/Cesium-1.58/Source/Core/Ellipsoid.js:353:27) at Ellipsoid.cartographicToCartesian (http://localhost/Cesium-1.58/Source/Core/Ellipsoid.js:390:14) at Object.PolygonGeometryLibrary.subdivideRhumbLine (http://localhost/Cesium-1.58/Source/Core/PolygonGeometryLibrary.js:212:31) at createGeometryFromPositions (http://localhost/Cesium-1.58/Source/Core/PolygonOutlineGeometry.js:90:60) at Function.PolygonOutlineGeometry.createGeometry (http://localhost/Cesium-1.58/Source/Core/PolygonOutlineGeometry.js:555:36) at createPolygonOutlineGeometry (http://localhost/Cesium-1.58/Source/Workers/createPolygonOutlineGeometry.js:16:39) at createGeometry (http://localhost/Cesium-1.58/Source/Workers/createGeometry.js:47:40) at callAndWrap (http://localhost/Cesium-1.58/Source/Workers/createTaskProcessorWorker.js:20:31)
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
/*This is my current code*/
var viewer = new Cesium.Viewer('cesiumContainer');

var highlightedEntity;
var highlightColor = Cesium.Color.YELLOW.withAlpha(0.6);
var normalColor = Cesium.Color.SLATEGREY.withAlpha(0.6);

//A property that returns a highlight color if the entity is currently moused over, or a default color otherwise.
function createCallback(entity){
    var colorProperty = new Cesium.CallbackProperty(function(time, result){
        if(highlightedEntity === entity){
            return Cesium.Color.clone(highlightColor, result);
        }
        return Cesium.Color.clone(normalColor, result);
    }, false);
    
    return new Cesium.ColorMaterialProperty(colorProperty);
}

var promise = Cesium.GeoJsonDataSource.load('../../SampleData/ne_10m_admin_0_countries2.json');
promise.then(function(dataSource) {
    viewer.dataSources.add(dataSource);
    
    //Get the array of entities
    var entities = dataSource.entities.values;
    
    for (var i = 0; i < entities.length; i++) {
        var entity = entities[i];
        entity.polygon.material = createCallback(entity);
    }
}).otherwise(function(error){
    //Display any errrors encountered while loading.
    window.alert(error);
});

var scene = viewer.scene;
var handler = viewer.screenSpaceEventHandler;
handler.setInputAction(function(movement) {
    var pickedObject = scene.pick(movement.endPosition);
    if (Cesium.defined(pickedObject) && pickedObject.id instanceof Cesium.Entity) {
        highlightedEntity = pickedObject.id;
    } else{
        highlightedEntity = undefined;
    }
    
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);



3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

- I want to highlight the country when hovering over the county and appears the country name also.

- I need to load all countries JSON File in GeoJsonDataSource.load.How can I get this source file? Can you please provide the all counties JSON file?

- I have downloaded the ne_10m_admin_0_countries2.json file from forums support but I am getting the below error in console.

- Is it possible to set URL on click of any country? How can I achieve this? Which Parameter do we need to pass in the JSON Data?

4. The Cesium version you're using, your operating system and browser.
- Cesium Version: 1.58
- Browser: Google Chrome
- Operating System: Windows


Megha Prajapati

unread,
Jun 21, 2019, 6:25:53 AM6/21/19
to cesium-dev
Below Code is working for the US states


var viewer = new Cesium.Viewer('cesiumContainer');

var highlightedEntity;
var highlightColor = Cesium.Color.YELLOW.withAlpha(0.6);
var normalColor = Cesium.Color.SLATEGREY.withAlpha(0.6);

//A property that returns a highlight color if the entity is currently moused over, or a default color otherwise.
function createCallback(entity){
    var colorProperty = new Cesium.CallbackProperty(function(time, result){
        if(highlightedEntity === entity){
            return Cesium.Color.clone(highlightColor, result);
        }
        return Cesium.Color.clone(normalColor, result);
    }, false);
   
    return new Cesium.ColorMaterialProperty(colorProperty);
}

var promise = Cesium.GeoJsonDataSource.load('../../SampleData/ne_10m_us_states.topojson');

promise.then(function(dataSource) {
    viewer.dataSources.add(dataSource);
   
    //Get the array of entities
    var entities = dataSource.entities.values;
   
    for (var i = 0; i < entities.length; i++) {
        var entity = entities[i];
        entity.polygon.material = createCallback(entity);
    }
}).otherwise(function(error){
    //Display any errrors encountered while loading.
    window.alert(error);
});

var scene = viewer.scene;
var handler = viewer.screenSpaceEventHandler;
handler.setInputAction(function(movement) {
    var pickedObject = scene.pick(movement.endPosition);
    if (Cesium.defined(pickedObject) && pickedObject.id instanceof Cesium.Entity) {
        highlightedEntity = pickedObject.id;
    } else{
        highlightedEntity = undefined;
    }
   
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

---------------------------

I want the same for all the countries for this I need countries JSON same as the attached  JSON.

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cesium-dev/f4ac2061-7569-48a3-8228-9e2d9f3080ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ne_10m_us_states.topojson

Omar Shehata

unread,
Jun 26, 2019, 10:13:47 AM6/26/19
to cesium-dev
Can you post the JSON file that's producing this error? It might be related to this issue: https://github.com/AnalyticalGraphicsInc/cesium/issues/7864

Where this GeoJSON of all the countries used to work in CesiumJS 1.53.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages