/// <summary>
        /// Serialize/deserialize index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        private ITagsCollectionIndexReadonly SerializeDeserializeLimitedStream(ITagsCollectionIndex index, int position)
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Seek(position, SeekOrigin.Begin);

            LimitedStream stream = new LimitedStream(memoryStream);
            TagIndexSerializer.Serialize(stream, index);
            stream.Seek(0, SeekOrigin.Begin);

            return TagIndexSerializer.Deserialize(stream);
        }
예제 #2
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));
                }
            }
        }
예제 #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;
 }
예제 #4
0
        /// <summary>
        /// Serialize/deserialize index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="blockSize"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        private ITagsIndexReadonly SerializeDeserializeBlockLimitedStream(ITagsIndex index, uint blockSize, int position)
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.Seek(position, SeekOrigin.Begin);

            LimitedStream stream = new LimitedStream(memoryStream);
            stream.Seek(position, SeekOrigin.Begin);
            TagIndexSerializer.SerializeBlocks(stream, index, blockSize);

            stream.Seek(position, SeekOrigin.Begin);
            return TagIndexSerializer.DeserializeBlocks(stream);
        }