-
-
Save shawncrawley/d82a95d081da014dd05a to your computer and use it in GitHub Desktop.
Code that yields a "Cannot set property 'geometry' of undefined" error from Cesium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make JSON call to EPA streams layer to return stream vector geometry within the viewport | |
Cesium.jsonp('http://watersgeo.epa.gov/arcgis/rest/services/NHDPlus_NP21/NHDSnapshot_NP21/MapServer/0/query',{ | |
parameters: { | |
geometryType: "esriGeometryPolygon", | |
geometry: geometry, | |
outFields: 'COMID', | |
inSR: '{"wkid" : 4326}', | |
outSR: '{"wkid" : 4326}', | |
f: 'json' | |
} | |
}) | |
.then(function(data) { | |
viewer.entities.suspendEvents(); | |
var numFeatures = data.features.length; | |
var selectedCOMIDS = []; | |
plotCountBefore = plotCounter; | |
plotCounter++; | |
for (var i = 0; i < numFeatures; i++) { | |
var entityCoords = []; | |
var numCoordinates = data.features[i].geometry.paths[0].length; | |
var coordinates = data.features[i].geometry.paths[0]; | |
for (var ii = 0; ii < numCoordinates; ii++) { | |
entityCoords.push(coordinates[ii][0]); | |
entityCoords.push(coordinates[ii][1]); | |
} | |
var comid = data.features[i].attributes.COMID; | |
selectedCOMIDS.push(comid); | |
selectedEntities.push(viewer.entities.add({ | |
id: comid, | |
polyline: { | |
positions: Cesium.Cartesian3.fromDegreesArray(entityCoords), | |
width: 2, | |
material: Cesium.Color.YELLOW | |
} | |
})); | |
var midPoint = entityCoords.length / 2; | |
var midIndex = midPoint % 2 == 0 ? midPoint : midPoint + 1; | |
var selectionName = getSelectionName(); | |
var showLabels = $('#labels-toggle').bootstrapSwitch('state'); | |
selectedLabels.push(viewer.entities.add({ | |
position: Cesium.Cartesian3.fromDegrees(entityCoords[midIndex], entityCoords[midIndex + 1]), | |
label: { | |
text: selectionName, | |
style: Cesium.LabelStyle.FILL_AND_OUTLINE, | |
outlineWidth: 2 | |
}, | |
id: (comid.toString() + "label"), | |
show: showLabels | |
})); | |
} | |
viewer.entities.resumeEvents(); | |
get_netcdf_chart_data(selectedCOMIDS); | |
}) | |
} | |
function get_netcdf_chart_data(comids) { | |
if (comids.constructor === Array) { | |
comids = comids.join(); | |
} | |
$.ajax({ | |
type: 'GET', | |
url: 'get-netcdf-data', | |
dataType: 'json', | |
data: {'comids': comids }, | |
success: function (data) { | |
if ("success" in data) { | |
if ("return_data" in data) { | |
var chart_data = JSON.parse(data.return_data); | |
var seriesCount = chart_data.length; | |
viewer.entities.suspendEvents(); | |
for (var i = 0; i < seriesCount; i++) { | |
for (var key in chart_data[i]) { | |
if (chart_data[i][key][0][1] == -9999) { | |
viewer.entities.removeById(key); | |
selectedEntities = $.grep(selectedEntities, function(e) { | |
return (e._id != key); | |
}); | |
viewer.entities.removeById(key.toString() + "label"); | |
selectedLabels = $.grep(selectedLabels, function(e) { | |
return (e._id != (key.toString() + "label")); | |
}); | |
} | |
} | |
} | |
viewer.entities.resumeEvents(); | |
} | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment