diff --git a/CHANGES.md b/CHANGES.md index 9b9a5249..2b1d1288 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Change Log +## ? - ? + +##### Additions :tada: + +- Added `CesiumGoogleMapTilesRasterOverlay` to stream imagery from Google Maps. +- Added `assetOptions` to `CesiumIonRasterOverlay` to pass JSON-string options to Cesium ion as it accesses an asset. + ## v1.18.1 - 2025-10-01 This release updates [cesium-native](https://github.com/CesiumGS/cesium-native) from v0.51.0 to v0.52.1. See the [changelog](https://github.com/CesiumGS/cesium-native/blob/main/CHANGES.md) for a complete list of changes in cesium-native. diff --git a/CONTRIBUTING.md.meta b/CONTRIBUTING.md.meta new file mode 100644 index 00000000..4c20f83c --- /dev/null +++ b/CONTRIBUTING.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3fd6df72dd74e4b4a9a1096d82b3e1b5 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs b/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs new file mode 100644 index 00000000..141a61e4 --- /dev/null +++ b/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs @@ -0,0 +1,166 @@ +using UnityEditor; +using UnityEngine; + +namespace CesiumForUnity +{ + [CustomEditor(typeof(CesiumGoogleMapTilesRasterOverlay))] + public class CesiumGoogleMapTilesRasterOverlayEditor : Editor + { + private CesiumRasterOverlayEditor _rasterOverlayEditor; + + private SerializedProperty _apiKey; + private SerializedProperty _mapType; + private SerializedProperty _language; + private SerializedProperty _region; + private SerializedProperty _scale; + private SerializedProperty _highDpi; + private SerializedProperty _layerTypes; + private SerializedProperty _styles; + private SerializedProperty _overlay; + + private string[] _scaleOptions; + private int _selectedScaleIndex; + + private void OnEnable() + { + this._rasterOverlayEditor = + (CesiumRasterOverlayEditor)Editor.CreateEditor( + this.target, + typeof(CesiumRasterOverlayEditor)); + + this._apiKey = this.serializedObject.FindProperty("_apiKey"); + this._mapType = this.serializedObject.FindProperty("_mapType"); + this._language = this.serializedObject.FindProperty("_language"); + this._region = this.serializedObject.FindProperty("_region"); + this._scale = this.serializedObject.FindProperty("_scale"); + this._highDpi = this.serializedObject.FindProperty("_highDpi"); + this._layerTypes = this.serializedObject.FindProperty("_layerTypes"); + this._styles = this.serializedObject.FindProperty("_styles"); + this._overlay = this.serializedObject.FindProperty("_overlay"); + + // Remove "ScaleFactor" prefix from the Scale enum options. + int nameOffset = ("ScaleFactor").Length; + this._scaleOptions = this._scale.enumNames; + for (int i = 0; i < this._scaleOptions.Length; i++) + { + this._scaleOptions[i] = this._scaleOptions[i].Substring(nameOffset); + } + this._selectedScaleIndex = this._scale.enumValueIndex; + } + + private void OnDisable() + { + if (this._rasterOverlayEditor != null) + { + DestroyImmediate(this._rasterOverlayEditor); + } + } + + public override void OnInspectorGUI() + { + this.serializedObject.Update(); + + EditorGUIUtility.labelWidth = CesiumEditorStyle.inspectorLabelWidth; + this.DrawGoogleMapTilesProperties(); + EditorGUILayout.Space(5); + this.DrawRasterOverlayProperties(); + + this.serializedObject.ApplyModifiedProperties(); + } + + private void DrawGoogleMapTilesProperties() + { + GUIContent apiKeyContent = new GUIContent( + "API Key", + "The Google Map Tiles API key to use."); + EditorGUILayout.DelayedTextField(this._apiKey, apiKeyContent); + + GUIContent mapTypeContent = new GUIContent( + "Map Type", + "The type of base map."); + EditorGUILayout.PropertyField(this._mapType, mapTypeContent); + + GUIContent languageContent = new GUIContent( + "Language", + "An IETF language tag that specifies the language used to display " + + "information on the tiles. For example, `en-US` specifies the " + + "English language as spoken in the United States."); + EditorGUILayout.DelayedTextField(this._language, languageContent); + + GUIContent regionContent = new GUIContent( + "Region", + "A Common Locale Data Repository region identifier (two uppercase " + + "letters) that represents the physical location of the user. For " + + "example, `US`."); + EditorGUILayout.DelayedTextField(this._region, regionContent); + + GUIContent scaleContent = new GUIContent( + "Scale", + "Scales-up the size of map elements (such as road labels), while " + + "retaining the tile size and coverage area of the default tile." + + "\n\n" + + "Increasing the scale also reduces the number of labels on the map, " + + "which reduces clutter."); + this._selectedScaleIndex = + EditorGUILayout.Popup(scaleContent, this._selectedScaleIndex, this._scaleOptions); + this._scale.enumValueIndex = this._selectedScaleIndex; + + GUIContent highDpiContent = new GUIContent( + "High DPI", + "Specifies whether to return high-resolution tiles." + + "\n\n" + + "If the scale-factor is increased, High DPI is used to increase the " + + "size of the tile. Normally, increasing the scale factor enlarges the " + + "resulting tile into an image of the same size, which lowers quality. " + + "With High DPI, the resulting size is also increased, preserving quality. " + + "DPI stands for Dots per Inch, and High DPI means the tile renders using " + + "more dots per inch than normal." + + "\n\n" + + "If enabled, the number of pixels in each of the x and y dimensions is " + + "multiplied by the scale factor (that is, 2x or 4x). The coverage area " + + "of the tile remains unchanged. This parameter works only with Scale " + + "values of 2x or 4x. It has no effect on 1x scale tiles."); + EditorGUILayout.PropertyField(this._highDpi, highDpiContent); + + GUIContent layerTypesContent = new GUIContent( + "Layer Types", + "The layer types to be added to the map."); + EditorGUILayout.PropertyField(this._layerTypes, layerTypesContent); + + GUIContent stylesContent = new GUIContent( + "Styles", + "A list of JSON style objects that specify the appearance and detail " + + "level of map features such as roads, parks, and built-up areas." + + "\n\n" + + "Styling is used to customize the standard Google base map. The Styles " + + "parameter is valid only if the Map Type is Roadmap."); + EditorGUILayout.PropertyField(this._styles, stylesContent); + + GUIContent overlayContent = new GUIContent( + "Overlay", + "Specifies whether Layer Types are rendered as a separate overlay, or " + + "combined with the base imagery." + + "\n\n" + + "When enabled, the base map isn't displayed. If you haven't defined any " + + "Layer Types, then this value is ignored."); + EditorGUILayout.PropertyField(this._overlay, overlayContent); + + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + if (EditorGUILayout.LinkButton("Map Tiles API Style reference")) + { + Application.OpenURL("https://developers.google.com/maps/documentation/tile/style-reference"); + } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + private void DrawRasterOverlayProperties() + { + if (this._rasterOverlayEditor != null) + { + this._rasterOverlayEditor.OnInspectorGUI(); + } + } + } +} diff --git a/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs.meta b/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs.meta new file mode 100644 index 00000000..3b6f442c --- /dev/null +++ b/Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 855b80a9fcf2d8b44a3845c463c5b8fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CesiumIonRasterOverlayEditor.cs b/Editor/CesiumIonRasterOverlayEditor.cs index 3eac0322..ce50bb42 100644 --- a/Editor/CesiumIonRasterOverlayEditor.cs +++ b/Editor/CesiumIonRasterOverlayEditor.cs @@ -12,6 +12,7 @@ public class CesiumIonRasterOverlayEditor : Editor private SerializedProperty _ionAssetID; private SerializedProperty _ionAccessToken; private SerializedProperty _ionServer; + private SerializedProperty _assetOptions; private void OnEnable() { @@ -24,6 +25,7 @@ private void OnEnable() this._ionAssetID = this.serializedObject.FindProperty("_ionAssetID"); this._ionAccessToken = this.serializedObject.FindProperty("_ionAccessToken"); this._ionServer = this.serializedObject.FindProperty("_ionServer"); + this._assetOptions = this.serializedObject.FindProperty("_assetOptions"); } private void OnDisable() @@ -74,6 +76,12 @@ private void DrawIonProperties() GUIContent ionServerContent = new GUIContent("ion Server", "The Cesium ion server to use."); EditorGUILayout.PropertyField(this._ionServer, ionServerContent); + + GUIContent assetOptionsContent = new GUIContent( + "Asset Options", + "Extra options to pass to Cesium ion when accessing the asset. " + + "This should be a JSON string."); + EditorGUILayout.DelayedTextField(this._assetOptions, assetOptionsContent); } private void DrawRasterOverlayProperties() diff --git a/Runtime/CesiumCreditSystem.cs b/Runtime/CesiumCreditSystem.cs index b1d02e7c..388474ed 100644 --- a/Runtime/CesiumCreditSystem.cs +++ b/Runtime/CesiumCreditSystem.cs @@ -304,7 +304,7 @@ internal IEnumerator LoadImage(string url) Debug.Log("Credit image could not be loaded into Texture2D."); } } - catch (FormatException e) + catch (FormatException) { Debug.Log("Could not parse credit image from base64 string."); } diff --git a/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs b/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs new file mode 100644 index 00000000..22647042 --- /dev/null +++ b/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs @@ -0,0 +1,282 @@ +using Reinterop; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace CesiumForUnity +{ + /// + /// The possible values of . + /// + public enum GoogleMapTilesMapType + { + /// + /// Satellite imagery. + /// + Satellite, + + /// + /// The standard Google Maps painted map tiles. + /// + Roadmap, + + /// + /// Terrain imagery. + /// + /// + /// When selecting terrain as the map type, you must also add + /// to + /// . + /// + Terrain + }; + + /// + /// The possible values of . + /// + public enum GoogleMapTilesScale + { + /// + /// The default. + /// + ScaleFactor1x, + + /// + /// Doubles label size and removes minor feature labels. + /// + ScaleFactor2x, + + /// + /// Quadruples label size and removes minor feature labels. + /// + ScaleFactor4x, + } + + /// + ///The possible values of . + /// + public enum GoogleMapTilesLayerType + { + /// + /// Required if you specify + /// as the map type. Can also be optionally overlaid on the satellite map type. + /// Has no effect on roadmap tiles. + /// + Roadmap, + + /// + /// Shows Street View-enabled streets and locations using blue outlines + /// on the map. + /// + Streetview, + + /// + /// Displays current traffic conditions. + /// + Traffic + }; + + /// + /// A raster overlay that directly accesses Google Map Tiles (2D). + /// If you're using Google Map Tiles via Cesium ion, use instead. + /// + [ReinteropNativeImplementation( + "CesiumForUnityNative::CesiumGoogleMapTilesRasterOverlayImpl", + "CesiumGoogleMapTilesRasterOverlayImpl.h")] + [AddComponentMenu("Cesium/Cesium Google Map Tiles Raster Overlay")] + [IconAttribute("Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")] + public partial class CesiumGoogleMapTilesRasterOverlay : CesiumRasterOverlay + { + + [SerializeField] + private string _apiKey = ""; + + /// + /// The Google Map Tiles API key to use. + /// + public string apiKey + { + get => this._apiKey; + set + { + this._apiKey = value; + this.Refresh(); + } + } + + [SerializeField] + private GoogleMapTilesMapType _mapType = GoogleMapTilesMapType.Satellite; + + /// + /// The type of base map. + /// + public GoogleMapTilesMapType mapType + { + get => this._mapType; + set + { + this._mapType = value; + this.Refresh(); + } + } + + [SerializeField] + private string _language = "en-US"; + + /// + /// An IETF language tag that specifies the language used to display + /// information on the tiles. For example, en-US specifies the English + /// language as spoken in the United States. + /// + public string language + { + get => this._language; + set + { + this._language = value; + this.Refresh(); + } + } + + [SerializeField] + private string _region = "US"; + + /// + /// A Common Locale Data Repository region identifier (two uppercase letters) + /// that represents the physical location of the user. For example, US. + /// + public string region + { + get => this._region; + set + { + this._region = value; + this.Refresh(); + } + } + + [SerializeField] + private GoogleMapTilesScale _scale = GoogleMapTilesScale.ScaleFactor1x; + + /// + /// Scales-up the size of map elements (such as road labels), while + /// retaining the tile size and coverage area of the default tile. + /// + /// + /// Increasing the scale also reduces the number of labels on the map, which + /// reduces clutter. + /// + public GoogleMapTilesScale scale + { + get => this._scale; + set + { + this._scale = value; + this.Refresh(); + } + } + + [SerializeField] + private bool _highDpi; + + /// + /// Specifies whether to return high-resolution tiles. + /// + /// + /// If the scale-factor is increased, highDpi is used to increase + /// the size of the tile. Normally, increasing the scale factor enlarges the + /// resulting tile into an image of the same size, which lowers quality. With + /// highDpi, the resulting size is also increased, preserving quality. + /// DPI stands for Dots per Inch, and High DPI means the tile renders using + /// more dots per inch than normal. + /// + /// + /// If true, then the number of pixels in each of the x and y + /// dimensions is multiplied by the scale factor (that is, 2x or 4x). The + /// coverage area of the tile remains unchanged. This parameter works only + /// with values of 2x or 4x. It has no + /// effect on 1x scale tiles. + /// + /// + public bool highDpi + { + get => this._highDpi; set + { + this._highDpi = value; + this.Refresh(); + } + } + + [SerializeField] + private List _layerTypes; + + /// + /// The layer types to be added to the map. + /// + public List layerTypes + { + get => this._layerTypes; + set + { + this._layerTypes = value; + this.Refresh(); + } + } + + [SerializeField] + private List _styles; + + /// + /// A list of JSON style objects that specify the appearance and + /// detail level of map features such as roads, parks, and built-up areas. + /// + /// + /// + /// Styling is used to customize the standard Google base map. The styles + /// parameter is valid only if the is + /// . + /// + /// + /// For the complete style syntax, see the + /// + /// Style Reference. + /// + /// + public List styles + { + get => this._styles; + set + { + this._styles = value; + this.Refresh(); + } + } + + [SerializeField] + private bool _overlay = false; + + /// + /// Specifies whether are rendered as a separate overlay, + /// or combined with the base imagery. + /// + /// + /// When true, the base map isn't displayed. If you haven't defined any + /// layerTypes, then this value is ignored. + /// + public bool overlay + { + get => this._overlay; + set + { + this._overlay = value; + this.Refresh(); + } + } + + /// + protected override partial void AddToTileset(Cesium3DTileset tileset); + + /// + protected override partial void RemoveFromTileset(Cesium3DTileset tileset); + }; +} \ No newline at end of file diff --git a/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs.meta b/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs.meta new file mode 100644 index 00000000..a3258638 --- /dev/null +++ b/Runtime/CesiumGoogleMapsTilesRasterOverlay.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e7cae66d51653994b8eed3a36ff03914 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CesiumIonRasterOverlay.cs b/Runtime/CesiumIonRasterOverlay.cs index 7374c9ab..5874ac34 100644 --- a/Runtime/CesiumIonRasterOverlay.cs +++ b/Runtime/CesiumIonRasterOverlay.cs @@ -78,6 +78,23 @@ public CesiumIonServer ionServer } } + [SerializeField] + private string _assetOptions = ""; + + /// + /// Extra options to pass to Cesium ion when accessing the asset. + /// This should be a JSON string. + /// + public string assetOptions + { + get => this._assetOptions; + set + { + this._assetOptions = value; + this.Refresh(); + } + } + /// protected override partial void AddToTileset(Cesium3DTileset tileset); /// diff --git a/Runtime/ConfigureReinterop.cs b/Runtime/ConfigureReinterop.cs index f99d7b78..e3b19a26 100644 --- a/Runtime/ConfigureReinterop.cs +++ b/Runtime/ConfigureReinterop.cs @@ -77,7 +77,7 @@ public void ExposeToCPP() int pixelWidth = c.pixelWidth; float aspect = c.aspect; bool isOrtho = c.orthographic; - float orthoSize = c.orthographicSize; + float orthoSize = c.orthographicSize; //IFormattable f = new Vector3(); //IEquatable f2 = new Vector3(); @@ -300,6 +300,7 @@ public void ExposeToCPP() ionOverlay.ionAssetID = ionOverlay.ionAssetID; ionOverlay.ionAccessToken = ionOverlay.ionAccessToken; ionOverlay.ionServer = ionOverlay.ionServer; + ionOverlay.assetOptions = ionOverlay.assetOptions; ionOverlay.AddToTilesetLater(null); CesiumRasterOverlay overlay = go.GetComponent(); @@ -320,6 +321,23 @@ public void ExposeToCPP() bingMapsRasterOverlay.mapStyle = bingMapsRasterOverlay.mapStyle; baseOverlay = bingMapsRasterOverlay; + CesiumGoogleMapTilesRasterOverlay googleMapTilesRasterOverlay = + go.GetComponent(); + googleMapTilesRasterOverlay.apiKey = googleMapTilesRasterOverlay.apiKey; + googleMapTilesRasterOverlay.mapType = googleMapTilesRasterOverlay.mapType; + googleMapTilesRasterOverlay.language = googleMapTilesRasterOverlay.language; + googleMapTilesRasterOverlay.region = googleMapTilesRasterOverlay.region; + googleMapTilesRasterOverlay.scale = googleMapTilesRasterOverlay.scale; + googleMapTilesRasterOverlay.highDpi = googleMapTilesRasterOverlay.highDpi; + googleMapTilesRasterOverlay.layerTypes = googleMapTilesRasterOverlay.layerTypes; + googleMapTilesRasterOverlay.styles = googleMapTilesRasterOverlay.styles; + googleMapTilesRasterOverlay.overlay = googleMapTilesRasterOverlay.overlay; + baseOverlay = googleMapTilesRasterOverlay; + + List layers = new List(); + if (layers.Count > 0) + layers[0] = layers[0]; + CesiumTileMapServiceRasterOverlay tileMapServiceRasterOverlay = go.GetComponent(); tileMapServiceRasterOverlay.url = tileMapServiceRasterOverlay.url; diff --git a/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.cpp b/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.cpp new file mode 100644 index 00000000..6d175d57 --- /dev/null +++ b/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.cpp @@ -0,0 +1,194 @@ +#include "CesiumGoogleMapTilesRasterOverlayImpl.h" + +#include "Cesium3DTilesetImpl.h" +#include "CesiumRasterOverlayUtility.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Cesium3DTilesSelection; +using namespace CesiumJsonReader; +using namespace CesiumRasterOverlays; +using namespace CesiumUtility; +using namespace DotNet; + +namespace CesiumForUnityNative { + +namespace { +std::string getMapType(CesiumForUnity::GoogleMapTilesMapType mapType) { + switch (mapType) { + case CesiumForUnity::GoogleMapTilesMapType::Roadmap: + return CesiumRasterOverlays::GoogleMapTilesMapType::roadmap; + case CesiumForUnity::GoogleMapTilesMapType::Terrain: + return CesiumRasterOverlays::GoogleMapTilesMapType::terrain; + case CesiumForUnity::GoogleMapTilesMapType::Satellite: + default: + return CesiumRasterOverlays::GoogleMapTilesMapType::satellite; + } +} + +std::string getScale(CesiumForUnity::GoogleMapTilesScale scale) { + switch (scale) { + case CesiumForUnity::GoogleMapTilesScale::ScaleFactor4x: + return CesiumRasterOverlays::GoogleMapTilesScale::scaleFactor4x; + case CesiumForUnity::GoogleMapTilesScale::ScaleFactor2x: + return CesiumRasterOverlays::GoogleMapTilesScale::scaleFactor2x; + case CesiumForUnity::GoogleMapTilesScale::ScaleFactor1x: + default: + return CesiumRasterOverlays::GoogleMapTilesScale::scaleFactor1x; + } +} + +std::optional> getLayerTypes( + const DotNet::System::Collections::Generic::List1< + CesiumForUnity::GoogleMapTilesLayerType>& layerTypes, + CesiumForUnity::GoogleMapTilesMapType mapType) { + std::vector result; + + bool hasRoadmap = false; + + int32_t count = layerTypes.Count(); + if (count > 0) { + result.reserve(count); + + for (int32_t i = 0; i < count; i++) { + CesiumForUnity::GoogleMapTilesLayerType layerType = layerTypes[i]; + switch (layerType) { + case CesiumForUnity::GoogleMapTilesLayerType::Roadmap: + hasRoadmap = true; + result.emplace_back(GoogleMapTilesLayerType::layerRoadmap); + break; + case CesiumForUnity::GoogleMapTilesLayerType::Streetview: + result.emplace_back(GoogleMapTilesLayerType::layerStreetview); + break; + case CesiumForUnity::GoogleMapTilesLayerType::Traffic: + result.emplace_back(GoogleMapTilesLayerType::layerTraffic); + break; + } + } + } + + if (mapType == CesiumForUnity::GoogleMapTilesMapType::Terrain && + !hasRoadmap) { + UnityEngine::Debug::LogWarning(System::String( + "When the mapType is set to Terrain on " + "CesiumGoogleMapTilesRasterOverlay, layerTypes must contain " + "Roadmap.")); + } + + return result; +} + +JsonValue::Array getStyles( + const DotNet::System::Collections::Generic::List1& + styles) { + int32_t count = styles.Count(); + + JsonValue::Array result; + result.reserve(count); + + JsonObjectJsonHandler handler{}; + + for (int32_t i = 0; i < count; ++i) { + const System::String& style = styles[i]; + std::string styleUtf8 = style.ToStlString(); + ReadJsonResult response = JsonReader::readJson( + std::span( + reinterpret_cast(styleUtf8.data()), + styleUtf8.size()), + handler); + + ErrorList errorList; + errorList.errors = std::move(response.errors); + errorList.warnings = std::move(response.warnings); + errorList.log( + spdlog::default_logger(), + fmt::format("Problems parsing JSON in element {} of Styles:", i)); + + if (response.value) { + result.emplace_back(std::move(*response.value)); + } + } + + return result; +} + +} // namespace + +CesiumGoogleMapTilesRasterOverlayImpl::CesiumGoogleMapTilesRasterOverlayImpl( + const DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& overlay) + : _pOverlay(nullptr) {} + +CesiumGoogleMapTilesRasterOverlayImpl:: + ~CesiumGoogleMapTilesRasterOverlayImpl() {} + +void CesiumGoogleMapTilesRasterOverlayImpl::AddToTileset( + const ::DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& overlay, + const ::DotNet::CesiumForUnity::Cesium3DTileset& tileset) { + if (this->_pOverlay != nullptr) { + // Overlay already added. + return; + } + + if (System::String::IsNullOrEmpty(overlay.apiKey())) { + // Don't create an overlay with an empty API key. + return; + } + + Cesium3DTilesetImpl& tilesetImpl = tileset.NativeImplementation(); + Tileset* pTileset = tilesetImpl.getTileset(); + if (!pTileset) + return; + + CesiumForUnity::CesiumRasterOverlay genericOverlay = overlay; + RasterOverlayOptions options = + CesiumRasterOverlayUtility::GetOverlayOptions(genericOverlay); + + this->_pOverlay = new GoogleMapTilesRasterOverlay( + overlay.materialKey().ToStlString(), + CesiumRasterOverlays::GoogleMapTilesNewSessionParameters{ + .key = overlay.apiKey().ToStlString(), + .mapType = getMapType(overlay.mapType()), + .language = overlay.language().ToStlString(), + .region = overlay.region().ToStlString(), + .scale = getScale(overlay.scale()), + .highDpi = overlay.highDpi(), + .layerTypes = getLayerTypes(overlay.layerTypes(), overlay.mapType()), + .styles = getStyles(overlay.styles()), + .overlay = overlay.overlay()}, + options); + + pTileset->getOverlays().add(this->_pOverlay); +} +void CesiumGoogleMapTilesRasterOverlayImpl::RemoveFromTileset( + const ::DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& overlay, + const ::DotNet::CesiumForUnity::Cesium3DTileset& tileset) { + if (this->_pOverlay == nullptr) + return; + + Cesium3DTilesetImpl& tilesetImpl = tileset.NativeImplementation(); + Tileset* pTileset = tilesetImpl.getTileset(); + if (!pTileset) + return; + + CesiumUtility::IntrusivePointer + pOverlay = this->_pOverlay.get(); + pTileset->getOverlays().remove(pOverlay); + this->_pOverlay = nullptr; +} + +} // namespace CesiumForUnityNative diff --git a/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.h b/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.h new file mode 100644 index 00000000..3a7722c9 --- /dev/null +++ b/native~/Runtime/src/CesiumGoogleMapTilesRasterOverlayImpl.h @@ -0,0 +1,40 @@ +#pragma once + +#include "CesiumImpl.h" + +#include + +namespace DotNet::CesiumForUnity { +class Cesium3DTileset; +class CesiumGoogleMapTilesRasterOverlay; +} // namespace DotNet::CesiumForUnity + +namespace CesiumRasterOverlays { +class GoogleMapTilesRasterOverlay; +} + +namespace CesiumForUnityNative { + +class CesiumGoogleMapTilesRasterOverlayImpl + : public CesiumImpl { +public: + CesiumGoogleMapTilesRasterOverlayImpl( + const DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& overlay); + ~CesiumGoogleMapTilesRasterOverlayImpl(); + + void AddToTileset( + const ::DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& + overlay, + const ::DotNet::CesiumForUnity::Cesium3DTileset& tileset); + void RemoveFromTileset( + const ::DotNet::CesiumForUnity::CesiumGoogleMapTilesRasterOverlay& + overlay, + const ::DotNet::CesiumForUnity::Cesium3DTileset& tileset); + +private: + CesiumUtility::IntrusivePointer< + CesiumRasterOverlays::GoogleMapTilesRasterOverlay> + _pOverlay; +}; + +} // namespace CesiumForUnityNative diff --git a/native~/Runtime/src/CesiumIonRasterOverlayImpl.cpp b/native~/Runtime/src/CesiumIonRasterOverlayImpl.cpp index 751433c6..3906afe2 100644 --- a/native~/Runtime/src/CesiumIonRasterOverlayImpl.cpp +++ b/native~/Runtime/src/CesiumIonRasterOverlayImpl.cpp @@ -67,6 +67,10 @@ void CesiumIonRasterOverlayImpl::AddToTileset( options, apiUrl); + if (!System::String::IsNullOrEmpty(overlay.assetOptions())) { + this->_pOverlay->setAssetOptions(overlay.assetOptions().ToStlString()); + } + pTileset->getOverlays().add(this->_pOverlay); } else { // Resolve the API URL if it's not already in progress. diff --git a/native~/extern/cesium-native b/native~/extern/cesium-native index 126a412a..6da0610f 160000 --- a/native~/extern/cesium-native +++ b/native~/extern/cesium-native @@ -1 +1 @@ -Subproject commit 126a412a791dd596c5ed81c05ef2443339c64ff8 +Subproject commit 6da0610f3c83c9f543e8384faf7b7d9025c68081