From 78d63c646c16a5715548f75b9baa3d2793d3179e Mon Sep 17 00:00:00 2001 From: Arthur Street Date: Wed, 28 Oct 2015 17:13:41 +1100 Subject: [PATCH 1/4] describe geoJson keys without underscores (if using my cesium changes) --- lib/Models/GeoJsonCatalogItem.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/Models/GeoJsonCatalogItem.js b/lib/Models/GeoJsonCatalogItem.js index 7245d894a3e..99af5262f86 100644 --- a/lib/Models/GeoJsonCatalogItem.js +++ b/lib/Models/GeoJsonCatalogItem.js @@ -6,6 +6,7 @@ var proj4 = require('proj4'); var CesiumMath = require('terriajs-cesium/Source/Core/Math'); var Color = require('terriajs-cesium/Source/Core/Color'); var defined = require('terriajs-cesium/Source/Core/defined'); +var definedNotNull = require('terriajs-cesium/Source/Core/definedNotNull'); var defineProperties = require('terriajs-cesium/Source/Core/defineProperties'); var DeveloperError = require('terriajs-cesium/Source/Core/DeveloperError'); var GeoJsonDataSource = require('terriajs-cesium/Source/DataSources/GeoJsonDataSource'); @@ -154,8 +155,37 @@ GeoJsonCatalogItem.prototype._getValuesThatInfluenceLoad = function() { var zipFileRegex = /.zip\b/i; var geoJsonRegex = /.geojson\b/i; +var simpleStyleIdentifiers = ['title', 'description', // +'marker-size', 'marker-symbol', 'marker-color', 'stroke', // +'stroke-opacity', 'stroke-width', 'fill', 'fill-opacity']; + +// this next function modelled on Cesium.geoJsonDataSource's defaultDescribe +function describeWithoutUnderscores(properties, nameProperty) { + var html = ''; + for ( var key in properties) { + if (properties.hasOwnProperty(key)) { + if (key === nameProperty || simpleStyleIdentifiers.indexOf(key) !== -1) { + continue; + } + var value = properties[key]; + key = key.replace(/_/g, ' '); + if (definedNotNull(value)) { + if (typeof value === 'object') { + html += '' + key + '' + describeWithoutUnderscores(value) + ''; + } else { + html += '' + key + '' + value + ''; + } + } + } + } + if (html.length > 0) { + html = '' + html + '
'; + } + return html; +} + GeoJsonCatalogItem.prototype._load = function() { - this._dataSource = new GeoJsonDataSource(this.name); + this._dataSource = new GeoJsonDataSource(this.name, describeWithoutUnderscores); var that = this; From 7cebc77145a40f71271d113ff3f32817f0cf1deb Mon Sep 17 00:00:00 2001 From: Arthur Street Date: Thu, 29 Oct 2015 10:00:44 +1100 Subject: [PATCH 2/4] use load options to specify geoJson describe function --- lib/Models/GeoJsonCatalogItem.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/Models/GeoJsonCatalogItem.js b/lib/Models/GeoJsonCatalogItem.js index 99af5262f86..1128dc1d839 100644 --- a/lib/Models/GeoJsonCatalogItem.js +++ b/lib/Models/GeoJsonCatalogItem.js @@ -185,7 +185,7 @@ function describeWithoutUnderscores(properties, nameProperty) { } GeoJsonCatalogItem.prototype._load = function() { - this._dataSource = new GeoJsonDataSource(this.name, describeWithoutUnderscores); + this._dataSource = new GeoJsonDataSource(this.name); var that = this; @@ -396,7 +396,7 @@ function loadGeoJson(geoJsonItem) { /* Style information is applied as follows, in decreasing priority: - simple-style properties set directly on individual features in the GeoJSON file - simple-style properties set as the 'Style' property on the catalog item - - our 'defaultStyles' set below (and point styling applied after Cesium loads the GeoJSON) + - our 'options' set below (and point styling applied after Cesium loads the GeoJSON) - if anything is underspecified there, then Cesium's defaults come in. See https://github.com/mapbox/simplestyle-spec/tree/master/1.1.0 @@ -438,7 +438,8 @@ function loadGeoJson(geoJsonItem) { var style = defaultValue(geoJsonItem.style, {}); - var defaultStyles = { + var options = { + describe: describeWithoutUnderscores, markerSize : defaultValue(parseMarkerSize(style['marker-size']), 20), markerSymbol: style['marker-symbol'], // and undefined if none markerColor : defaultColor(style['marker-color'], pointPalette), @@ -447,17 +448,17 @@ function loadGeoJson(geoJsonItem) { markerOpacity: style['marker-opacity'] // not in SimpleStyle spec or supported by Cesium but see below }; - defaultStyles.fill = defaultColor(style.fill, defaultStyles.stroke.clone); + options.fill = defaultColor(style.fill, options.stroke.clone); if (defined(style['stroke-opacity'])) { - defaultStyles.stroke.alpha = Number.parseFloat(style['stroke-opacity']); + options.stroke.alpha = Number.parseFloat(style['stroke-opacity']); } if (defined(style['fill-opacity'])) { - defaultStyles.fill.alpha = Number.parseFloat(style['fill-opacity']); + options.fill.alpha = Number.parseFloat(style['fill-opacity']); } else { - defaultStyles.fill.alpha = 0.75; + options.fill.alpha = 0.75; } - return dataSource.load(geoJsonItem._readyData, defaultStyles).then(function() { + return dataSource.load(geoJsonItem._readyData, options).then(function() { var entities = dataSource.entities.values; for (var i = 0; i < entities.length; ++i) { @@ -467,10 +468,10 @@ function loadGeoJson(geoJsonItem) { a filled circle instead of the default marker. */ if (defined(entity.billboard) && !defined(entity.properties['marker-symbol']) && - !defined(defaultStyles.markerSymbol)) { + !defined(options.markerSymbol)) { entity.point = new PointGraphics({ - color: defaultStyles.markerColor, - pixelSize: defaultStyles.markerSize / 2, + color: options.markerColor, + pixelSize: options.markerSize / 2, outlineWidth: 1, outlineColor: Color.BLACK }); From ce2c12f8d436b482b3bbc7339382abf5f92b535a Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Thu, 5 Nov 2015 14:44:42 +1100 Subject: [PATCH 3/4] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 58a116635c5..ac830e68f6a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Change Log ### 1.0.47 * The `name` of a feature from a CSV file is now taken from a `name` or `title` column, if it exists. Previously the name was always "Site Data". +* Underscores are now replaced with spaces in feature info panel for `GeoJsonCatalogItem`. * Updated to [Cesium](http://cesiumjs.org) 1.15. Significant changes relevant to TerriaJS users include: * Added support for the [glTF 1.0](https://github.com/KhronosGroup/glTF/blob/master/specification/README.md) draft specification. * Added support for the glTF extensions [KHR_binary_glTF](https://github.com/KhronosGroup/glTF/tree/master/extensions/Khronos/KHR_binary_glTF) and [KHR_materials_common](https://github.com/KhronosGroup/glTF/tree/KHR_materials_common/extensions/Khronos/KHR_materials_common). From eba3a40d7b13f79101bb33faa0ef11057b39f663 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Thu, 5 Nov 2015 14:45:04 +1100 Subject: [PATCH 4/4] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ac830e68f6a..aa6feffd9c0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Change Log ### 1.0.47 * The `name` of a feature from a CSV file is now taken from a `name` or `title` column, if it exists. Previously the name was always "Site Data". -* Underscores are now replaced with spaces in feature info panel for `GeoJsonCatalogItem`. +* Underscores are now replaced with spaces in the feature info panel for `GeoJsonCatalogItem`. * Updated to [Cesium](http://cesiumjs.org) 1.15. Significant changes relevant to TerriaJS users include: * Added support for the [glTF 1.0](https://github.com/KhronosGroup/glTF/blob/master/specification/README.md) draft specification. * Added support for the glTF extensions [KHR_binary_glTF](https://github.com/KhronosGroup/glTF/tree/master/extensions/Khronos/KHR_binary_glTF) and [KHR_materials_common](https://github.com/KhronosGroup/glTF/tree/KHR_materials_common/extensions/Khronos/KHR_materials_common).