示例#1
0
        private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            if (!IsFeatureValid(feature))
            {
                return;
            }

            //this will be improved in next version and will probably be replaced by filters
            var styleSelectorKey = FindSelectorKey(feature);

            var meshData = new MeshData();

            meshData.TileRect = tile.Rect;

            //and finally, running the modifier stack on the feature
            var mod = Stacks.FirstOrDefault(x => x.Type.Contains(styleSelectorKey));

            if (mod != null)
            {
                mod.Stack.Execute(tile, feature, meshData, parent, mod.Type);
            }
            else
            {
                if (_defaultStack != null)
                {
                    _defaultStack.Execute(tile, feature, meshData, parent, _key);
                }
            }
        }
示例#2
0
        protected void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            if (feature.Properties.ContainsKey("extrude") && !Convert.ToBoolean(feature.Properties["extrude"]))
            {
                return;
            }

            if (feature.Points.Count < 1)
            {
                return;
            }

            //this will be improved in next version and will probably be replaced by filters
            var styleSelectorKey = _layerProperties.coreOptions.sublayerName;

            var meshData = new MeshData();

            meshData.TileRect = tile.Rect;

            //and finally, running the modifier stack on the feature
            var processed = false;

            if (!processed)
            {
                if (_defaultStack != null)
                {
                    _defaultStack.Execute(tile, feature, meshData, parent, styleSelectorKey);
                }
            }
        }
示例#3
0
        private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            if (feature.Properties.ContainsKey("extrude") && !Convert.ToBoolean(feature.Properties["extrude"]))
            {
                return;
            }

            if (feature.Points.Count < 1)
            {
                return;
            }

            //this will be improved in next version and will probably be replaced by filters
            var styleSelectorKey = FindSelectorKey(feature);

            var meshData = new MeshData();

            meshData.TileRect = tile.Rect;

            //and finally, running the modifier stack on the feature
            var processed = false;

            for (int i = 0; i < Stacks.Count; i++)
            {
                foreach (var key in Stacks[i].Types)
                {
                    if (key == styleSelectorKey)
                    {
                        processed = true;
                        Stacks[i].Stack.Execute(tile, feature, meshData, parent, styleSelectorKey);
                        break;
                    }
                }

                if (processed)
                {
                    break;
                }
            }
            if (!processed)
            {
                if (_defaultStack != null)
                {
                    _defaultStack.Execute(tile, feature, meshData, parent, _key);
                }
            }
        }
        /// <summary>
        /// Preprocess features, finds the relevant modifier stack and passes the feature to that stack
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="tile"></param>
        /// <param name="parent"></param>
        private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            if (feature.Properties.ContainsKey("extrude") && !bool.Parse(feature.Properties["extrude"].ToString()))
            {
                return;
            }

            //we're not cutting out the holes yet
            foreach (var geometry in feature.Points)
            {
                var meshData = new MeshData();
                meshData.TileRect = tile.Rect;

                if (geometry.Count <= 1)
                {
                    continue;
                }

                //this will be improved in next version and will probably be replaced by filters
                string styleSelectorKey = "";
                if (string.IsNullOrEmpty(_classificationKey))
                {
                    if (feature.Properties.ContainsKey("type"))
                    {
                        styleSelectorKey = feature.Properties["type"].ToString().ToLowerInvariant();
                    }
                    else if (feature.Properties.ContainsKey("class"))
                    {
                        styleSelectorKey = feature.Properties["class"].ToString().ToLowerInvariant();
                    }
                }
                else if (feature.Properties.ContainsKey(_classificationKey))
                {
                    if (feature.Properties.ContainsKey(_classificationKey))
                    {
                        styleSelectorKey = feature.Properties[_classificationKey].ToString().ToLowerInvariant();
                    }
                }

                //we'll run all visualizers on MeshData here
                var list = geometry;
                //.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.Center).ToVector3xz()).ToList();

                //long straight edges looks bad on bumpy terrain
                if (_subdivideLongEdges)
                {
                    var verts = new List <Vector3>();
                    if (list.Count > 1)
                    {
                        for (int i = 0; i < list.Count - 1; i++)
                        {
                            verts.Add(list[i]);
                            var dist = Vector3.Distance(list[i], list[i + 1]);
                            var step = Math.Min(_maxEdgeSectionCount, dist / _preferredEdgeSectionLength);
                            if (step > 1)
                            {
                                var counter = 1;
                                while (counter < step)
                                {
                                    var nv = Vector3.Lerp(list[i], list[i + 1], Mathf.Min(1, counter / step));
                                    verts.Add(nv);
                                    counter++;
                                }
                            }
                        }
                    }
                    verts.Add(list.Last());
                    list = verts;
                }

                //adding terrain & building min_height to vertices
                //we may move this into height modifier in the future
                meshData.Vertices = list.Select(vertex =>
                {
                    var h   = tile.QueryHeightData((float)((vertex.x + tile.Rect.Size.x / 2) / tile.Rect.Size.x), (float)((vertex.z + tile.Rect.Size.y / 2) / tile.Rect.Size.y));
                    vertex += new Vector3(0, h, 0);

                    if (feature.Properties.ContainsKey("min_height"))
                    {
                        var min_height = Convert.ToSingle(feature.Properties["min_height"]);
                        vertex        += new Vector3(0, min_height, 0);
                    }

                    return(vertex);
                }).ToList();

                //and finally, running the modifier stack on the feature
                var        mod = Stacks.FirstOrDefault(x => x.Type.Contains(styleSelectorKey));
                GameObject go;
                if (mod != null)
                {
                    go = mod.Stack.Execute(tile, feature, meshData, parent, mod.Type);
                }
                else
                {
                    if (_defaultStack != null)
                    {
                        go = _defaultStack.Execute(tile, feature, meshData, parent, _key);
                    }
                }
                //go.layer = LayerMask.NameToLayer(_key);
            }
        }
        protected void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            pos      = GameManager.poiLocaitonList;
            typeDict = GameManager.poiTypeList;

            if (feature.Properties.ContainsKey("extrude") && !Convert.ToBoolean(feature.Properties["extrude"]))
            {
                return;
            }

            if (feature.Points.Count < 1)
            {
                return;
            }

            //this will be improved in next version and will probably be replaced by filters
            var styleSelectorKey = _layerProperties.coreOptions.sublayerName;

            if (styleSelectorKey != "Buildings")
            {
                // Calculate Distance between POIs and do not spawn if too close to other POIs
                var        rangeBool      = true;
                var        geom           = feature.Data.Geometry <float>();
                var        location       = feature.Data.GeometryAsWgs84((ulong)tile.CanonicalTileId.Z, (ulong)tile.CanonicalTileId.X, (ulong)tile.CanonicalTileId.Y)[0][0];
                var        locationDouble = new double[] { location.Lat, location.Lng };
                var        maxDistance    = 150.0f;
                CheapRuler cr             = new CheapRuler(locationDouble[1], CheapRulerUnits.Meters);
                // If spawned object is treasure only check distance to other treasures
                if (styleSelectorKey == "Treasures")
                {
                    foreach (KeyValuePair <string, double[]> position in pos)
                    {
                        if (position.Key.Contains("Treasures"))
                        {
                            if (cr.Distance(locationDouble, position.Value) < maxDistance && !pos.ContainsKey(styleSelectorKey + " - " + feature.Data.Id.ToString()))
                            {
                                rangeBool = false;
                                return;
                            }
                        }
                    }
                }
                // for POIs check only distance to POIs and not to treasures
                else
                {
                    foreach (KeyValuePair <string, double[]> position in pos)
                    {
                        if (!position.Key.Contains("Treasures"))
                        {
                            if (cr.Distance(locationDouble, position.Value) < maxDistance && !pos.ContainsKey(styleSelectorKey + " - " + feature.Data.Id.ToString()))
                            {
                                rangeBool = false;
                                return;
                            }
                        }
                    }
                }

                // Add spawned POIs and treasures to dictionaries
                if (rangeBool && feature.Data.Id.ToString() != null && !pos.ContainsKey(styleSelectorKey + " - " + feature.Data.Id.ToString()))
                {
                    pos.Add(styleSelectorKey + " - " + feature.Data.Id.ToString(), locationDouble);
                    typeDict.Add(styleSelectorKey + " - " + feature.Data.Id.ToString(), feature.Properties);
                }
            }

            var meshData = new MeshData();

            meshData.TileRect = tile.Rect;

            //and finally, running the modifier stack on the feature
            var processed = false;

            if (!processed)
            {
                if (_defaultStack != null)
                {
                    _defaultStack.Execute(tile, feature, meshData, parent, styleSelectorKey);
                }
            }
        }