Skip to content

Commit a6d1e31

Browse files
authored
Merge pull request #612 from CesiumGS/google-overlay
Add `CesiumGoogleMapTilesRasterOverlay` to stream Google Maps 2D Tiles
2 parents d098c2d + 4537425 commit a6d1e31

14 files changed

+768
-3
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## ? - ?
4+
5+
##### Additions :tada:
6+
7+
- Added `CesiumGoogleMapTilesRasterOverlay` to stream imagery from Google Maps.
8+
- Added `assetOptions` to `CesiumIonRasterOverlay` to pass JSON-string options to Cesium ion as it accesses an asset.
9+
310
## v1.18.1 - 2025-10-01
411

512
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.

CONTRIBUTING.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace CesiumForUnity
5+
{
6+
[CustomEditor(typeof(CesiumGoogleMapTilesRasterOverlay))]
7+
public class CesiumGoogleMapTilesRasterOverlayEditor : Editor
8+
{
9+
private CesiumRasterOverlayEditor _rasterOverlayEditor;
10+
11+
private SerializedProperty _apiKey;
12+
private SerializedProperty _mapType;
13+
private SerializedProperty _language;
14+
private SerializedProperty _region;
15+
private SerializedProperty _scale;
16+
private SerializedProperty _highDpi;
17+
private SerializedProperty _layerTypes;
18+
private SerializedProperty _styles;
19+
private SerializedProperty _overlay;
20+
21+
private string[] _scaleOptions;
22+
private int _selectedScaleIndex;
23+
24+
private void OnEnable()
25+
{
26+
this._rasterOverlayEditor =
27+
(CesiumRasterOverlayEditor)Editor.CreateEditor(
28+
this.target,
29+
typeof(CesiumRasterOverlayEditor));
30+
31+
this._apiKey = this.serializedObject.FindProperty("_apiKey");
32+
this._mapType = this.serializedObject.FindProperty("_mapType");
33+
this._language = this.serializedObject.FindProperty("_language");
34+
this._region = this.serializedObject.FindProperty("_region");
35+
this._scale = this.serializedObject.FindProperty("_scale");
36+
this._highDpi = this.serializedObject.FindProperty("_highDpi");
37+
this._layerTypes = this.serializedObject.FindProperty("_layerTypes");
38+
this._styles = this.serializedObject.FindProperty("_styles");
39+
this._overlay = this.serializedObject.FindProperty("_overlay");
40+
41+
// Remove "ScaleFactor" prefix from the Scale enum options.
42+
int nameOffset = ("ScaleFactor").Length;
43+
this._scaleOptions = this._scale.enumNames;
44+
for (int i = 0; i < this._scaleOptions.Length; i++)
45+
{
46+
this._scaleOptions[i] = this._scaleOptions[i].Substring(nameOffset);
47+
}
48+
this._selectedScaleIndex = this._scale.enumValueIndex;
49+
}
50+
51+
private void OnDisable()
52+
{
53+
if (this._rasterOverlayEditor != null)
54+
{
55+
DestroyImmediate(this._rasterOverlayEditor);
56+
}
57+
}
58+
59+
public override void OnInspectorGUI()
60+
{
61+
this.serializedObject.Update();
62+
63+
EditorGUIUtility.labelWidth = CesiumEditorStyle.inspectorLabelWidth;
64+
this.DrawGoogleMapTilesProperties();
65+
EditorGUILayout.Space(5);
66+
this.DrawRasterOverlayProperties();
67+
68+
this.serializedObject.ApplyModifiedProperties();
69+
}
70+
71+
private void DrawGoogleMapTilesProperties()
72+
{
73+
GUIContent apiKeyContent = new GUIContent(
74+
"API Key",
75+
"The Google Map Tiles API key to use.");
76+
EditorGUILayout.DelayedTextField(this._apiKey, apiKeyContent);
77+
78+
GUIContent mapTypeContent = new GUIContent(
79+
"Map Type",
80+
"The type of base map.");
81+
EditorGUILayout.PropertyField(this._mapType, mapTypeContent);
82+
83+
GUIContent languageContent = new GUIContent(
84+
"Language",
85+
"An IETF language tag that specifies the language used to display " +
86+
"information on the tiles. For example, `en-US` specifies the " +
87+
"English language as spoken in the United States.");
88+
EditorGUILayout.DelayedTextField(this._language, languageContent);
89+
90+
GUIContent regionContent = new GUIContent(
91+
"Region",
92+
"A Common Locale Data Repository region identifier (two uppercase " +
93+
"letters) that represents the physical location of the user. For " +
94+
"example, `US`.");
95+
EditorGUILayout.DelayedTextField(this._region, regionContent);
96+
97+
GUIContent scaleContent = new GUIContent(
98+
"Scale",
99+
"Scales-up the size of map elements (such as road labels), while " +
100+
"retaining the tile size and coverage area of the default tile." +
101+
"\n\n" +
102+
"Increasing the scale also reduces the number of labels on the map, " +
103+
"which reduces clutter.");
104+
this._selectedScaleIndex =
105+
EditorGUILayout.Popup(scaleContent, this._selectedScaleIndex, this._scaleOptions);
106+
this._scale.enumValueIndex = this._selectedScaleIndex;
107+
108+
GUIContent highDpiContent = new GUIContent(
109+
"High DPI",
110+
"Specifies whether to return high-resolution tiles." +
111+
"\n\n" +
112+
"If the scale-factor is increased, High DPI is used to increase the " +
113+
"size of the tile. Normally, increasing the scale factor enlarges the " +
114+
"resulting tile into an image of the same size, which lowers quality. " +
115+
"With High DPI, the resulting size is also increased, preserving quality. " +
116+
"DPI stands for Dots per Inch, and High DPI means the tile renders using " +
117+
"more dots per inch than normal." +
118+
"\n\n" +
119+
"If enabled, the number of pixels in each of the x and y dimensions is " +
120+
"multiplied by the scale factor (that is, 2x or 4x). The coverage area " +
121+
"of the tile remains unchanged. This parameter works only with Scale " +
122+
"values of 2x or 4x. It has no effect on 1x scale tiles.");
123+
EditorGUILayout.PropertyField(this._highDpi, highDpiContent);
124+
125+
GUIContent layerTypesContent = new GUIContent(
126+
"Layer Types",
127+
"The layer types to be added to the map.");
128+
EditorGUILayout.PropertyField(this._layerTypes, layerTypesContent);
129+
130+
GUIContent stylesContent = new GUIContent(
131+
"Styles",
132+
"A list of JSON style objects that specify the appearance and detail " +
133+
"level of map features such as roads, parks, and built-up areas." +
134+
"\n\n" +
135+
"Styling is used to customize the standard Google base map. The Styles " +
136+
"parameter is valid only if the Map Type is Roadmap.");
137+
EditorGUILayout.PropertyField(this._styles, stylesContent);
138+
139+
GUIContent overlayContent = new GUIContent(
140+
"Overlay",
141+
"Specifies whether Layer Types are rendered as a separate overlay, or " +
142+
"combined with the base imagery." +
143+
"\n\n" +
144+
"When enabled, the base map isn't displayed. If you haven't defined any " +
145+
"Layer Types, then this value is ignored.");
146+
EditorGUILayout.PropertyField(this._overlay, overlayContent);
147+
148+
GUILayout.BeginHorizontal();
149+
GUILayout.FlexibleSpace();
150+
if (EditorGUILayout.LinkButton("Map Tiles API Style reference"))
151+
{
152+
Application.OpenURL("https://developers.google.com/maps/documentation/tile/style-reference");
153+
}
154+
GUILayout.FlexibleSpace();
155+
GUILayout.EndHorizontal();
156+
}
157+
158+
private void DrawRasterOverlayProperties()
159+
{
160+
if (this._rasterOverlayEditor != null)
161+
{
162+
this._rasterOverlayEditor.OnInspectorGUI();
163+
}
164+
}
165+
}
166+
}

Editor/CesiumGoogleMapTilesRasterOverlayEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/CesiumIonRasterOverlayEditor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class CesiumIonRasterOverlayEditor : Editor
1212
private SerializedProperty _ionAssetID;
1313
private SerializedProperty _ionAccessToken;
1414
private SerializedProperty _ionServer;
15+
private SerializedProperty _assetOptions;
1516

1617
private void OnEnable()
1718
{
@@ -24,6 +25,7 @@ private void OnEnable()
2425
this._ionAssetID = this.serializedObject.FindProperty("_ionAssetID");
2526
this._ionAccessToken = this.serializedObject.FindProperty("_ionAccessToken");
2627
this._ionServer = this.serializedObject.FindProperty("_ionServer");
28+
this._assetOptions = this.serializedObject.FindProperty("_assetOptions");
2729
}
2830

2931
private void OnDisable()
@@ -74,6 +76,12 @@ private void DrawIonProperties()
7476

7577
GUIContent ionServerContent = new GUIContent("ion Server", "The Cesium ion server to use.");
7678
EditorGUILayout.PropertyField(this._ionServer, ionServerContent);
79+
80+
GUIContent assetOptionsContent = new GUIContent(
81+
"Asset Options",
82+
"Extra options to pass to Cesium ion when accessing the asset. " +
83+
"This should be a JSON string.");
84+
EditorGUILayout.DelayedTextField(this._assetOptions, assetOptionsContent);
7785
}
7886

7987
private void DrawRasterOverlayProperties()

Runtime/CesiumCreditSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ internal IEnumerator LoadImage(string url)
304304
Debug.Log("Credit image could not be loaded into Texture2D.");
305305
}
306306
}
307-
catch (FormatException e)
307+
catch (FormatException)
308308
{
309309
Debug.Log("Could not parse credit image from base64 string.");
310310
}

0 commit comments

Comments
 (0)