Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bionicl authored May 21, 2019
2 parents 8a102b4 + cf2dcc2 commit 035e4f5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Assets/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -25699,7 +25699,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -2.4958083e-10}
m_AnchoredPosition: {x: 0, y: 0.00000088978703}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &1371052592
Expand Down Expand Up @@ -26384,7 +26384,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 275.22113, y: 60}
m_AnchoredPosition: {x: 275.22116, y: 60}
m_SizeDelta: {x: 0, y: 150}
m_Pivot: {x: 1, y: 1}
--- !u!114 &1433522477
Expand Down
34 changes: 24 additions & 10 deletions Assets/Scripts/GoogleMapDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.Networking;

public class GoogleMapDisplay : MonoBehaviour {
public static GoogleMapDisplay instance;
Expand Down Expand Up @@ -154,25 +155,34 @@ public void ChangeMapZoom() {
IEnumerator DownloadMap(Action<Sprite, OneRequest> action, OneRequest request) {
string url = ReturnApiUrl(request);

using (WWW www = new WWW(url)) {
yield return www;
Sprite sprite = Sprite.Create(www.texture,
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError) {
Debug.LogError("DOWNLOAD MAP ERROR: " + www.error);
} else {
Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
Sprite sprite = Sprite.Create(texture,
new Rect(0, 0, 640, 640),
new Vector2(0.5f, 0.5f));

action.Invoke(sprite, request);
}
}

IEnumerator DownloadMapRetina(Action<Sprite, OneRequest> action, OneRequest request) {

string url = ReturnApiUrl(request);

using (WWW www = new WWW(url)) {
yield return www;
Sprite sprite = Sprite.Create(www.texture,
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError) {
Debug.LogError("DOWNLOAD MAP RETINA ERROR: " + www.error);
} else {
Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
Sprite sprite = Sprite.Create(texture,
new Rect(0, 0, 1280, 1280),
new Vector2(0.5f, 0.5f), 200);

action.Invoke(sprite, request);
}
}
Expand Down Expand Up @@ -209,12 +219,16 @@ string ReturnApiUrl(OneRequest request) {
Vector2 metersPos = Conversion.MetersToLatLon(new Vector2(tempPos.x, tempPos.y));
string output = "";
string retinaMultiplayer = "";
string positionX = metersPos.x.ToString();
positionX = positionX.Replace(',', '.');
string positionY = metersPos.y.ToString();
positionY = positionY.Replace(',', '.');
if (CheckUIScale.isRetina)
retinaMultiplayer = "@2x";
if (useGoogleMaps)
output = string.Format("http://maps.googleapis.com/maps/api/staticmap?center={0},{1}&zoom={2}&size=640x640&key={3}{4}", metersPos.x, metersPos.y, request.zoomLevel, GoogleLocationApi.instance.apiKey, style);
output = string.Format("http://maps.googleapis.com/maps/api/staticmap?center={0},{1}&zoom={2}&size=640x640&key={3}{4}", positionX, positionY, request.zoomLevel, GoogleLocationApi.instance.apiKey, style);
else
output = string.Format("https://api.mapbox.com/styles/v1/bionicl/cjbfocd42b59q2rqasdw3ezwb/static/{1},{0},{2},0,0/640x640{3}?access_token={4}&logo=false&attribution=false", metersPos.x, metersPos.y, request.zoomLevel-1, retinaMultiplayer, GoogleLocationApi.instance.mapBoxApiKey);
output = string.Format("https://api.mapbox.com/styles/v1/bionicl/cjbfocd42b59q2rqasdw3ezwb/static/{1},{0},{2},0,0/640x640{3}?access_token={4}&logo=false&attribution=false", positionX, positionY, request.zoomLevel-1, retinaMultiplayer, GoogleLocationApi.instance.mapBoxApiKey);
return output;
}
}
29 changes: 12 additions & 17 deletions Assets/Scripts/GooglePhotosApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,24 +366,19 @@ void AddPhotosToTimeLineItems(GooglePhotosResponse response) {
//}
}
public IEnumerator DownloadImage(string url, Image targetImage) {
// Start a download of the given URL
var www = new WWW(url);
// wait until the download is done
yield return www;
// Create a texture in DXT1 format
Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.DXT1, false);

// assign the downloaded image to sprite
www.LoadImageIntoTexture(texture);
Rect rec = new Rect(0, 0, texture.width, texture.height);
Sprite spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 200);

targetImage.sprite = spriteToUse;

www.Dispose();
www = null;
loadPhotosButtonText.text = "Load photos";
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError) {
Debug.LogError("DOWNLOAD GOOGLE IMAGE ERROR: " + www.error);
} else {
Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
Sprite sprite = Sprite.Create(texture,
new Rect(0, 0, texture.width, texture.height),
new Vector2(0.5f, 0.5f), 200);
targetImage.sprite = sprite;
loadPhotosButtonText.text = "Load photos";
}

}
}

0 comments on commit 035e4f5

Please sign in to comment.