private void UpdateTileSize() { switch (TileSize) { case TileSize.Small: this.TilePixelSize = TileDensity.Small; break; case TileSize.Medium: this.TilePixelSize = TileDensity.Medium; break; case TileSize.Wide: this.TilePixelSize = TileDensity.Wide; break; case TileSize.Large: this.TilePixelSize = TileDensity.Large; break; default: throw new NotImplementedException(TileSize.ToString()); } UpdateBranding(); }
void Update() { tileSizeText.text = TileSize.ToString("F1"); EstimateAggressionText.text = EstimateAggression.ToString("F2"); Path path = FastPath.FindPathImmediate(Start, End); if (path.ValidPath) { InvalidPathIndicator.gameObject.SetActive(false); } else { InvalidPathIndicator.gameObject.SetActive(true); } if (DrawMap) { FastPath.DrawMapInEditor(FastPath.DefaultMap); } if (DrawPath) { path.DrawPath(); } RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { if (hit.collider.tag != "Enemy") // && (hit.collider.tag != "NonWalkable" || hit.collider.gameObject == Obstacle.gameObject)) { Obstacle.transform.position = new Vector3(hit.point.x, enemyY, hit.point.z); Path p = FastPath.FindPathImmediate(Start, End, FastPath.IndexesBetween(FastPath.DefaultMap, Obstacle.bounds.min, Obstacle.bounds.max)); if (p.ValidPath) { ObstacleRenderer.material.color = Color.green; if (Input.GetMouseButtonDown(0)) { GameObject instance = (GameObject)Object.Instantiate(Obstacle.gameObject, new Vector3(hit.point.x, enemyY, hit.point.z), Quaternion.identity); instance.GetComponent <MeshRenderer>().material = new Material(ObstacleRenderer.material); FastPath.Update(FastPath.DefaultMap, FastPath.IndexesBetween(FastPath.DefaultMap, Obstacle.bounds.min, Obstacle.bounds.max)); } } else { ObstacleRenderer.material.color = Color.red; } if (DrawPath) { p.DrawPath(); } } else { ObstacleRenderer.material.color = Color.red; } } }
/*Returns a string containing the XML metadata for the .dzi file. * format: the format of the individual tiles ('png' or 'jpeg')*/ public string GetDziMetadataString(string imageFormat = "jpeg") { if (!imageFormat.Equals("jpeg", StringComparison.OrdinalIgnoreCase) && !imageFormat.Equals("png", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException($"Invalid image format {imageFormat}"); } var width = Level0Dimensions.Width; var height = Level0Dimensions.Height; var updatedMetadataTemplate = DeepZoomImageTemplate.Replace("@Width", width.ToString()) .Replace("@Height", height.ToString()); updatedMetadataTemplate = updatedMetadataTemplate.Replace("@TileSize", TileSize.ToString()) .Replace("@Overlap", DeepZoomOverlap.ToString()); updatedMetadataTemplate = updatedMetadataTemplate.Replace("@Format", imageFormat.ToLower()); return(updatedMetadataTemplate); }
/// <summary> /// Creates a map image for a tile. /// </summary> private static async Task <string> CreateTileMapImageAsync(string tileId, double latitude, double longitude, int width, int height, TileSize tileSize) { // Get the image from Bing and save to disk. string tileImageFile = string.Format("{0}-{1}.png", tileId, tileSize.ToString()); string tileImagePath = Path.Combine("Tiles", tileImageFile); bool fileExists = false; try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync(tileImagePath); fileExists = true; } catch { } // Create the file: if (!fileExists) { BingMapsServiceHelper bingMapsHelper = new BingMapsServiceHelper(); using (var memoryStream = await bingMapsHelper.GetStaticImageBytesAsync( latitude, longitude, width, height)) { IStorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(tileImagePath, CreationCollisionOption.ReplaceExisting); using (var stream = await storageFile.OpenStreamForWriteAsync()) { memoryStream.WriteTo(stream); } } } return(tileImageFile); }
public override Dictionary <string, string> SaveState() { Dictionary <string, string> resultState = base.SaveState(); resultState["IsZoomToExtentOfNewLayer"] = IsZoomToExtentOfNewLayer.ToString(); resultState["IsZoomToExtentOfOnlyFirstLayer"] = IsZoomToExtentOfOnlyFirstLayer.ToString(); resultState["MaxRecordsToDraw"] = MaxRecordsToDraw.ToString(CultureInfo.InvariantCulture); resultState["UseCache"] = UseCache.ToString(); resultState["IsLimitDrawgingFeaturesCount"] = IsLimitDrawgingFeaturesCount.ToString(); resultState["TileSize"] = TileSize.ToString(CultureInfo.InvariantCulture); resultState["IsShowAddDataRepositoryDialog"] = IsShowAddDataRepositoryDialog.ToString(); resultState["IsShowPanZoomBar"] = IsShowPanZoomBar.ToString(); resultState["HighQuality"] = HighQuality.ToString(); resultState["DefaultBaseMapOption"] = ((int)DefaultBaseMapOption).ToString(CultureInfo.InvariantCulture); resultState["PlaceSearchMaxResultCount"] = PlaceSearchMaxValue.ToString(CultureInfo.InvariantCulture); resultState["AltitudeMode"] = ((int)AltitudeMode).ToString(CultureInfo.InvariantCulture); resultState["Height"] = Height.ToString(CultureInfo.InvariantCulture); resultState["ZoomSnapDirection"] = ((int)ZoomSnapDirection).ToString(CultureInfo.InvariantCulture); resultState["DisableGlobeButton"] = DisableGlobeButton.ToString(); resultState["OverlayRefreshDelayInterval"] = OverlayRefreshDelayInterval.ToString(); return(resultState); }
public XmlDocument GetTileSets(string tilemapName) { var doc = new XmlDocument(); var root = doc.CreateElement(String.Empty, "TileMap", String.Empty); doc.AppendChild(root); var versionAttribute = doc.CreateAttribute("version"); versionAttribute.Value = Utils.TileMapServiceVersion; root.Attributes.Append(versionAttribute); var tilemapservice = $"{this.baseUrl}/tms/{Utils.TileMapServiceVersion}/"; var tilemapserviceAttribute = doc.CreateAttribute("tilemapservice"); tilemapserviceAttribute.Value = tilemapservice; root.Attributes.Append(tilemapserviceAttribute); var titleNode = doc.CreateElement("Title"); titleNode.AppendChild(doc.CreateTextNode(tilemapName)); root.AppendChild(titleNode); var abstractNode = doc.CreateElement("Abstract"); abstractNode.AppendChild(doc.CreateTextNode(tilemapName)); root.AppendChild(abstractNode); var srs = doc.CreateElement("SRS"); srs.AppendChild(doc.CreateTextNode(Utils.EPSG3857)); root.AppendChild(srs); const int TileSize = 256; const double maxy = 20037508.342789; const double maxx = 20037508.342789; const double miny = -20037508.342789; const double minx = -20037508.342789; var boundingBox = doc.CreateElement("BoundingBox"); var maxyAttribute = doc.CreateAttribute("maxy"); maxyAttribute.Value = maxy.ToString("F6", CultureInfo.InvariantCulture); boundingBox.Attributes.Append(maxyAttribute); var maxxAttribute = doc.CreateAttribute("maxx"); maxxAttribute.Value = maxx.ToString("F6", CultureInfo.InvariantCulture); boundingBox.Attributes.Append(maxxAttribute); var minyAttribute = doc.CreateAttribute("miny"); minyAttribute.Value = miny.ToString("F6", CultureInfo.InvariantCulture); boundingBox.Attributes.Append(minyAttribute); var minxAttribute = doc.CreateAttribute("minx"); minxAttribute.Value = minx.ToString("F6", CultureInfo.InvariantCulture); boundingBox.Attributes.Append(minxAttribute); root.AppendChild(boundingBox); var origin = doc.CreateElement("Origin"); var yAttribute = doc.CreateAttribute("y"); yAttribute.Value = miny.ToString("F6", CultureInfo.InvariantCulture); origin.Attributes.Append(yAttribute); var xAttribute = doc.CreateAttribute("x"); xAttribute.Value = minx.ToString("F6", CultureInfo.InvariantCulture); origin.Attributes.Append(xAttribute); root.AppendChild(origin); var tm = Startup.TileSources[tilemapName]; var tileFormat = doc.CreateElement("TileFormat"); var extensionAttribute = doc.CreateAttribute("extension"); extensionAttribute.Value = tm.Configuration.Format; tileFormat.Attributes.Append(extensionAttribute); var mimetypeAttribute = doc.CreateAttribute("mime-type"); mimetypeAttribute.Value = tm.ContentType; tileFormat.Attributes.Append(mimetypeAttribute); var heightAttribute = doc.CreateAttribute("height"); heightAttribute.Value = TileSize.ToString(CultureInfo.InvariantCulture); tileFormat.Attributes.Append(heightAttribute); var widthAttribute = doc.CreateAttribute("width"); widthAttribute.Value = TileSize.ToString(CultureInfo.InvariantCulture); tileFormat.Attributes.Append(widthAttribute); root.AppendChild(tileFormat); var tileSets = doc.CreateElement("TileSets"); root.AppendChild(tileSets); for (var level = 0; level <= 18; level++) // TODO: get real existing range { var tileSet = doc.CreateElement("TileSet"); var href = $"{this.baseUrl}/tms/{Utils.TileMapServiceVersion}/{tm.Configuration.Name}/{tilemapName}/{level}"; var hrefAttribute = doc.CreateAttribute("href"); hrefAttribute.Value = href; tileSet.Attributes.Append(hrefAttribute); var orderAttribute = doc.CreateAttribute("order"); orderAttribute.Value = $"{level}"; tileSet.Attributes.Append(orderAttribute); var unitsperpixel = (maxx - minx) / (((double)TileSize) * Math.Pow(2, level)); var unitsperpixelAttribute = doc.CreateAttribute("units-per-pixel"); unitsperpixelAttribute.Value = unitsperpixel.ToString(CultureInfo.InvariantCulture); tileSet.Attributes.Append(unitsperpixelAttribute); tileSets.AppendChild(tileSet); } return(doc); }
private void UpdateBranding() { // On Small tiles, margin is only 4px, so branding needs to move too switch (TileSize) { case TileSize.Small: Branding.Margin = new Thickness(0, 0, 2, -4); break; default: Branding.Margin = new Thickness(0, 0, 6, 0); break; } bool showName; bool showCornerLogo; // If the notification overrided branding if (_notificationBranding != null) { var brandingValue = _notificationBranding.Value; // If we're on Mobile if (DeviceFamily == DeviceFamily.Mobile) { // "logo" and "nameAndLogo" become "name" switch (brandingValue) { case Model.Enums.Branding.Logo: case Model.Enums.Branding.NameAndLogo: brandingValue = Model.Enums.Branding.Name; break; } } switch (brandingValue) { case Model.Enums.Branding.None: showName = false; showCornerLogo = false; break; case Model.Enums.Branding.Name: showName = true; showCornerLogo = false; break; case Model.Enums.Branding.Logo: showName = false; showCornerLogo = true; break; default: //NameAndLogo showName = true; showCornerLogo = true; break; } // Small can never show display name (but it can apparently display logo) if (TileSize == TileSize.Small) { showName = false; } } // Otherwise, use behaviors from VisualElements else { // Default behavior is to never show corner logo (if notification displayed, default branding inherits ShowName from basic tile properties, never shows corner logo) showCornerLogo = false; switch (TileSize) { case TileSize.Small: showName = false; // name never shown on small break; case TileSize.Medium: showName = VisualElements.ShowNameOnSquare150x150Logo; break; case TileSize.Wide: showName = VisualElements.ShowNameOnWide310x150Logo; break; case TileSize.Large: showName = VisualElements.ShowNameOnSquare310x310Logo; break; default: throw new NotImplementedException(TileSize.ToString()); } } // Decide to show the name TextBlockDisplayName.Visibility = showName ? Visibility.Visible : Visibility.Collapsed; // Decide to show corner logo CornerLogo.Visibility = showCornerLogo ? Visibility.Visible : Visibility.Collapsed; // Decide if branding is shown... if (HasBadge() || showName || showCornerLogo) { Branding.Visibility = Visibility.Visible; } else { Branding.Visibility = Visibility.Collapsed; } }
public void Generate() { if (InputFilePath == null) { throw new InvalidOperationException("Input file path is not specified."); } if (OutputDirPath == null) { throw new InvalidOperationException("Output directory path is not specified."); } if (ViewerCreation && BaseName == null) { throw new InvalidOperationException("Base name should be specified for viewer creation."); } var zoomLevels = new List <ZoomLevel>(); ImageReader reader = null; try { reader = ImageReader.Create(InputFilePath); var d = 1f; ZoomLevel zoomLevel; do { zoomLevel.ImageWidth = (int)((float)reader.Width / d); zoomLevel.ImageHeight = (int)((float)reader.Height / d); zoomLevel.GridWidth = (zoomLevel.ImageWidth + TileSize - 1) / TileSize; zoomLevel.GridHeight = (zoomLevel.ImageHeight + TileSize - 1) / TileSize; zoomLevels.Add(zoomLevel); tileTotal += zoomLevel.GridWidth * zoomLevel.GridHeight; d *= 2; } while (zoomLevel.ImageWidth > TileSize || zoomLevel.ImageHeight > TileSize); zoomLevels.Reverse(); if (ViewerCreation) { var bd = AppDomain.CurrentDomain.BaseDirectory; try { if (!Directory.Exists(OutputDirPath)) { Directory.CreateDirectory(OutputDirPath); } } catch (Exception e) { throw new IOException(String.Format("Can't create directory {0}.\r\n {1}", OutputDirPath, e.Message)); } File.Copy(Path.Combine(bd, ScriptFileName), Path.Combine(OutputDirPath, ScriptFileName), true); var viewer = File.ReadAllText(Path.Combine(bd, ViewerFileName)). Replace("{viewerwidth}", ViewerWidth.ToString()). Replace("{viewerheight}", ViewerHeight.ToString()). Replace("{imagewidth}", reader.Width.ToString()). Replace("{imageheight}", reader.Height.ToString()). Replace("{basename}", BaseName). Replace("{structure}", FileStructure.Replace("{ext}", GetTileFileExt())); if (TileSize != 256) { viewer = viewer.Replace("{tilesize}", TileSize.ToString()); } else { var r = new Regex(@"^.*{tilesize}.*\r\n", RegexOptions.Multiline); viewer = r.Replace(viewer, ""); } File.WriteAllText(Path.Combine(OutputDirPath, BaseName + ".htm"), viewer); } } finally { if (reader != null) { reader.Dispose(); } } tileProcessedTotal = 0; //Application can't have more than 2048 file handlers. //We can reach the limit with >~100 MP images for (int minTileIndex = 1; minTileIndex <= tileTotal; minTileIndex += MaxOpenFileCount) { int maxTileIndex = Math.Min(minTileIndex + MaxOpenFileCount - 1, tileTotal); int tileIndex = 0; //Store reference to all pipeline elements for further correct object disposing var pipelineElements = new List <PipelineElement>(); try { reader = ImageReader.Create(InputFilePath); pipelineElements.Add(reader); PipelineElement source; //Create progress tracker if (Progress != null) { var progress = new ProgressReporter(); progress.Progress += (s, e) => { OnProgress(e); }; pipelineElements.Add(progress); reader.Receivers.Add(progress); source = progress; } else { source = reader; } for (int zoom = 0; zoom < zoomLevels.Count; zoom++) { PipelineElement resize; if (zoom == zoomLevels.Count) { resize = source; } else { resize = new Resize(zoomLevels[zoom].ImageWidth, zoomLevels[zoom].ImageHeight, ResizeInterpolationMode.Anisotropic9); pipelineElements.Add(resize); source.Receivers.Add(resize); } for (int tileX = 0; tileX < zoomLevels[zoom].GridWidth; tileX++) { for (int tileY = 0; tileY < zoomLevels[zoom].GridHeight; tileY++) { tileIndex++; if (tileIndex < minTileIndex) { continue; } int x = tileX * TileSize; int y = tileY * TileSize; int width = Math.Min((tileX + 1) * TileSize, zoomLevels[zoom].ImageWidth) - x; int height = Math.Min((tileY + 1) * TileSize, zoomLevels[zoom].ImageHeight) - y; var crop = new Crop(x, y, width, height); pipelineElements.Add(crop); resize.Receivers.Add(crop); var outputFilePath = Path.Combine(GetTileOutputDirPath(), String.Format(GetFileStructureFormat(), zoom, tileX, tileY, GetTileFileExt())); var p = Path.GetDirectoryName(outputFilePath); try { if (!Directory.Exists(p)) { Directory.CreateDirectory(p); } } catch (Exception e) { throw new IOException(String.Format("Can't create directory {0}.\r\n {1}", p, e.Message)); } ImageWriter writer; switch (TileImageFormat) { case TileImageFormat.PNG: writer = new PngWriter(outputFilePath); break; default: writer = new JpegWriter(outputFilePath, TileJpegQuality); break; } pipelineElements.Add(writer); crop.Receivers.Add(writer); if (tileIndex == maxTileIndex) { //Remove resize elements without crop receivers for (var l = source.Receivers.Count - 1; l >= 0; l--) { if (source.Receivers[l].Receivers.Count == 0) { source.Receivers.RemoveAt(l); } } Pipeline.Run(reader); tileProcessedTotal = maxTileIndex; goto LoopOut; } } } } LoopOut: ; } finally { for (var i = 0; i < pipelineElements.Count; i++) { pipelineElements[i].Dispose(); } } } }
/// <summary> /// Creates a map image for a tile. /// </summary> private static async Task<string> CreateTileMapImageAsync(string tileId, double latitude, double longitude, int width, int height, TileSize tileSize) { // Get the image from Bing and save to disk. string tileImageFile = string.Format("{0}-{1}.png", tileId, tileSize.ToString()); string tileImagePath = Path.Combine("Tiles", tileImageFile); bool fileExists = false; try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync(tileImagePath); fileExists = true; } catch { } // Create the file: if (!fileExists) { BingMapsServiceHelper bingMapsHelper = new BingMapsServiceHelper(); using (var memoryStream = await bingMapsHelper.GetStaticImageBytesAsync( latitude, longitude, width, height)) { IStorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(tileImagePath, CreationCollisionOption.ReplaceExisting); using (var stream = await storageFile.OpenStreamForWriteAsync()) { memoryStream.WriteTo(stream); } } } return tileImageFile; }
/// <summary> /// Load a tiled image with a known number of tiles on the x-y axis from disk. /// The tiles don't have to be uniform, in order to support altered references. /// @todo Check file type and pixel format. /// @todo Deal with possible memory leaks from not disposing images on error (not just in this method). /// </summary> /// <param name="filename">The file to load.</param> /// <param name="columns">Number of tiles left-right.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentOutOfRangeException"></exception> /// <exception cref="System.ArgumentException"></exception> public TiledImage(string filename, int columns) { Validation.CheckString("filename", filename); Validation.CheckInteger("columnWidth", columns, 1); try { Image image = Bitmap.FromFile(filename); this.image = new Bitmap(image); if (this.image.Width % columns != 0) { throw new ArgumentException("Image width is not divisible by " + columns.ToString() + ".", "columns"); } TileSize = this.image.Width / columns; Width = this.image.Width / TileSize; if (this.image.Height % TileSize != 0) { throw new ArgumentException("Image height is not divisible by " + TileSize.ToString() + ".", "Tile Size"); } Height = this.image.Height / TileSize; } catch (Exception e) { throw new ArgumentException("Bad image file: " + e.Message, e); } }