createOsmBuildings.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 deprecationWarning from "../Core/deprecationWarning.js";
  6. import IonResource from "../Core/IonResource.js";
  7. import Cesium3DTileset from "./Cesium3DTileset.js";
  8. import Cesium3DTileStyle from "./Cesium3DTileStyle.js";
  9. /**
  10. * Creates a {@link Cesium3DTileset} instance for the
  11. * {@link https://cesium.com/content/cesium-osm-buildings/|Cesium OSM Buildings}
  12. * tileset.
  13. *
  14. * @function
  15. *
  16. * @param {object} [options] Construction options. Any options allowed by the {@link Cesium3DTileset} constructor
  17. * may be specified here. In addition to those, the following properties are supported:
  18. * @param {Color} [options.defaultColor=Color.WHITE] The default color to use for buildings
  19. * that do not have a color. This parameter is ignored if <code>options.style</code> is specified.
  20. * @param {Cesium3DTileStyle} [options.style] The style to use with the tileset. If not
  21. * specified, a default style is used which gives each building or building part a
  22. * color inferred from its OpenStreetMap <code>tags</code>. If no color can be inferred,
  23. * <code>options.defaultColor</code> is used.
  24. * @param {boolean} [options.enableShowOutline=true] If true, enable rendering outlines. This can be set to false to avoid the additional processing of geometry at load time.
  25. * @param {boolean} [options.showOutline=true] Whether to show outlines around buildings. When true,
  26. * outlines are displayed. When false, outlines are not displayed.
  27. * @returns {Cesium3DTileset}
  28. *
  29. * @see Ion
  30. *
  31. * @example
  32. * // Create Cesium OSM Buildings with default styling
  33. * const viewer = new Cesium.Viewer('cesiumContainer');
  34. * viewer.scene.primitives.add(Cesium.createOsmBuildings());
  35. *
  36. * @example
  37. * // Create Cesium OSM Buildings with a custom style highlighting
  38. * // schools and hospitals.
  39. * viewer.scene.primitives.add(Cesium.createOsmBuildings({
  40. * style: new Cesium.Cesium3DTileStyle({
  41. * color: {
  42. * conditions: [
  43. * ["${feature['building']} === 'hospital'", "color('#0000FF')"],
  44. * ["${feature['building']} === 'school'", "color('#00FF00')"],
  45. * [true, "color('#ffffff')"]
  46. * ]
  47. * }
  48. * })
  49. * }));
  50. */
  51. function createOsmBuildings(options) {
  52. deprecationWarning(
  53. "createOsmBuildings",
  54. "createOsmBuildings was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use createOsmBuildingsAsync instead."
  55. );
  56. options = combine(options, {
  57. url: IonResource.fromAssetId(96188),
  58. });
  59. const tileset = new Cesium3DTileset(options);
  60. let style = options.style;
  61. if (!defined(style)) {
  62. const color = defaultValue(
  63. options.defaultColor,
  64. Color.WHITE
  65. ).toCssColorString();
  66. style = new Cesium3DTileStyle({
  67. color: `Boolean(\${feature['cesium#color']}) ? color(\${feature['cesium#color']}) : ${color}`,
  68. });
  69. }
  70. tileset.style = style;
  71. return tileset;
  72. }
  73. export default createOsmBuildings;