private void SbAddClick(object sender, RoutedEventArgs e) { var l = ((FrameworkElement) sender).DataContext as StoredLayer; if (l == null) return; switch (l.Type) { case "Map Service": var ml = new ArcGISImageServiceLayer(); ml.Url = l.Id; ml.ID = l.Title; ml.Visible = true; var pts = AppStateSettings.Instance.ViewDef.FindOrCreateAcceleratedGroupLayer(l.Path); pts.ChildLayers.Add(ml); ml.Initialize(); break; // FIXME TODO: Unreachable code //break; case "Feature Service": var fl = new FeatureLayer() {}; fl.Url = l.Id + @"/0"; fl.ID = l.Title; fl.Visible = true; fl.InitializationFailed += fl_InitializationFailed; fl.Initialized += fl_Initialized; fl.UpdateCompleted += fl_UpdateCompleted; var pt = AppStateSettings.Instance.ViewDef.FindOrCreateAcceleratedGroupLayer(l.Path); pt.ChildLayers.Add(fl); fl.Initialize(); fl.Update(); break; case "wms": var wl = new WmsLayer { SupportedSpatialReferenceIDs = new[] {102100}, Visible = false }; wl.Visible = true; wl.SkipGetCapabilities = false; wl.Initialized += (st, es) => { wl.Layers = wl.LayerList.Select(k => k.Title).ToArray(); }; wl.Url = l.Id; wl.ID = l.Title; wl.Title = l.Title; var p = AppStateSettings.Instance.ViewDef.FindOrCreateGroupLayer(l.Path); p.ChildLayers.Add(wl); wl.Initialize(); break; } AppStateSettings.Instance.ViewDef.StoredLayers.Add(l); AppStateSettings.Instance.ViewDef.StoredLayers.Save(); }
private static void CreateAttributionTemplate(WmsLayer layer) { if (layer != null) { string template = string.Format(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> <TextBlock Text=""{0}"" TextWrapping=""Wrap""/></DataTemplate>" , string.Join(" ", layer.copyrightText.ToArray())); #if SILVERLIGHT _attributionTemplate = System.Windows.Markup.XamlReader.Load(template) as DataTemplate; #else using (System.IO.MemoryStream stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(template))) { _attributionTemplate = System.Windows.Markup.XamlReader.Load(stream) as DataTemplate; } #endif layer.OnPropertyChanged("AttributionTemplate"); } }
public void Add() { //WmtsLayer kml = new WmtsLayer() // { // ID = Name, // Url = // "http://134.221.210.43:8008/geoserver/gwc/service/wmts?REQUEST=getcapabilities" // }; kml = new WmsLayer() { ID = Name, Url = Location }; gl = AppState.ViewDef.FindOrCreateGroupLayer(this.Folder); //kml.Version = "1.1.0"; //kml.ServiceMode = WmtsLayer.WmtsServiceMode.KVP; kml.Layers = Layers; if (gl != null) gl.ChildLayers.Add(kml); kml.Initialize(); IsRunning = true; }
/// <summary> /// Creates the legend info from a layer info. /// </summary> /// <param name="layerInfo">The layer info.</param> /// <returns></returns> private static LayerLegendInfo CreateLegendInfo(WmsLayer.LayerInfo layerInfo) { List<LegendItemInfo> legendItemInfos = null; // If there is a legend url, create a legend item with the image if (!string.IsNullOrEmpty(layerInfo.LegendUrl)) { legendItemInfos = new List<LegendItemInfo> { new LegendItemInfo { ImageSource = new BitmapImage(new Uri(layerInfo.LegendUrl)) } }; } return new LayerLegendInfo { LayerDescription = layerInfo.Abstract, LayerName = layerInfo.Title, SubLayerID = layerInfo.SubLayerID, LayerLegendInfos = CreateLegendInfos(layerInfo.ChildLayers), MaximumScale = layerInfo.MaximumScale, MinimumScale = layerInfo.MinimumScale, LegendItemInfos = legendItemInfos }; }
private static void CreateAttributionTemplate(WmsLayer layer) { if (layer != null) { string template = string.Format(@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> <TextBlock Text=""{0}"" TextWrapping=""Wrap""/></DataTemplate>", string.Join(" ", layer.copyrightText.ToArray())); #if SILVERLIGHT _attributionTemplate = System.Windows.Markup.XamlReader.Load(template) as DataTemplate; #else using (System.IO.MemoryStream stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(template))) { _attributionTemplate = System.Windows.Markup.XamlReader.Load(stream) as DataTemplate; } #endif layer.OnPropertyChanged("AttributionTemplate"); } }
private void SetVisibleLayers(WmsLayer.LayerInfo layerInfo) { if (Layers == null) return; bool visible = false; if (Layers.Contains(layerInfo.Name)) { // the layer and all its children is visible visible = true; foreach (var child in Descendants(layerInfo.ChildLayers)) child.Visible = true; } else if (layerInfo.ChildLayers != null) { foreach (var child in layerInfo.ChildLayers) { SetVisibleLayers(child); visible |= child.Visible; // if a child is visible, all ascendants must be visible } } layerInfo.Visible = visible; }
private string CreateUrl(WmsLayer wl) { int num = (wl.SpatialReference != null) ? wl.SpatialReference.WKID : 0; string str = wl.Url; var builder = new StringBuilder(str); if (!str.Contains("?")) { builder.Append("?"); } else if (!str.EndsWith("&")) { builder.Append("&"); } builder.Append("SERVICE=WMS&REQUEST=GetMap"); builder.AppendFormat("&WIDTH={0}", 512); builder.AppendFormat("&HEIGHT={0}", 512); builder.AppendFormat("&FORMAT={0}", wl.ImageFormat); builder.AppendFormat("&LAYERS={0}", (wl.Layers == null) ? "" : string.Join(",", wl.Layers)); builder.Append("&STYLES="); builder.AppendFormat("&BGCOLOR={0}", "0xFFFFFF"); builder.AppendFormat("&TRANSPARENT={0}", "TRUE"); builder.AppendFormat("&VERSION={0}", "1.1.1"); if (((wl.SupportedSpatialReferenceIDs != null) && (((num == 0x18ed4) || (num == 0x18ee1)) || ((num == 0xf11) || (num == 0xdbf31)))) && !wl.SupportedSpatialReferenceIDs.Contains(num)) { if (wl.SupportedSpatialReferenceIDs.Contains(0xf11)) { num = 0xf11; } else if (wl.SupportedSpatialReferenceIDs.Contains(0x18ed4)) { num = 0x18ed4; } else if (wl.SupportedSpatialReferenceIDs.Contains(0x18ee1)) { num = 0x18ee1; } else if (wl.SupportedSpatialReferenceIDs.Contains(0xdbf31)) { num = 0xdbf31; } } builder.AppendFormat("&SRS=EPSG:{0}", num); string returnstring = builder.ToString(); returnstring.Replace("&", "&"); return returnstring; }
public static void ParseWmsLayers(Layer layer, WmsLayer.LayerInfo layerinfo, ref sWmsLayer parent) { var wms = new sWmsLayer { Layer = layer, Title = layerinfo.Name, LayerInfo = layerinfo, BaseLayer = parent.BaseLayer, IsTabAvailable = layer is ITabLayer, IsConfigAvailable = layer is ISettingsLayer }; parent.Children.Add(wms); if (layerinfo.ChildLayers.Count <= 0) return; foreach (var sl in layerinfo.ChildLayers) { ParseWmsLayers(layer, sl, ref wms); } }