protected virtual void OnSourceServerChanged(object sender, ValueChangedEventArgs <SourceTileServer> e) { if (e.PreviousValue != null) { RemoveLogicalChild(e.PreviousValue); } if (e.CurrentValue != null) { AddLogicalChild(e.CurrentValue); } SourceTileServer sourceServer = server.SourceServer; if (sourceServer != null) { tileProvider.MinLevel = sourceServer.MinLevel; tileProvider.MaxLevel = sourceServer.MaxLevel; tileWidth = sourceServer.TileWidth; tileHeight = sourceServer.TileHeight; MapTileProvider provider = tileProvider as MapTileProvider; if (provider != null) { provider.MaxLatitude = sourceServer.MaxLatitude; } } UpdateDebugMenuHeaders(); BeginInvalidateVisual(); }
protected virtual void OnNetworkServerChanged(object sender, ValueChangedEventArgs <SourceTileServer> e) { if (e.PreviousValue != null) { RemoveLogicalChild(e.PreviousValue); } if (e.CurrentValue != null) { AddLogicalChild(e.CurrentValue); } SourceTileServer networkServer = server.SourceServer; if (networkServer != null) { tileProvider.MinLevel = networkServer.MinLevel; tileProvider.MaxLevel = networkServer.MaxLevel; MapTileProvider mapProvider = tileProvider as MapTileProvider; if (mapProvider != null) { mapProvider.MaxLatitude = networkServer.MaxLatitude; } tileWidth = networkServer.TileWidth; tileHeight = networkServer.TileHeight; } BeginInvalidateVisual(); }
public override void BeginLoadImage(TileIndex id) { VerifyTileIndex(id); string uri = CreateRequestUriCore(MapTileProvider.Normalize(id)); bool useMultipleServers = ServersNum != 0; if (useMultipleServers) { CurrentServer++; if (CurrentServer >= MinServer + ServersNum) { CurrentServer = MinServer; } } if (runningDownloadsNum >= MaxConcurrentDownloads) { waitingIDs.Push(id); return; } MapsTraceSource.Instance.ServerInformationTraceSource.TraceInformation("\"{0}\" - began to load url=\"{1}\"", GetCustomName(), uri); WebRequest request = WebRequest.Create(uri); request.Proxy.Credentials = CredentialCache.DefaultCredentials; AdjustRequest(request); runningDownloadsNum++; // this is hack to prevent freezing when request.BeginGetResponse was called // at the 1st time if (!firstCall) { request.BeginGetResponse(ResponseReadyCallback, new ResponseCallbackInfo { ID = id, Request = request }); } else { Task.Factory.StartNew(() => { request.BeginGetResponse(ResponseReadyCallback, new ResponseCallbackInfo { ID = id, Request = request }); }).WithExceptionThrowingInDispatcher(Dispatcher); } }
public override bool Contains(TileIndex id) { // todo probably preload existing images into fileMap. // todo probably save previous fileMaps. if (id.Level != currentLevel) { fileMap = new Dictionary <TileIndex, bool>(new TileIndex.TileIndexEqualityComparer()); currentLevel = id.Level; if (MapTileProvider.GetTotalTilesCount(currentLevel) <= maxIndicesToPrecache) { Stopwatch timer = Stopwatch.StartNew(); var directory = new DirectoryInfo(GetZoomDir(currentLevel)); if (directory.Exists) { var files = directory.GetFiles(); var fileNames = (from file in files select file.Name).ToList(); fileNames.Sort(); var tileInfos = from tile in MapTileProvider.GetTilesForLevel(currentLevel) let name = GetFileName(GetNameByIndex(tile)) orderby name select new { Tile = tile, Name = name }; foreach (var tileInfo in tileInfos) { fileMap[tileInfo.Tile] = fileNames.Contains(tileInfo.Name); } MapsTraceSource.Instance.ServerInformationTraceSource .TraceInformation($"Precached directory for level {currentLevel}: {timer.ElapsedMilliseconds} ms"); } } } if (fileMap.ContainsKey(id)) { return(fileMap[id]); } else { string path = GetImagePath(id); bool res = File.Exists(path); fileMap[id] = res; return(res); } }
protected List <VisibleTileInfo> GetVisibleTiles() { var transform = plotter.Viewport.Transform; Rect output = plotter.Viewport.Output; DataRect visible = plotter.Viewport.Visible; var tileInfos = (from tile in tileProvider.GetTilesForRegion(TransformRegion(visible), tileProvider.Level) let visibleRect = Transform(tileProvider.GetTileBounds(tile)) let screenRect = visibleRect.ViewportToScreen(transform) where output.IntersectsWith(screenRect) select new VisibleTileInfo { Tile = tile, ScreenBounds = screenRect, VisibleBounds = visibleRect }).ToList(); if (tileInfos.Count > MapTileProvider.GetTotalTilesCount(tileProvider.Level)) { //Debugger.Break(); } return(tileInfos); }
private void ChangeTextFormat() { if (changedTextFormat) { return; } // todo discover why sometimes we arrive here from PlotterChildren_CollectionChanged when we have removed this handler from // plotter.Children.CollectionChanged invocation list. if (plotter == null) { return; } var cursorGraph = plotter.Children.OfType <CursorCoordinateGraph>().FirstOrDefault <CursorCoordinateGraph>(); if (cursorGraph != null) { changedTextFormat = true; // saving previous text mappings prevXMapping = cursorGraph.XTextMapping; prevYMapping = cursorGraph.YTextMapping; // setting new text mappings cursorGraph.XTextMapping = value => { if (double.IsNaN(value)) { return(""); } if (-180 <= value && value <= 180) { Degree degree = Degree.CreateLongitude(value); return(degree.ToString()); } else { return(null); } }; cursorGraph.YTextMapping = value => { if (double.IsNaN(value)) { return(""); } MapTileProvider provider = tileProvider as MapTileProvider; if (provider != null && provider.MinLatitude <= value && value <= provider.MaxLatitude) { Degree degree = Degree.CreateLatitude(value); return(degree.ToString()); } else { return(null); } }; } }
protected void OnRender() { if (DesignerProperties.GetIsInDesignMode(this)) { return; } if (plotter == null) { return; } panel.Children.Clear(); freeChildren = new List <MapElement>(panel.Children.Count); for (int i = 0; i < panel.Children.Count; i++) { freeChildren.Add((MapElement)panel.Children[i]); } rendering = true; invalidatePending = false; var transform = plotter.Viewport.Transform; Rect output = plotter.Viewport.Output; DataRect visible = plotter.Viewport.Visible; visibleBounds = visible; drawnBounds = DataRect.Empty; var tileInfos = GetVisibleTiles(); var lowerTilesList = GetLoadedLowerTiles(tileInfos); // displaying lower tiles foreach (var tile in lowerTilesList) { if (server.IsLoaded(tile)) { var bmp = server[tile]; DataRect visibleRect = tileProvider.GetTileBounds(tile); DrawImage(bmp, visibleRect, tile); } else { server.BeginLoadImage(tile); } } int count = 0; foreach (var tileInfo in tileInfos) { drawnBounds.Union(tileInfo.VisibleBounds); count++; if (server.IsLoaded(tileInfo.Tile)) { var bmp = server[tileInfo.Tile]; DrawImage(bmp, tileInfo.VisibleBounds, tileInfo.Tile); } else { server.BeginLoadImage(tileInfo.Tile); } } showsWholeMap = count == MapTileProvider.GetTotalTilesCount(tileProvider.Level); foreach (var item in freeChildren) { panel.Children.Remove(item); pool.Put(item); } foreach (MapElement item in panel.Children) { if (item.Bitmap == null) { panel.Children.Remove(item); pool.Put(item); } } rendering = false; Debug.WriteLine("Drawn " + Environment.TickCount); }