public IEnumerator MapboxSatellite()
        {
            string id      = "mapbox.satellite";
            int    minZoom = 0;
            int    maxZoom = 22;

            TileJSONResponse response = null;

            Unity.MapboxAccess.Instance.TileJSON.Get(
                id
                , (TileJSONResponse tjr) =>
            {
                response = tjr;
            }
                );


            IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();

            while (enumerator.MoveNext())
            {
                yield return(null);
            }

            testsCommonToVectorAndRasterTilesets(response, id, minZoom, maxZoom, boundsSouth: -85, boundsNorth: 85);
        }
        public IEnumerator ConcatenatedVectorTilesets()
        {
            string id      = "mapbox.mapbox-traffic-v1,mapbox.mapbox-streets-v7";
            int    minZoom = 0;
            int    maxZoom = 16;

            TileJSONResponse response = null;

            Unity.MapboxAccess.Instance.TileJSON.Get(
                id
                , (TileJSONResponse tjr) =>
            {
                response = tjr;
            }
                );


            IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();

            while (enumerator.MoveNext())
            {
                yield return(null);
            }

            testsCommonToVectorAndRasterTilesets(
                response
                , id
                , minZoom
                , maxZoom
                , boundsSouth: -90
                , boundsNorth: 90
                );
            testsForVectorTilesets(response);
        }
        public IEnumerator MapboxEmerald()
        {
            string id      = "mapbox.emerald";
            int    minZoom = 0;
            int    maxZoom = 22;

            TileJSONResponse response = null;

            Unity.MapboxAccess.Instance.TileJSON.Get(
                id
                , (TileJSONResponse tjr) =>
            {
                response = tjr;
            }
                );


            IEnumerator enumerator = ((FileSource)Unity.MapboxAccess.Instance.TileJSON.FileSource).WaitForAllRequests();

            while (enumerator.MoveNext())
            {
                yield return(null);
            }

            testsCommonToVectorAndRasterTilesets(response, id, minZoom, maxZoom);

            Assert.IsNotEmpty(response.Source, "'Source' not set properly");
        }
        private void testsForVectorTilesets(TileJSONResponse response)
        {
            Assert.IsNotNull(response.VectorLayers, "'VectorLayers' not set properly");
            Assert.GreaterOrEqual(response.VectorLayers.Length, 1, "Not enough 'VectorLayers'");

            TileJSONObjectVectorLayer vl1 = response.VectorLayers[0];

            Assert.IsNotNull(vl1.Fields, "VectorLayer fields not parsed properly");
            Assert.GreaterOrEqual(vl1.Fields.Count, 1, "Not enough vector layer fields");
            Assert.IsNotEmpty(vl1.Id, "'Id' of vector layer not parsed properly");
            Assert.IsNotEmpty(vl1.Source, "'Source' of vector layer not parsed properly");
            Assert.IsNotEmpty(vl1.SourceName, "'SourceName' of vector layer not parsed properly");
        }
 private void LoadEditorTileJSON(SerializedProperty property, VectorSourceType sourceTypeValue, string sourceString)
 {
     if (sourceTypeValue != VectorSourceType.None && !string.IsNullOrEmpty(sourceString))
     {
         if (tileJSONResponse == null || string.IsNullOrEmpty(sourceString) || sourceString != TilesetId)
         {
             //tileJSONData.ClearData();
             try
             {
                 Unity.MapboxAccess.Instance.TileJSON.Get(sourceString, (response) =>
                 {
                     //if the code has reached this point it means that there is a valid access token
                     tileJSONResponse = response;
                     if (response == null || response.VectorLayers == null)                             //indicates bad tileresponse
                     {
                         tileJSONData.ClearData();
                         return;
                     }
                     tileJSONData.ProcessTileJSONData(response);
                 });
             }
             catch (System.Exception)
             {
                 //no valid access token causes MapboxAccess to throw an error and hence setting this property
                 tileJSONData.ClearData();
             }
         }
         else if (tileJSONData.LayerPropertyDescriptionDictionary.Count == 0)
         {
             tileJSONData.ProcessTileJSONData(tileJSONResponse);
         }
     }
     else
     {
         tileJSONData.ClearData();
     }
     TilesetId = sourceString;
 }
Ejemplo n.º 6
0
        public void ProcessTileJSONData(TileJSONResponse tjr)
        {
            tileJSONLoaded = true;
            List <string> layerPropertiesList = new List <string>();

            // Un-comment if required. Throws a warning right now.
            //List<string> sourceLayersList = new List<string>();

            if (tjr == null || tjr.VectorLayers == null || tjr.VectorLayers.Length == 0)
            {
                return;
            }

            ClearData();

            var propertyName        = "";
            var propertyDescription = "";
            var layerSource         = "";

            foreach (var layer in tjr.VectorLayers)
            {
                //load layer names
                var layerName = layer.Id;
                layerPropertiesList = new List <string>();
                layerSource         = layer.Source;
                //if (layer.Fields.Count == 0)
                //continue;

                //loading layer sources
                if (LayerSourcesDictionary.ContainsKey(layerName))
                {
                    LayerSourcesDictionary[layerName].Add(layerSource);
                }
                else
                {
                    LayerSourcesDictionary.Add(layerName, new List <string>()
                    {
                        layerSource
                    });
                }

                //loading layers to a data source
                if (SourceLayersDictionary.ContainsKey(layerSource))
                {
                    List <string> sourceList = new List <string>();
                    LayerSourcesDictionary.TryGetValue(layerName, out sourceList);

                    if (sourceList.Count > 1 && sourceList.Contains(layerSource))                     // the current layerName has more than one source
                    {
                        if (SourceLayersDictionary.ContainsKey(commonLayersKey))
                        {
                            SourceLayersDictionary[commonLayersKey].Add(layerName);
                        }
                        else
                        {
                            SourceLayersDictionary.Add(commonLayersKey, new List <string>()
                            {
                                layerName
                            });
                        }

                        if (LayerDisplayNames.Contains(layerName))
                        {
                            LayerDisplayNames.Remove(layerName);
                        }
                        LayerDisplayNames.Add(layerName);
                        //						LayerDisplayNames.Add(layerName + " " + commonLayersKey);
                    }
                    else
                    {
                        SourceLayersDictionary[layerSource].Add(layerName);
                        LayerDisplayNames.Add(layerName);
                    }
                }
                else
                {
                    SourceLayersDictionary.Add(layerSource, new List <string>()
                    {
                        layerName
                    });
                    LayerDisplayNames.Add(layerName);
                }


                //Load properties
                foreach (var property in layer.Fields)
                {
                    propertyName        = property.Key;
                    propertyDescription = property.Value;
                    layerPropertiesList.Add(propertyName);

                    //adding property descriptions
                    if (LayerPropertyDescriptionDictionary.ContainsKey(layerName))
                    {
                        if (!LayerPropertyDescriptionDictionary[layerName].ContainsKey(propertyName))
                        {
                            LayerPropertyDescriptionDictionary[layerName].Add(propertyName, propertyDescription);
                        }
                    }
                    else
                    {
                        LayerPropertyDescriptionDictionary.Add(layerName, new Dictionary <string, string>()
                        {
                            { propertyName, propertyDescription }
                        });
                    }

                    //Loading display names for properties
                    if (PropertyDisplayNames.ContainsKey(layerName))
                    {
                        if (!PropertyDisplayNames[layerName].Contains(propertyName))
                        {
                            PropertyDisplayNames[layerName].Add(propertyName);

                            //logic to add the list of masked properties from all sources that are not #1
                            if (LayerSourcesDictionary[layerName].Count > 1 && !string.IsNullOrEmpty(tjr.Source))
                            {
                                var firstSource = tjr.Source.Split(new string[] { "," }, System.StringSplitOptions.None)[0].Trim();
                                if (layerSource != firstSource)
                                {
                                    if (PropertyDisplayNames[layerName].Contains(propertyName))
                                    {
                                        PropertyDisplayNames[layerName].Remove(propertyName);
                                    }

                                    PropertyDisplayNames[layerName].Add(propertyName);
                                    //PropertyDisplayNames[layerName].Add(propertyName + " " + optionalPropertiesString);
                                }
                            }
                        }
                    }
                    else
                    {
                        PropertyDisplayNames.Add(layerName, new List <string> {
                            propertyName
                        });
                    }
                }

                if (PropertyDisplayNames.ContainsKey(layerName) && PropertyDisplayNames[layerName].Count > 1)
                {
                    PropertyDisplayNames[layerName].Sort();
                }
            }


            if (LayerDisplayNames.Count > 1)
            {
                LayerDisplayNames.Sort();
            }
        }
        private void testsCommonToVectorAndRasterTilesets(
            TileJSONResponse response
            , string id
            , int minZoom
            , int maxZoom
            , double boundsWest  = -180
            , double boundsSouth = -85.0511
            , double boundsEast  = 180
            , double boundsNorth = 85.0511
            )
        {
            Assert.IsNotNull(response, "Parsing error or no data received from the servers.");

            Assert.IsNotEmpty(response.Attribution, "Attribution not set.");

            Assert.AreEqual(boundsWest, response.BoundsParsed.West, "Bounds.West does not match");
            Assert.AreEqual(boundsSouth, response.BoundsParsed.South, 0.003, "Bounds.South does not match");
            Assert.AreEqual(boundsEast, response.BoundsParsed.East, "Bounds.East does not match");
            Assert.AreEqual(boundsNorth, response.BoundsParsed.North, 0.003, "Bounds.North does not match");

            // this does not work as some tilesets report whole world bounds despite covering a small area only
            // revisit some time in the future
            //Assert.AreEqual(response.BoundsParsed.Center.x, response.CenterParsed.x, 0.003, "Center.x does not match");
            //Assert.AreEqual(response.BoundsParsed.Center.y, response.CenterParsed.y, "Center.y does not match");

            //concatenated tilesets don't have created property
            if (response.Created.HasValue)
            {
                Assert.Greater(response.Created.Value, 0, "'Created' not set");
                Assert.IsNotNull(response.CreatedUtc, "'CreatedUtc' not set properly'");
            }

            // mapbox.satellite doesn't set 'format': bug??
            // revisit in the future
            //Assert.IsNotEmpty(response.Format, "'Format' is empty");

            // concatenated tilesets don't report 'id'
            if (!id.Contains(","))
            {
                Assert.IsNotEmpty(response.Id, "'Id' is empty");
                Assert.AreEqual(id, response.Id, "'Id' not set properly");
            }
            Assert.AreEqual(minZoom, response.MinZoom, "'MinZoom' not set properly");
            Assert.AreEqual(maxZoom, response.MaxZoom, "'MaxZoom' not set properly");

            //Unmodified tilesets don't have a modified property
            if (response.Modified.HasValue)
            {
                Assert.Greater(response.Modified.Value, 0, "'Modified not set'");
                Assert.IsTrue(response.ModifiedUtc.HasValue, "'Modified not properly parsed'");
            }

            Assert.IsNotEmpty(response.Name, "'Name' not set properly");
            Assert.IsFalse(response.Private, "'Private' not set properly");
            Assert.AreEqual("xyz", response.Scheme, "'Scheme' not set properly");
            Assert.IsNotEmpty(response.TileJSONVersion, "'TileJSONVersion not set properly");

            Assert.IsNotNull(response.Tiles, "'Tiles' not set properly");
            Assert.GreaterOrEqual(response.Tiles.Length, 1, "Not enough 'Tiles'");

            // concatenated tilesets don't report 'webpage'
            if (!id.Contains(","))
            {
                Assert.IsNotEmpty(response.WebPage, "'WebPage' not set properly");
            }
        }