Ejemplo n.º 1
0
 public string GetMapConfiguration(Dictionary<string, string> customNamespaces = null)
 {
     // Only return map configuration if the web map is not linked
     if (ViewerApplication.WebMapSettings.Linked != true)
     {
     MapXamlWriter mapXamlWriter = new MapXamlWriter(true);
     if (customNamespaces != null)
     {
         foreach (KeyValuePair<string, string> customNamespace in customNamespaces)
         {
             mapXamlWriter.Namespaces.Add(customNamespace.Key, customNamespace.Value);
         }
     }
         return mapXamlWriter.MapToXaml(Map);
     }
     else
     {
         return string.Empty;
     }
 }
        void onGetConfigurationCompleted(object sender, GetConfigurationCompletedEventArgs e)
        {
            if (e.Map == null)
            {
                MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Builder.Resources.Strings.ErrorRetrievingMapDocumentForSite);
                return;
            }

            mapXaml = new MapXamlWriter(true).MapToXaml(e.Map);
            btnOk.IsEnabled = true;
            BuilderApplication.Instance.HideWindow(chooseSiteControl);
        }
        public static void UpdateProxyUrl(string proxyUrl)
        {
            Map map = (MapApplication.Current != null) ? MapApplication.Current.Map : null;
            if (map == null)
                return;

            bool mapRequiresRefresh = false;
            #region Check if layers can be updated in-place
            List<Layer> layersForRefresh = new List<Layer>();
            foreach (Layer layer in map.Layers)
            {
                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                {
                    if (ProxyUrlHelper.CanChangeProxyUrl(layer))
                        layersForRefresh.Add(layer);
                    else
                    {
                        mapRequiresRefresh = true;
                        break;
                    }
                }
            }
            #endregion
            #region Set proxy url if layers can be updated
            if (!mapRequiresRefresh)
            {
                foreach (Layer layer in layersForRefresh)
                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
            }
            #endregion
            #region Else, serialize/deserialize map, remove and re-add layers
            else
            {
                MapXamlWriter writer = new MapXamlWriter(true);
                try
                {
                    string mapXaml = writer.MapToXaml(map);

                    if (!string.IsNullOrEmpty(mapXaml))
                    {
                        Map newMap = System.Windows.Markup.XamlReader.Load(mapXaml) as Map;
                        if (newMap != null && newMap.Layers.Count == map.Layers.Count)
                        {
                            map.Layers.Clear();
                            map.Extent = newMap.Extent;
                            List<Layer> layers = new List<Layer>();
                            foreach (Layer layer in newMap.Layers)
                            {
                                if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsesProxy(layer))
                                    SecureServicesHelper.SetProxyUrl(layer, proxyUrl);
                                layers.Add(layer);
                            }
                            newMap.Layers.Clear();
                            foreach (Layer layer in layers)
                                map.Layers.Add(layer);
                        }
                    }
                }
                catch(Exception ex)
                {
                    Logger.Instance.LogError(ex);
                    MessageBoxDialog.Show(ESRI.ArcGIS.Mapping.Controls.Resources.Strings.ErrorChangingProxies);
                }
            }
            #endregion
        }
 public static string GetMapXaml(MapEventArgs e)
 {
     MapXamlWriter writer = new MapXamlWriter(true);
     return writer.MapToXaml(e.Map);
 }