createOsmBuildings.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Color from "../Core/Color.js";
  2. import combine from "../Core/combine.js";
  3. import defaultValue from "../Core/defaultValue.js";
  4. import defined from "../Core/defined.js";
  5. import IonResource from "../Core/IonResource.js";
  6. import Cesium3DTileset from "./Cesium3DTileset.js";
  7. import Cesium3DTileStyle from "./Cesium3DTileStyle.js";
  8. /**
  9. * Creates a {@link Cesium3DTileset} instance for the
  10. * {@link https://cesium.com/content/cesium-osm-buildings/|Cesium OSM Buildings}
  11. * tileset.
  12. *
  13. * @function
  14. *
  15. * @param {Object} [options] Construction options. Any options allowed by the {@link Cesium3DTileset} constructor
  16. * may be specified here. In addition to those, the following properties are supported:
  17. * @param {Color} [options.defaultColor=Color.WHITE] The default color to use for buildings
  18. * that do not have a color. This parameter is ignored if <code>options.style</code> is specified.
  19. * @param {Cesium3DTileStyle} [options.style] The style to use with the tileset. If not
  20. * specified, a default style is used which gives each building or building part a
  21. * color inferred from its OpenStreetMap <code>tags</code>. If no color can be inferred,
  22. * <code>options.defaultColor</code> is used.
  23. * @returns {Cesium3DTileset}
  24. *
  25. * @see Ion
  26. *
  27. * @example
  28. * // Create Cesium OSM Buildings with default styling
  29. * var viewer = new Cesium.Viewer('cesiumContainer');
  30. * viewer.scene.primitives.add(Cesium.createOsmBuildings());
  31. *
  32. * @example
  33. * // Create Cesium OSM Buildings with a custom style highlighting
  34. * // schools and hospitals.
  35. * viewer.scene.primitives.add(Cesium.createOsmBuildings({
  36. * style: new Cesium.Cesium3DTileStyle({
  37. * color: {
  38. * conditions: [
  39. * ["${feature['building']} === 'hospital'", "color('#0000FF')"],
  40. * ["${feature['building']} === 'school'", "color('#00FF00')"],
  41. * [true, "color('#ffffff')"]
  42. * ]
  43. * }
  44. * })
  45. * }));
  46. */
  47. function createOsmBuildings(options) {
  48. options = combine(options, {
  49. url: IonResource.fromAssetId(96188),
  50. });
  51. var tileset = new Cesium3DTileset(options);
  52. var style = options.style;
  53. if (!defined(style)) {
  54. var color = defaultValue(
  55. options.defaultColor,
  56. Color.WHITE
  57. ).toCssColorString();
  58. style = new Cesium3DTileStyle({
  59. color:
  60. "Boolean(${feature['cesium#color']}) ? color(${feature['cesium#color']}) : " +
  61. color,
  62. });
  63. }
  64. tileset.style = style;
  65. return tileset;
  66. }
  67. export default createOsmBuildings;