Exemple #1
0
        IEnumerator _RefreshMapTile()
        {
            //找到瓦片中心的纬度和经度
            tileCenterLocation.Latitude  = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel);
            tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel);

            var url = GOOGLE_MAPS_URL;
            //构造查询地图瓦片的字符串参数
            var queryString = "";

            queryString += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude));
            queryString += "&zoom=" + zoomLevel.ToString();
            queryString += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
            queryString += "&scale=" + (doubleResolution ? "2" : "1");
            queryString += "&maptype=" + mapType.ToString().ToLower();
            queryString += "&format=" + "png";

            //styles
            queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5";
            queryString += "&style=element:labels|visibility:off";

            var usingSensor = false;

#if MOBILE_INPUT
            usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
#endif

            queryString += "&sensor=" + (usingSensor ? "true" : "false");

            //set map bounds rect
            TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel);
            TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel);

            BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel);
            BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel);

            print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString));

            //var req = new WWW(url + "?" + queryString);
            //var req = new WWW("https://maps.googleapis.com/maps/api/staticmap?center=50.917316,-114.080923&zoom=17&format=png&sensor=false&size=640x640&scale=2&maptype=roadmap&style=feature:landscape.man_made|visibility:on|invert_lightness:true");
            //在这里更改地址,以显示静态地图
            var req = new WWW("http://api.map.baidu.com/staticimage?center=116.988908,36.686075&width=500&height=500&zoom=19");
            //等待服务器返回
            yield return(req);

            //先释放旧的贴图
            Destroy(GetComponent <Renderer>().material.mainTexture);
            //出错检查
            if (req.error != null)
            {
                print(string.Format("Tile {0}x{1} : exception={2} textured", TileOffset.x, TileOffset.y, req.error));
            }
            else
            {
                //没有错误,绘制图像
                //返回的图像作为瓦片地图
                GetComponent <Renderer>().material.mainTexture = req.texture;
                print(string.Format("Tile {0}x{1} textured", TileOffset.x, TileOffset.y));
            }
        }
Exemple #2
0
        IEnumerator _RefreshMapTile()
        {
            // タイル中心の緯度/経度を取得
            tileCenterLocation.Latitude  = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel);
            tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel);

            var url         = GOOGLE_MAPS_URL;
            var queryString = "";

            // 地図タイルをリクエストするクエリ文字列パラメーターを作成する
            queryString += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude));
            queryString += "&zoom=" + zoomLevel.ToString();
            queryString += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
            queryString += "&scale=" + (doubleResolution ? "2" : "1");
            queryString += "&maptype=" + mapType.ToString().ToLower();
            queryString += "&format=" + "png";

            // 地図のスタイルを追加する
            queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5";
            queryString += "&style=element:labels|visibility:off";

            var usingSensor = false;

#if MOBILE_INPUT
            usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
#endif

            queryString += "&sensor=" + (usingSensor ? "true" : "false");

            //set map bounds rect
            TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel);
            TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel);

            BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel);
            BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel);

            print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString));

            // 最後に、画像をリクエストする
            var req = UnityWebRequestTexture.GetTexture(GOOGLE_MAPS_URL + "?" + queryString);
            // サービスが応答するまで待つ
            yield return(req.Send());

            // 最初に古いテクスチャーを破棄する
            Destroy(GetComponent <Renderer>().material.mainTexture);
            // エラーをチェックする
            if (req.error != null)
            {
                print(string.Format("Error loading tile {0}x{1}:  exception={2}",
                                    TileOffset.x, TileOffset.y, req.error));
            }
            else
            {
                // レンダリング画像がエラーがなければ戻ってきた画像をタイルテクスチャーとして設定する
                GetComponent <Renderer> ().material.mainTexture = ((DownloadHandlerTexture)req.downloadHandler).texture;
                print(string.Format("Tile {0}x{1} textured", TileOffset.x, TileOffset.y));
            }
        }
Exemple #3
0
        IEnumerator _RefreshMapTile()
        {
            //find the center lat/long of the tile
            tileCenterLocation.Latitude  = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel);
            tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel);

            var queryString = "";

            //build the query string parameters for the map tile request
            queryString += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude));
            queryString += "&zoom=" + zoomLevel.ToString();
            queryString += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
            queryString += "&scale=" + (doubleResolution ? "2" : "1");
            queryString += "&maptype=" + mapType.ToString().ToLower();
            queryString += "&format=" + "png";

            //adding the map styles
            queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5";
            queryString += "&style=element:labels|visibility:off";

            //queryString += "&key={your API key here}";

            //check if script is on a mobile device and using a location service
            var usingSensor = false;

#if MOBILE_INPUT
            usingSensor = Input.location.isEnabledByUser &&
                          Input.location.status == LocationServiceStatus.Running &&
                          gpsLocationService != null;
#endif
            queryString += "&sensor=" + (usingSensor ? "true" : "false");

            //set map bounds rect
            TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel);
            TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel);

            BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel);
            BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel);

            print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString));

            //finally, we request the image
            var req = new WWW(GOOGLE_MAPS_URL + "?" + queryString);
            //yield until the service responds
            yield return(req);

            //first destroy the old texture first
            Destroy(GetComponent <Renderer>().material.mainTexture);
            //when the image returns set it as the tile texture
            GetComponent <Renderer>().material.mainTexture = req.texture;
            print(string.Format("Tile {0}x{1} textured", TileOffset.x, TileOffset.y));
            if (TileOffset.x == 0 && TileOffset.y == 0)
            {
                gpsLocationService.MapRedrawn();
            }
        }
        IEnumerator _RefreshMapTile()
        {
            //find the center lat/ long of the tile
            tileCenterLocation.Latitude  = GoogleMapUtils.adjustLatByPixels(worldCenterLocation.Latitude, (int)(size * 1 * TileOffset.y), zoomLevel);
            tileCenterLocation.Longitude = GoogleMapUtils.adjustLonByPixels(worldCenterLocation.Longitude, (int)(size * 1 * TileOffset.x), zoomLevel);

            var url         = GOOGLE_MAPS_URL;
            var queryString = "";

            //build the query string parameters for the map tile request
            queryString += "center=" + WWW.UnEscapeURL(string.Format("{0},{1}", tileCenterLocation.Latitude, tileCenterLocation.Longitude));
            queryString += "&zoom=" + zoomLevel.ToString();
            queryString += "&size=" + WWW.UnEscapeURL(string.Format("{0}x{0}", size));
            queryString += "&scale=" + (doubleResolution ? "2" : "1");
            queryString += "&maptype=" + mapType.ToString().ToLower();
            queryString += "&format=" + "png";

            //styles
            queryString += "&style=element:geometry|invert_lightness:true|weight:3.1|hue:0x00ffd5";
            queryString += "&style=element:labels|visibility:off";

            var usingSensor = false;

#if MOBILE_INPUT
            usingSensor = Input.location.isEnabledByUser && Input.location.status == LocationServiceStatus.Running;
#endif

            queryString += "&sensor=" + (usingSensor ? "true" : "false");

            //set map bounds rect
            TopLeftCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, -size, zoomLevel);
            TopLeftCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, size, zoomLevel);

            BottomRightCorner.x = GoogleMapUtils.adjustLonByPixels(tileCenterLocation.Longitude, size, zoomLevel);
            BottomRightCorner.y = GoogleMapUtils.adjustLatByPixels(tileCenterLocation.Latitude, -size, zoomLevel);

            print(string.Format("Tile {0}x{1} requested with {2}", TileOffset.x, TileOffset.y, queryString));


            //Finally we request the image
            var req = new WWW(url + "?" + queryString);
            //var req = new WWW("https://maps.googleapis.com/maps/api/staticmap?center=50.917316,-114.080923&zoom=17&format=png&sensor=false&size=640x640&scale=2&maptype=roadmap&style=feature:landscape.man_made|visibility:on|invert_lightness:true");
            //yield until the service responds
            yield return(req);

            GetComponent <Renderer>().material.mainTexture = req.texture;
            print(string.Format("Tile {0}x{1} textured", TileOffset.x, TileOffset.y));
        }