protected Layer(Wms wms) { // This object is readonly. Debug.Assert(wms != null, "Layer cannot exist without WMS!"); Wms = wms; CrsIds = null; AutoUpdate = true; ImageFormat = ImageFormat.PNG; IsTransparent = true; BgColor = Color.White; node.Checked = true; }
public Uri GetImageAddress(Wms wms) { // This object is readonly. // WMS is readonly. Debug.Assert(wms != null, "Every layer must have a parent layer!"); if (layers.Length > 0 && (crsId >= 0 && crsId < wms.CRSCount)) { // Coordinates of requested map, left ... var left = viewport.LeftCorner.ToString(CultureInfo.InvariantCulture); // ... bottom ... var bottom = viewport.BottomCorner.ToString(CultureInfo.InvariantCulture); // ... right ... var right = viewport.RightCorner.ToString(CultureInfo.InvariantCulture); var top = viewport.TopCorner.ToString(CultureInfo.InvariantCulture); // ... and top var isReversed = wms.IsCrsReversed; var minx = isReversed ? bottom : left; var miny = isReversed ? left : bottom; var maxx = isReversed ? top : right; var maxy = isReversed ? right : top; var address = string.Format(CultureInfo.InvariantCulture, IMAGE_ADDRESS_TEMPLATE, wms.ServiceAddress, // Address of the service wms.Version, // Version of the service layers, // Ordered list of layers (the first is the top-most) wms.CRSVariableName, // Variable name for CRS wms.GetCRSName(crsId), // CRS of requested map minx, miny, maxx, maxy, viewport.Width, // Width of image in pixels viewport.Height, // Height of image in pixels wms.GetImageFormat(format), // Format of the map image isTransparent.ToString(), // String representation of transparency // Transparent color in hexadecimal: red ... bgColor.R.ToString("X2", CultureInfo.InvariantCulture), bgColor.G.ToString("X2", CultureInfo.InvariantCulture), // ... green ... bgColor.B.ToString("X2", CultureInfo.InvariantCulture)); // ... and blue try { var uri = new Uri(address); return(uri); } catch (UriFormatException) { Debug.Fail("The address template is incorrect!"); return(null); } } return(null); }
private void Enable() { Debug.Assert(layer != null, "We cannot decide whether the form is enabled without layer!"); var enabled = layer.IsRequestedIndividually() && supportedCrs.SelectedIndex != -1; supportedCrs.Enabled = enabled; downloadOneImage.Enabled = enabled && !layer.IsLeaf(); autoUpdate.Enabled = enabled; imageFormats.Enabled = enabled; Debug.Assert(!enabled || imageFormats.SelectedIndex != -1, "At least one image format must be selected!"); transparent.Enabled = enabled && Wms.AbleToBeTransparent(layer.ImageFormat); transparentColor.Enabled = enabled; imageAddress.Enabled = enabled; }
public Layer Create(Wms wms) { // This object is readonly. Layer layer; if (layers.Count > 0) { layer = new BranchLayer(wms); } else { layer = new LeafLayer(Name, wms); } try { layer.node = new TreeNode(Title); layer.node.Tag = layer; layer.node.Checked = true; layer.node.ToolTipText = Description; var crsIdsArray = new int[crsIds.Count]; layer.CrsIds = crsIdsArray; crsIds.Keys.CopyTo(crsIdsArray, 0); layer.ImageFormat = WmsCreator.GetBestSupportedFormat(); foreach (var creator in layers) { var subLayer = creator.Create(wms); layer.Nodes.Add(subLayer.node); } } catch (Exception) { layer.Dispose(); throw; } return(layer); }
public void Refresh(Layer newLayer) { layer = newLayer; if (newLayer != null) { FillCrsComboBox(); layerTitle.Text = newLayer.Title; layerDescription.Text = newLayer.Description; downloadOneImage.Checked = newLayer.DownloadOneImage; autoUpdate.Checked = newLayer.AutoUpdate; FillImageFormatsComboBox(); transparent.Checked = newLayer.IsTransparent && Wms.AbleToBeTransparent(newLayer.ImageFormat); transparentColor.Text = ColorTranslator.ToHtml(newLayer.BgColor); transparentColor.ForeColor = GetContrastColor(newLayer.BgColor); transparentColor.BackColor = newLayer.BgColor; Enabled = true; Enable(); } else { Enabled = false; supportedCrs.Items.Clear(); layerTitle.Text = string.Empty; layerDescription.Text = string.Empty; downloadOneImage.Checked = true; autoUpdate.Checked = true; imageFormats.Items.Clear(); transparent.Checked = true; transparentColor.Text = string.Empty; transparentColor.ForeColor = SystemColors.WindowText; transparentColor.BackColor = SystemColors.Control; } RefreshImageAddress(); }
public Wms Create() { var wms = new Wms(); Debug.Assert(ServiceAddress != null, "Every WMS has its source address!"); wms.ServiceAddress = ServiceAddress; wms.Title = Title; wms.Description = Description; wms.version = Version; wms.MaxWidth = MaxWidth; wms.MaxHeight = MaxHeight; Debug.Assert(systems.Count > 0, "There is no CRS in creator!"); wms.systems = systems.ToArray(); wms.crsId = SetPreferredCrs(); Debug.Assert(imageFormats.Count > 0, "There is no image format in creator!"); var imageFormatsArray = new ImageFormat[imageFormats.Count]; wms.ImageFormats = imageFormatsArray; imageFormats.Keys.CopyTo(imageFormatsArray, 0); Debug.Assert(Layer != null, "Every WMS creator must also create a root layer!"); wms.Layer = Layer.Create(wms); return(wms); }
public void Refresh(Wms newWms) { wms = newWms; if (newWms != null) { serviceAddress.Text = newWms.ServiceAddress.ToString(); serviceTitle.Text = newWms.Title; serviceDescription.Text = newWms.Description; protocolVersion.Text = newWms.Version; FillCrsComboBox(); downloadMaps.Checked = newWms.IsDownloadingEnabled; Enabled = true; } else { Enabled = false; serviceAddress.Text = string.Empty; serviceTitle.Text = string.Empty; serviceDescription.Text = string.Empty; protocolVersion.Text = string.Empty; crs.Items.Clear(); downloadMaps.Checked = true; } }
public LeafLayer(string layerName, Wms wms) : base(wms) { Debug.Assert(!string.IsNullOrEmpty(layerName), "The leaf layer must have a name!"); name = layerName; }
public BranchLayer(Wms wms) : base(wms) { // Not used }