public Tile plot(iustc.map.data.Path[] paths, iustc.map.data.Rectangle rect, int level) { //Deployment.Current.Dispatcher.BeginInvoke(() => // { Canvas bitmap = new Canvas(); bitmap.Width = size + 2; bitmap.Height = size + 2; bitmap.Background = defaultPaint.Fill; RectangleGeometry clipRect = new RectangleGeometry(); clipRect.Rect = new System.Windows.Rect(0, 0, size + 2, size + 2); bitmap.Clip = clipRect; // Step 1: plot ground plotNature(bitmap, paths, rect); // Step 2: plot road border plotRoadBorder(bitmap, paths, rect, level); //Step 3: plot roads plotRoad(bitmap, paths, rect, level); // Step 4: plot building plotBuilding(bitmap, paths, rect); Tile tile = new Tile(rect.north, rect.west, bitmap); //}); return tile; }
public void put(string key, Tile[] value) { // lock ("myLock") // { try { //if (wSet.Remove(key)) //{ // if (!avail.ContainsKey(key)) // avail.Remove(key); // avail.Add(key, value); //} cache.put(key, value); } finally { } // } // mainPage.testUI(); }
public void run() { while (_thread.IsAlive) { string quadkey = cm.takeKey(); if (quadkey == null) break ; iustc.map.data.Rectangle rect = Toolkit.getRectangle(quadkey); QuadtreeEntry entry = dm.getEntry(quadkey); Deployment.Current.Dispatcher.BeginInvoke(() => { Tile[] tiles = new Tile[entry.labels.Length + 1]; Point p; if (MainPage.isoFile.FileExists("cache\\" + quadkey + ".jpg")) { MainPage.profiling("get from isoFile start"); using(MainPage.isoFileStream = MainPage.isoFile.OpenFile("cache\\" + quadkey + ".jpg", System.IO.FileMode.Open)) { BitmapImage bm = new BitmapImage(); bm.SetSource(MainPage.isoFileStream); Image img = new Image(); img.Source = bm; Canvas canvas = new Canvas(); canvas.Children.Add(img); tiles[0] = new Tile(rect.north, rect.west, canvas); } MainPage.profiling("get from isoFile end"); } else { tiles[0] = mapPlotter.plot(entry.paths, rect, entry.zoomLevel()); using(MainPage.isoFileStream = MainPage.isoFile.OpenFile("cache\\" + quadkey + ".jpg", System.IO.FileMode.CreateNew)) { WriteableBitmap wb = new WriteableBitmap(tiles[0].bitmap, null); wb.SaveJpeg(MainPage.isoFileStream, wb.PixelWidth, wb.PixelHeight, 0, 65); } } p = cm.mainPage.geoToView(tiles[0].lat, tiles[0].lon); if (!cm.mainPage.MapViewport.Children.Contains(tiles[0].bitmap)) cm.mainPage.MapViewport.Children.Add(tiles[0].bitmap); tiles[0].bitmap.SetValue(Canvas.TopProperty, p.Y); tiles[0].bitmap.SetValue(Canvas.LeftProperty, p.X); tiles[0].bitmap.SetValue(Canvas.ZIndexProperty, -1); RotateTransform trans = new RotateTransform(); for (int i = 0; i < entry.labels.Length; i++) { Label label = entry.labels[i]; Tile tile = labelCache.get(label.id); if (tile == null) { if (MainPage.isoFile.FileExists("cache" + label.id.ToString() + ".jpg")) { using (MainPage.isoFileStream = MainPage.isoFile.OpenFile("cache\\" + label.id.ToString() + ".jpg", System.IO.FileMode.Open)) { BitmapImage bm = new BitmapImage(); bm.SetSource(MainPage.isoFileStream); Image img = new Image(); img.Source = bm; Canvas canvas = new Canvas(); canvas.Children.Add(img); tile = new Tile(label.lat, label.lon, canvas); } } else { TextBlock tb = new TextBlock(); Canvas canvas = new Canvas(); Image img = new Image(); tile = labelPlotter.plot(label, tb, canvas, img, trans); using (MainPage.isoFileStream = MainPage.isoFile.OpenFile("cache\\" + label.id.ToString() + ".jpg", System.IO.FileMode.Create)) { if (label.id != 0) { WriteableBitmap wb = new WriteableBitmap(tile.bitmap, null); wb.SaveJpeg(MainPage.isoFileStream, wb.PixelWidth, wb.PixelHeight, 0, 65); } } } labelCache.put(label.id, tile); } tiles[i + 1] = tile; p = cm.mainPage.geoToView(tile.lat, tile.lon); if (!cm.mainPage.LabelViewport.Children.Contains(tile.bitmap)) cm.mainPage.LabelViewport.Children.Add(tile.bitmap); tile.bitmap.SetValue(Canvas.TopProperty, p.Y - 15); tile.bitmap.SetValue(Canvas.LeftProperty, p.X); } cm.put(quadkey, tiles); }); } }
public Tile plot(iustc.map.data.Path[] paths, iustc.map.data.Rectangle rect, int level) { WriteableBitmap bitmap = new WriteableBitmap(size, size); // Step 1: plot ground plotNature(bitmap, paths, rect); // Step 2: plot road border plotRoadBorder(bitmap, paths, rect, level); // Step 3: plot roads plotRoad(bitmap, paths, rect, level); // Step 4: plot building plotBuilding(bitmap, paths, rect); Tile tile = new Tile(rect.north, rect.west, bitmap); return tile; }