Example #1
0
        /// <summary>
        /// Fills the given simple scene with objects inside the given view and for the given zoomFactor.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        public void Get(Scene2DSimple scene, View2D view, float zoomFactor)
        {
            lock (_stream) {             // make sure there is only synchonous access to the stream.
                // check what is in the non-simplified scene.
                IScene2DPrimitivesSource simpleSource = this.GetNonSimplifiedStream();
                simpleSource.Get(scene, view, zoomFactor);

                // check what index this zoomfactor is for.
                int idx = this.SearchForScene(zoomFactor);
                if (idx >= 0)                                              // the index was found.
                {
                    if (!_loadedScenes.TryGetValue(idx, out simpleSource)) // the scene was not found.
                    {
                        long position = _index.SceneIndexes [idx];
                        _stream.Seek(position, SeekOrigin.Begin);
                        LimitedStream stream = new LimitedStream(_stream);
                        //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
                        //simpleSource = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
                        OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
                            new Styled.Scene2DStyledSerializer();
                        simpleSource = serializer.Deserialize(stream, true);
                        _loadedScenes.Add(idx, simpleSource);
                    }
                    simpleSource.Get(scene, view, zoomFactor);

                    OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredSource", System.Diagnostics.TraceEventType.Verbose,
                                                    string.Format("Deserialized from scene at zoom {0} and idx {1} synchronized.", zoomFactor, idx));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds a new scene layer with the given primitives source as it's source.
        /// </summary>
        /// <param name="scene"></param>
        /// <returns></returns>
        public LayerScene AddLayerScene(IScene2DPrimitivesSource scene)
        {
            LayerScene layerScene = new LayerScene(scene);

            this.AddLayer(layerScene);
            return(layerScene);
        }
Example #3
0
 /// <summary>
 /// Returns the non-simplified scene.
 /// </summary>
 /// <returns></returns>
 private IScene2DPrimitivesSource GetNonSimplifiedStream()
 {
     if (_nonSimplifiedScene == null)
     {
         long position = _index.SceneIndexes[_index.SceneIndexes.Length - 1];
         _stream.Seek(position, SeekOrigin.Begin);
         LimitedStream stream = new LimitedStream(_stream);
         //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
         //_nonSimplifiedScene = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
         OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
             new Styled.Scene2DStyledSerializer();
         _nonSimplifiedScene = serializer.Deserialize(stream, true);
     }
     return(_nonSimplifiedScene);
 }
        public void Scene2DSimpleSerializeDeserializeTest()
        {
            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"),
                imageSource);

            // initialize the data source.
            var xmlSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.test.osm"));
            IEnumerable <OsmGeo> dataSource = xmlSource;
            MemoryDataSource     source     = MemoryDataSource.CreateFrom(xmlSource);

            // get data.
            var scene            = new Scene2DSimple();
            var projection       = new WebMercator();
            GeoCoordinateBox box = null;

            foreach (var osmGeo in dataSource)
            {
                CompleteOsmGeo completeOsmGeo = null;
                switch (osmGeo.Type)
                {
                case OsmGeoType.Node:
                    completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node);
                    break;

                case OsmGeoType.Way:
                    completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way,
                                                            source);
                    break;

                case OsmGeoType.Relation:
                    completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation,
                                                                 source);
                    break;
                }

                // update box.
                if (completeOsmGeo != null)
                {
                    if (box == null)
                    {
                        box = completeOsmGeo.BoundingBox;
                    }
                    else if (completeOsmGeo.BoundingBox != null)
                    {
                        box = box + completeOsmGeo.BoundingBox;
                    }
                }

                // translate each object into scene object.
                mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo);
            }

            // create the stream.
            var stream = new MemoryStream();

            scene.Serialize(stream, false);

            // deserialize the stream.
            IScene2DPrimitivesSource sceneSource = Scene2DSimple.Deserialize(stream, false);

            if (box != null)
            {
                // query both and get the same results.
                int counter = 100;
                var rand    = new Random();
                while (counter > 0)
                {
                    var queryBox = new GeoCoordinateBox(
                        box.GenerateRandomIn(rand),
                        box.GenerateRandomIn(rand));
                    var    zoomFactor = (float)projection.ToZoomFactor(15);
                    View2D testView   = View2D.CreateFromBounds(
                        projection.LatitudeToY(queryBox.MaxLat),
                        projection.LongitudeToX(queryBox.MinLon),
                        projection.LatitudeToY(queryBox.MinLat),
                        projection.LongitudeToX(queryBox.MaxLon));
                    var testScene = new Scene2DSimple();
                    sceneSource.Get(testScene, testView, zoomFactor);

//                    var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor));
//                    var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor));

                    //Assert.AreEqual(resultReference.Count, resultIndex.Count);
                    //foreach (var data in resultIndex)
                    //{
                    //    Assert.IsTrue(resultReference.Contains(data));
                    //}
                    //foreach (var data in resultReference)
                    //{
                    //    Assert.IsTrue(resultIndex.Contains(data));
                    //}
                    counter--;
                }
            }
        }
Example #5
0
 /// <summary>
 /// Creates a new scene layer.
 /// </summary>
 /// <param name="index"></param>
 public LayerScene(IScene2DPrimitivesSource index)
 {
     _index = index;
     _scene2DSimple = new Scene2DSimple();
 }
Example #6
0
 /// <summary>
 /// Creates a new scene layer.
 /// </summary>
 /// <param name="index"></param>
 public LayerScene(IScene2DPrimitivesSource index)
 {
     _index         = index;
     _scene2DSimple = new Scene2DSimple();
 }
Example #7
0
 /// <summary>
 /// Returns the non-simplified scene.
 /// </summary>
 /// <returns></returns>
 private IScene2DPrimitivesSource GetNonSimplifiedStream()
 {
     if (_nonSimplifiedScene == null)
     {
         long position = _index.SceneIndexes[_index.SceneIndexes.Length - 1];
         _stream.Seek(position, SeekOrigin.Begin);
         LimitedStream stream = new LimitedStream(_stream);
         //Scene2DRTreeSerializer serializer = new Scene2DRTreeSerializer(true);
         //_nonSimplifiedScene = new Scene2DPrimitivesSource(serializer.Deserialize(stream));
         OsmSharp.UI.Renderer.Scene.Storage.Styled.Scene2DStyledSerializer serializer =
             new Styled.Scene2DStyledSerializer();
         _nonSimplifiedScene = serializer.Deserialize(stream, true);
     }
     return _nonSimplifiedScene;
 }
Example #8
0
 /// <summary>
 /// Adds a new scene layer with the given primitives source as it's source.
 /// </summary>
 /// <param name="scene"></param>
 /// <returns></returns>
 public LayerScene AddLayerScene(IScene2DPrimitivesSource scene)
 {
     LayerScene layerScene = new LayerScene(scene);
     this.AddLayer(layerScene);
     return layerScene;
 }