예제 #1
0
        private void SaveTileData(Tile tile, string filePath)
        {
            lock (_lockGuard)
            {
                if (CoreLibrary.HasData(tile.QuadKey))
                {
                    return;
                }

                var filePathResolved       = _pathResolver.Resolve(filePath);
                var stylesheetPathResolved = _pathResolver.Resolve(tile.Stylesheet.Path);

                Trace.Info(TraceCategory, String.Format("save tile data {0} from {1} using style: {2}",
                                                        tile, filePathResolved, stylesheetPathResolved));

                string errorMsg = null;
                CoreLibrary.AddToStore(MapStorageType.Persistent,
                                       stylesheetPathResolved,
                                       filePathResolved,
                                       tile.QuadKey,
                                       error => errorMsg = error);

                if (errorMsg != null)
                {
                    throw new MapDataException(String.Format(Strings.CannotAddDataToInMemoryStore, errorMsg));
                }
            }
        }
예제 #2
0
        /// <summary> Downloads map data for given tile. </summary>
        private IObservable <Tile> CreateDownloadSequence(Tile tile)
        {
            // data exists in store
            if (CoreLibrary.HasData(tile.QuadKey))
            {
                return(Observable.Return(tile));
            }

            // data exists in cache
            var filePath = GetCacheFilePath(tile);

            if (_fileSystemService.Exists(filePath))
            {
                var errorMsg = SaveTileDataInMemory(tile, filePath);
                return(errorMsg == null
                    ? Observable.Return(tile)
                    : Observable.Throw <Tile>(new MapDataException(Strings.CannotAddDataToInMemoryStore, errorMsg)));
            }

            // need to download from remote server
            return(Observable.Create <Tile>(observer =>
            {
                double padding = 0.001;
                BoundingBox query = tile.BoundingBox;
                var queryString = String.Format(_mapDataServerQuery,
                                                query.MinPoint.Latitude - padding, query.MinPoint.Longitude - padding,
                                                query.MaxPoint.Latitude + padding, query.MaxPoint.Longitude + padding);
                var uri = String.Format("{0}{1}", _mapDataServerUri, Uri.EscapeDataString(queryString));
                Trace.Warn(TraceCategory, Strings.NoPresistentElementSourceFound, tile.QuadKey.ToString(), uri);
                _networkService.GetAndGetBytes(uri)
                .ObserveOn(Scheduler.ThreadPool)
                .Subscribe(bytes =>
                {
                    Trace.Debug(TraceCategory, "saving bytes: {0}", bytes.Length.ToString());
                    lock (_lockObj)
                    {
                        if (!_fileSystemService.Exists(filePath))
                        {
                            using (var stream = _fileSystemService.WriteStream(filePath))
                                stream.Write(bytes, 0, bytes.Length);
                        }
                    }

                    // try to add in memory store
                    var errorMsg = SaveTileDataInMemory(tile, filePath);
                    if (errorMsg != null)
                    {
                        observer.OnError(new MapDataException(String.Format(Strings.CannotAddDataToInMemoryStore, errorMsg)));
                    }
                    else
                    {
                        observer.OnNext(tile);
                        observer.OnCompleted();
                    }
                });

                return Disposable.Empty;
            }));
        }
예제 #3
0
        private IObservable <string> CreateMapDataObservable(Tile tile)
        {
            if (CoreLibrary.HasData(tile.QuadKey))
            {
                return(Observable.Return(""));
            }

            if (OsmTileRange.Contains(tile.QuadKey.LevelOfDetail))
            {
                return(_osmMapDataProvider.Get(tile));
            }

            return(_mapzenMapDataProvider.Get(tile));
        }
예제 #4
0
        /// <inheritdoc />
        public IObservable <Union <Element, Mesh> > Load(Tile tile)
        {
            return(_mapDataProvider
                   .Get(tile)
                   .SelectMany(filePath =>
            {
                if (!CoreLibrary.HasData(tile.QuadKey))
                {
                    SaveTileData(tile, filePath);
                }

                return CreateLoadSequence(tile);
            }));
        }
예제 #5
0
            /// <inheritdoc />
            public override void OnNext(Tile value)
            {
                if (CoreLibrary.HasData(value.QuadKey))
                {
                    Notify(new Tuple <Tile, string>(value, ""));
                    return;
                }

                if (OsmTileRange.Contains(value.QuadKey.LevelOfDetail))
                {
                    _osmMapDataProvider.OnNext(value);
                }
                else
                {
                    _mapzenMapDataProvider.OnNext(value);
                }
            }