/// <summary>
        /// Builds the scene.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="view"></param>
        private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view)
        {
            // get the indexed object at this zoom.
            HashSet<ArcId> interpretedObjects;
            if (!_interpretedObjects.TryGetValue ((int)zoomFactor, out interpretedObjects)) {
                interpretedObjects = new HashSet<ArcId> ();
                _interpretedObjects.Add ((int)zoomFactor, interpretedObjects);
            }

            // build the boundingbox.
            var viewBox = view.OuterBox;
            var box = new GeoCoordinateBox (map.Projection.ToGeoCoordinates (viewBox.Min [0], viewBox.Min [1]),
                                                        map.Projection.ToGeoCoordinates (viewBox.Max [0], viewBox.Max [1]));
            foreach (var requestedBox in _requestedBoxes) {
                if (requestedBox.Contains (box)) {
                    return;
                }
            }
            _requestedBoxes.Add (box);

            //// set the scene backcolor.
            //SimpleColor? color = _styleInterpreter.GetCanvasColor ();
            //_scene.BackColor = color.HasValue
            //                               ? color.Value.Value
            //                               : SimpleColor.FromArgb (0, 255, 255, 255).Value;

            // get data.
            foreach (var arc in _dataSource.GetArcs(box)) {
                // translate each object into scene object.
                var arcId = new ArcId () {
                    Vertex1 = arc.Key,
                    Vertex2 = arc.Value.Key
                };
                if (!interpretedObjects.Contains (arcId)) {
                    interpretedObjects.Add (arcId);

                    // create nodes.
                    float latitude, longitude;
                    _dataSource.GetVertex (arcId.Vertex1, out latitude, out longitude);
                    var node1 = CompleteNode.Create (arcId.Vertex1);
                    node1.Coordinate = new GeoCoordinate (latitude, longitude);
                    _dataSource.GetVertex (arcId.Vertex2, out latitude, out longitude);
                    var node2 = CompleteNode.Create (arcId.Vertex2);
                    node2.Coordinate = new GeoCoordinate (latitude, longitude);

                    // create way.
                    var way = CompleteWay.Create (-1);
                    if (arc.Value.Value.Forward) {
                        way.Nodes.Add (node1);
                        way.Nodes.Add (node2);
                    } else {
                        way.Nodes.Add (node2);
                        way.Nodes.Add (node1);
                    }
                    way.Tags.AddOrReplace (_dataSource.TagsIndex.Get (arc.Value.Value.Tags));

                    _styleInterpreter.Translate (_scene, map.Projection, way);
                    interpretedObjects.Add (arcId);
                }
            }
        }
Beispiel #2
0
        /// Saves to an XML writer.
        private void Save(XmlWriter xml)
        {
            xml.WriteStartDocument();
            xml.WriteStartElement("graphml", xmlns.NamespaceName);
            xml.WriteAttributeString("xmlns", "xsi", null, xmlnsXsi.NamespaceName);
            xml.WriteAttributeString("xmlns", "y", null, xmlnsY.NamespaceName);
            xml.WriteAttributeString("xmlns", "yed", null, xmlnsYed.NamespaceName);
            xml.WriteAttributeString("xsi", "schemaLocation", null, xsiSchemaLocation);

            for (int i = 0; i < Properties.Count; i++)
            {
                var p = Properties[i];
                p.Id = "d" + i;
                p.GetKeyElement().WriteTo(xml);
            }

            xml.WriteStartElement("graph", xmlns.NamespaceName);
            xml.WriteAttributeString("id", "G");
            xml.WriteAttributeString("edgedefault", "directed");
            xml.WriteAttributeString("parse.nodes", Graph.NodeCount().ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("parse.edges", Graph.ArcCount().ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("parse.order", "nodesfirst");
            DefinePropertyValues(xml, Graph);

            Dictionary <string, Node> nodeById = new Dictionary <string, Node>();

            if (NodeId == null)
            {
                NodeId = new Dictionary <Node, string>();
            }
            foreach (var kv in NodeId)
            {
                if (nodeById.ContainsKey(kv.Value))
                {
                    throw new Exception("Duplicate node id " + kv.Value);
                }
                nodeById[kv.Value] = kv.Key;
            }
            foreach (var node in Graph.Nodes())
            {
                string id;
                NodeId.TryGetValue(node, out id);
                if (id == null)
                {
                    id = node.Id.ToString(CultureInfo.InvariantCulture);
                    while (nodeById.ContainsKey(id))
                    {
                        id += '_';
                    }
                    NodeId[node] = id;
                    nodeById[id] = node;
                }

                xml.WriteStartElement("node", xmlns.NamespaceName);
                xml.WriteAttributeString("id", id);
                DefinePropertyValues(xml, node);
                xml.WriteEndElement();                 // node
            }

            foreach (var arc in Graph.Arcs())
            {
                string id;
                if (ArcId != null)
                {
                    ArcId.TryGetValue(arc, out id);
                }
                else
                {
                    id = null;
                }

                xml.WriteStartElement("edge", xmlns.NamespaceName);
                if (id != null)
                {
                    xml.WriteAttributeString("id", id);
                }
                if (Graph.IsEdge(arc))
                {
                    xml.WriteAttributeString("directed", "false");
                }
                xml.WriteAttributeString("source", NodeId[Graph.U(arc)]);
                xml.WriteAttributeString("target", NodeId[Graph.V(arc)]);
                DefinePropertyValues(xml, arc);
                xml.WriteEndElement();                 // edge
            }

            xml.WriteEndElement();             // graph
            xml.WriteEndElement();             // graphml
        }
Beispiel #3
0
        /// <summary>
        /// Builds the scene.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="view"></param>
        private void BuildScene(Map map, float zoomFactor, GeoCoordinate center, View2D view)
        {
            // get the indexed object at this zoom.
            HashSet <ArcId> interpretedObjects;

            if (!_interpretedObjects.TryGetValue((int)zoomFactor, out interpretedObjects))
            {
                interpretedObjects = new HashSet <ArcId>();
                _interpretedObjects.Add((int)zoomFactor, interpretedObjects);
            }

            // build the boundingbox.
            var viewBox = view.OuterBox;
            var box     = new GeoCoordinateBox(map.Projection.ToGeoCoordinates(viewBox.Min[0], viewBox.Min[1]),
                                               map.Projection.ToGeoCoordinates(viewBox.Max[0], viewBox.Max[1]));

            foreach (var requestedBox in _requestedBoxes)
            {
                if (requestedBox.Contains(box))
                {
                    return;
                }
            }
            _requestedBoxes.Add(box);

            //// set the scene backcolor.
            //SimpleColor? color = _styleInterpreter.GetCanvasColor ();
            //_scene.BackColor = color.HasValue
            //                               ? color.Value.Value
            //                               : SimpleColor.FromArgb (0, 255, 255, 255).Value;

            // get data.
            foreach (var arc in _dataSource.GetEdges(box))
            {
                // translate each object into scene object.
                var arcId = new ArcId()
                {
                    Vertex1 = arc.Key,
                    Vertex2 = arc.Value.Key
                };
                if (!interpretedObjects.Contains(arcId))
                {
                    interpretedObjects.Add(arcId);

                    // create nodes.
                    float latitude, longitude;
                    _dataSource.GetVertex(arcId.Vertex1, out latitude, out longitude);
                    var node1 = new Node();
                    node1.Id        = arcId.Vertex1;
                    node1.Latitude  = latitude;
                    node1.Longitude = longitude;
                    _dataSource.GetVertex(arcId.Vertex2, out latitude, out longitude);
                    var node2 = new Node();
                    node2.Id        = arcId.Vertex2;
                    node2.Latitude  = latitude;
                    node2.Longitude = longitude;

                    // create way.
                    var way = CompleteWay.Create(-1);
                    if (arc.Value.Value.Forward)
                    {
                        way.Nodes.Add(node1);
                        way.Nodes.Add(node2);
                    }
                    else
                    {
                        way.Nodes.Add(node2);
                        way.Nodes.Add(node1);
                    }
                    way.Tags.AddOrReplace(_dataSource.TagsIndex.Get(arc.Value.Value.Tags));

                    _styleInterpreter.Translate(_scene, map.Projection, way);
                    interpretedObjects.Add(arcId);
                }
            }
        }