예제 #1
0
        void imageServer_InitializationFailed(object sender, EventArgs e)
        {
            ArcGISImageServiceLayer image = sender as ArcGISImageServiceLayer;

            if (image != null)
            {
                if (image.ProxyURL == null)
                {
                    _status = "ImageServer FAILED using Proxy";
                    ArcGISImageServiceLayer newImage = new ArcGISImageServiceLayer();
                    newImage.InitializationFailed += new EventHandler <EventArgs>(imageServer_InitializationFailed);
                    newImage.Url = image.Url;
                    newImage.ID  = image.ID;

                    //newImage.ProxyURL = MyProxy;

                    newImage.ProxyURL = _proxyUrl;

                    _map.Layers.Remove(image);
                    _map.Layers.Add(image);
                }
                else
                {
                    MessageBox.Show("Cannot access that service");
                }
            }
        }
예제 #2
0
        private void OnMakeColorMapClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                ArcGISImageServiceLayer lyr           = map1.Layers[0] as ArcGISImageServiceLayer;
                RenderingRule           renderingRule = new RenderingRule();
                // Note: The .RasterFunctonName must use the text string 'Colormap'.
                renderingRule.RasterFunctionName = "Colormap";

                // Note: the .VariableName must use the text string 'Raster'.
                renderingRule.VariableName = "Raster";

                // Define a Dictionary object with String/Object pairs. The Strings that are used for the keys as
                // Dictionary entries will need to have exact text strings depending on what raster function is being used.
                Dictionary <string, object> rasterParams = new Dictionary <string, object>();

                // Example #1: Create a random set of colors for the color map.
                // Note: The a key of 'ColormapName' takes the string 'Random'.

                rasterParams.Add("ColormapName", RasterParamCombo.SelectionBoxItem.ToString());
                // Add the rasterParms Dictionary as the RenderingRule's RasterFunctionArguments.
                renderingRule.RasterFunctionArguments = rasterParams;
                // Apply the user defined myRenderingRule to the ArcGISImageServiceLayer's .RenderingRule
                lyr.RenderingRule = renderingRule;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error making color map: " + ex.Message);
            }
        }
예제 #3
0
        protected override void WriteAttributes(Layer layer)
        {
            base.WriteAttributes(layer);
            ArcGISImageServiceLayer imageServiceLayer = layer as ArcGISImageServiceLayer;

            if (imageServiceLayer != null)
            {
                WriteAttribute("Url", imageServiceLayer.Url);
                if (!LayerExtensions.GetUsesProxy(layer))
                {
                    if (!string.IsNullOrEmpty(imageServiceLayer.ProxyURL))
                    {
                        WriteAttribute("ProxyURL", imageServiceLayer.ProxyURL);
                    }
                    if (!string.IsNullOrEmpty(imageServiceLayer.Token))
                    {
                        WriteAttribute("Token", imageServiceLayer.Token);
                    }
                }

                WriteAttribute("ImageFormat", imageServiceLayer.ImageFormat.ToString());

                if (imageServiceLayer.BandIds != null && imageServiceLayer.BandIds.Length > 0)
                {
                    WriteAttribute("BandIds", string.Join(",", imageServiceLayer.BandIds));
                }
            }
        }
예제 #4
0
        // Initializes the Layer property
        private void initializeLayer()
        {
            Layer layer = null;

            // Create the layer based on the type of service encapsulated by the search result
            if (Service is MapService)
            {
                MapService mapService = (MapService)Service;
                if (mapService.IsTiled &&
                    mapService.SpatialReference.WKID == MapApplication.Current.Map.SpatialReference.WKID)
                {
                    layer = new ArcGISTiledMapServiceLayer()
                    {
                        Url = Service.Url, ProxyURL = ProxyUrl
                    }
                }
                ;
                else
                {
                    layer = new ArcGISDynamicMapServiceLayer()
                    {
                        Url = Service.Url, ProxyURL = ProxyUrl
                    }
                };
            }
            else if (Service is ImageService)
            {
                layer = new ArcGISImageServiceLayer()
                {
                    Url = Service.Url, ProxyURL = ProxyUrl
                };
            }
            else if (Service is FeatureLayerService || (Service is FeatureService && ((FeatureService)Service).Layers.Count() == 1))
            {
                string url = Service is FeatureService?string.Format("{0}/0", Service.Url) : Service.Url;

                layer = new FeatureLayer()
                {
                    Url       = url,
                    ProxyUrl  = ProxyUrl,
                    OutFields = new OutFields()
                    {
                        "*"
                    }
                };
            }

            // Initialize the layer's ID and display name
            if (layer != null)
            {
                string id   = Guid.NewGuid().ToString("N");
                string name = propertyExists("Title") ? Result.Title : id;

                layer.ID = id;
                MapApplication.SetLayerName(layer, name);
            }
            Layer = layer;
        }
예제 #5
0
        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 void RasterFunctionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     ArcGISImageServiceLayer imageLayer = MyMap.Layers["MyImageLayer"] as ArcGISImageServiceLayer;
     var rasterFunction = (sender as ComboBox).SelectedItem as RasterFunctionInfo;
     if (rasterFunction != null)
     {
         RenderingRule renderingRule = new RenderingRule() { RasterFunctionName = rasterFunction.Name };
         imageLayer.RenderingRule = renderingRule;
         imageLayer.Refresh();
     }
 }
        // Zooms to the image layer and starts accepting user points
        private async void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
        {
            if (e.Layer is ArcGISImageServiceLayer)
            {
                if (e.Layer.FullExtent != null)
                    await MyMapView.SetViewAsync(e.Layer.FullExtent);

				_imageLayer = (ArcGISImageServiceLayer)e.Layer;
                await AcceptClassPointsAsync();
            }
        }
예제 #8
0
 private void MyMapView_LayerLoaded(object sender, Esri.ArcGISRuntime.Controls.LayerLoadedEventArgs e)
 {
     if (e.Layer.ID == "ImageLayer")
     {
         ArcGISImageServiceLayer imageLayer = e.Layer as ArcGISImageServiceLayer;
         if (e.LoadError == null)
         {
             RasterFunctionsComboBox.ItemsSource   = imageLayer.ServiceInfo.RasterFunctionInfos;
             RasterFunctionsComboBox.SelectedIndex = 0;
         }
     }
 }
예제 #9
0
        // Zooms to the image layer and starts accepting user points
        private async void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
        {
            if (e.Layer is ArcGISImageServiceLayer)
            {
                if (e.Layer.FullExtent != null)
                {
                    await MyMapView.SetViewAsync(e.Layer.FullExtent);
                }

                _imageLayer = (ArcGISImageServiceLayer)e.Layer;
                await AcceptClassPointsAsync();
            }
        }
예제 #10
0
 private void OnApplyRenderingRuleClicked(object sender, RoutedEventArgs e)
 {
     try
     {
         ArcGISImageServiceLayer lyr           = map1.Layers[0] as ArcGISImageServiceLayer;
         RenderingRule           renderingRule = new RenderingRule();
         renderingRule.RasterFunctionName = "Aspect";
         lyr.RenderingRule = renderingRule;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error applying rendering rule: " + ex.Message);
     }
 }
 private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
 {
     try
     {
         ArcGISImageServiceLayer imageLayer = MyMap.Layers["ImageServiceLayer"] as ArcGISImageServiceLayer;
         MosaicRule mosaicRule = new MosaicRule();
         mosaicRule.MosaicMethod = "esriMosaicViewpoint";
         mosaicRule.Viewpoint    = e.MapPoint;
         imageLayer.MosaicRule   = mosaicRule;
         imageLayer.Refresh();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #12
0
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ArcGISImageServiceLayer     imageLayer    = MyMap.Layers["ImageServiceLayer"] as ArcGISImageServiceLayer;
                RenderingRule               renderingRule = new RenderingRule();
                Dictionary <string, object> rasterParams  = new Dictionary <string, object>();

                if (SRRadioButton.IsChecked.Value)
                {
                    renderingRule.RasterFunctionName = "ShadedRelief";
                    renderingRule.VariableName       = "Raster";

                    rasterParams.Add("Azimuth", string.IsNullOrEmpty(AzimuthTextBox.Text) ? 0 : double.Parse(AzimuthTextBox.Text));
                    rasterParams.Add("Altitude", string.IsNullOrEmpty(AltitudeTextBox.Text) ? 0 : double.Parse(AltitudeTextBox.Text));
                    rasterParams.Add("ZFactor", string.IsNullOrEmpty(ZFactorTextBox.Text) ? 0 : double.Parse(ZFactorTextBox.Text));

                    if (ColormapCheckBox.IsChecked.Value)
                    {
                        rasterParams.Add("Colormap", CreateColorMap());
                    }
                    else
                    {
                        renderingRule.RasterFunctionName = "Hillshade";
                        renderingRule.VariableName       = "DEM";
                    }
                    renderingRule.RasterFunctionArguments = rasterParams;
                }
                else
                {
                    renderingRule.RasterFunctionName = "Slope";
                    renderingRule.VariableName       = "DEM";

                    rasterParams.Add("ZFactor", string.IsNullOrEmpty(ZFactorTextBox.Text) ? 0 : double.Parse(ZFactorTextBox.Text));

                    renderingRule.RasterFunctionArguments = rasterParams;
                }

                imageLayer.RenderingRule = renderingRule;
                imageLayer.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #13
0
        void imageServer_InitializationFailed(object sender, EventArgs e)
        {
            ArcGISImageServiceLayer image = sender as ArcGISImageServiceLayer;
            if (image != null)
            {
                if (image.ProxyURL == null)
                {
                    _status = "ImageServer FAILED using Proxy";
                    ArcGISImageServiceLayer newImage = new ArcGISImageServiceLayer();
                    newImage.InitializationFailed += new EventHandler<EventArgs>(imageServer_InitializationFailed);
                    newImage.Url = image.Url;
                    newImage.ID = image.ID;

                    //newImage.ProxyURL = MyProxy;

                    newImage.ProxyURL = _proxyUrl;

                    _map.Layers.Remove(image);
                    _map.Layers.Add(image);
                }
                else
                    MessageBox.Show("Cannot access that service");
            }
        }
        // Initializes the Layer property
        private void initializeLayer()
        {
            Layer layer = null;

            // Create the layer based on the type of service encapsulated by the search result
            if (Service is MapService)
            {
                MapService mapService = (MapService)Service;
                if (mapService.IsTiled &&
                mapService.SpatialReference.WKID == MapApplication.Current.Map.SpatialReference.WKID)
                    layer = new ArcGISTiledMapServiceLayer() { Url = Service.Url, ProxyURL = ProxyUrl };
                else
                    layer = new ArcGISDynamicMapServiceLayer() { Url = Service.Url, ProxyURL = ProxyUrl };
            }
            else if (Service is ImageService)
            {
                layer = new ArcGISImageServiceLayer() { Url = Service.Url, ProxyURL = ProxyUrl };
            }
            else if (Service is FeatureLayerService || (Service is FeatureService && ((FeatureService)Service).Layers.Count() == 1))
            {
                string url = Service is FeatureService ? string.Format("{0}/0", Service.Url) : Service.Url;
                layer = new FeatureLayer() 
                { 
                    Url = url, 
                    ProxyUrl = ProxyUrl,
                    OutFields = new OutFields() { "*" }
                };
            }

            // Initialize the layer's ID and display name
            if (layer != null)
            {
                string id = Guid.NewGuid().ToString("N");
                string name = propertyExists("Title") ? Result.Title : id;

                layer.ID = id;
                MapApplication.SetLayerName(layer, name);
            }
            Layer = layer;
        }
        public override void Execute(object parameter)
        {
            FeatureLayer fl = Layer as FeatureLayer;

            if (fl != null)
            {
                navigateToUrl(Utility.CreateUriWithProxy(fl.ProxyUrl, fl.Url));
                return;
            }

            ArcGISDynamicMapServiceLayer dynLayer = Layer as ArcGISDynamicMapServiceLayer;

            if (dynLayer != null)
            {
                navigateToUrl(Utility.CreateUriWithProxy(dynLayer.ProxyURL, dynLayer.Url));
                return;
            }

            ArcGISImageServiceLayer imageLayer = Layer as ArcGISImageServiceLayer;

            if (imageLayer != null)
            {
                navigateToUrl(Utility.CreateUriWithProxy(imageLayer.ProxyURL, imageLayer.Url));
                return;
            }

            ArcGISTiledMapServiceLayer tiledLayer = Layer as ArcGISTiledMapServiceLayer;

            if (tiledLayer != null)
            {
                navigateToUrl(Utility.CreateUriWithProxy(tiledLayer.ProxyURL, tiledLayer.Url));
                return;
            }

            GeoRssLayer geoRssLayer = Layer as GeoRssLayer;

            if (geoRssLayer != null)
            {
                if (geoRssLayer.Source != null)
                {
                    navigateToUrl(geoRssLayer.Source.AbsoluteUri);
                }
                return;
            }

            WmsLayer wmsLayer = Layer as WmsLayer;

            if (wmsLayer != null)
            {
                string url = wmsLayer.Url;
                if (!string.IsNullOrEmpty(url))
                {
                    if (!url.Contains("?"))
                    {
                        url += "?";
                    }
                    else
                    {
                        url += "&";
                    }
                    if (url.IndexOf("request=GetCapabilities", StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        url += "request=GetCapabilities";
                    }
                    if (!string.IsNullOrEmpty(wmsLayer.Version) && url.IndexOf("version=", StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        url += "&version=" + wmsLayer.Version;
                    }
                    navigateToUrl(Utility.CreateUriWithProxy(wmsLayer.ProxyUrl, url));
                }
                return;
            }

            OpenStreetMapLayer osmLayer = Layer as OpenStreetMapLayer;

            if (osmLayer != null)
            {
                navigateToUrl("http://www.openstreetmap.org");
                return;
            }

            ESRI.ArcGIS.Client.Bing.TileLayer bingLayer = Layer as ESRI.ArcGIS.Client.Bing.TileLayer;
            if (bingLayer != null)
            {
                navigateToUrl("http://www.bing.com/maps/");
                return;
            }

            ICustomGraphicsLayer customGraphicsLayer = Layer as ICustomGraphicsLayer;

            if (customGraphicsLayer != null && customGraphicsLayer.SupportsNavigateToServiceDetailsUrl())
            {
                Uri uri = customGraphicsLayer.GetServiceDetailsUrl();
                if (uri != null)
                {
                    navigateToUrl(uri.AbsoluteUri);
                }
                return;
            }
        }
        /// <summary>
        /// Determines the map units for the map
        /// </summary>
        /// <param name="map">The map to find map units for</param>
        /// <param name="onComplete">The method to invoke once map units have been retrieved</param>
        /// <param name="onFailed">The method to invoke when map unit retrieval fails</param>
        public static void GetMapUnitsAsync(this Map Map, Action <LengthUnits> onComplete,
                                            Action onFailed = null)
        {
            if (Map != null)
            {
                Layer layer = Map.Layers.FirstOrDefault();
                if (layer != null)
                {
                    TileLayer tiledLayer = layer as TileLayer;
                    if (tiledLayer != null)
                    {
                        // Bing is web mercator
                        onComplete(LengthUnits.UnitsMeters);
                    }
                    else
                    {
                        OpenStreetMapLayer osmLayer = layer as OpenStreetMapLayer;
                        if (osmLayer != null)
                        {
                            // Open Streem map is web mercator
                            onComplete(LengthUnits.UnitsMeters);
                        }
                        else
                        {
                            // ArcGIS Server Base Map
                            string units    = null;
                            string layerUrl = null;
                            ArcGISTiledMapServiceLayer agsTiledlayer = layer as ArcGISTiledMapServiceLayer;
                            if (agsTiledlayer != null)
                            {
                                units    = agsTiledlayer.Units;
                                layerUrl = agsTiledlayer.Url;
                            }
                            else
                            {
                                ArcGISDynamicMapServiceLayer agsDynamicLayer = layer as ArcGISDynamicMapServiceLayer;
                                if (agsDynamicLayer != null)
                                {
                                    units    = agsDynamicLayer.Units;
                                    layerUrl = agsDynamicLayer.Url;
                                }
                                else
                                {
                                    ArcGISImageServiceLayer agsImageLayer = layer as ArcGISImageServiceLayer;
                                    if (agsImageLayer != null)
                                    {
                                        layerUrl = agsImageLayer.Url;
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(units))
                            {
                                units = units.Replace("esri", "Units"); // replace esri prefix
                                if (Enum.IsDefined(typeof(LengthUnits), units))
                                {
                                    onComplete((LengthUnits)Enum.Parse(typeof(LengthUnits), units, true));
                                }
                                else if (onFailed != null)
                                {
                                    onFailed();
                                }
                            }
                            else if (!string.IsNullOrEmpty(layerUrl))
                            {
                                ArcGISService.GetServiceInfoAsync(layerUrl, null, (o, e) =>
                                {
                                    if (e.Service != null && !string.IsNullOrEmpty(e.Service.Units))
                                    {
                                        string serviceUnits = e.Service.Units;
                                        serviceUnits        = serviceUnits.Replace("esri", "Units"); // replace esri prefix
                                        if (Enum.IsDefined(typeof(LengthUnits), serviceUnits))
                                        {
                                            onComplete((LengthUnits)Enum.Parse(typeof(LengthUnits), serviceUnits, true));
                                        }
                                        else if (onFailed != null)
                                        {
                                            onFailed();
                                        }
                                    }
                                });
                                return;
                            }
                        }
                    }
                }
            }
        }
예제 #17
0
        public void InitMap()
        {
            if (_behaviors != null)
            {
                _behaviors.Clear();
            }
            MapObj.Layers.Clear();
            MapView.LayerLoaded -= MapView_LayerLoaded;
            MapView.LayerLoaded += MapView_LayerLoaded;

            LogUtil.Info(typeof(Map), "初始化地图...");

            MapView.MaxScale = ConfigUtil.MaxScale;
            MapView.MinScale = ConfigUtil.MinScale;

            var lo = ConfigUtil.TiledLayer;

            if (lo != null)
            {
                var tiledLayer = new ArcGISTiledMapServiceLayer(lo.Uri)
                {
                    ID          = lo.Id,
                    DisplayName = lo.Name
                };
                if (lo.Token != null)
                {
                    tiledLayer.Token = lo.Token.Replace("\r\n", "");
                    //tiledLayer.Token = "XDjutneIavm-1NSbIhZFhq3mCcseAViwRgf48LVcEbk.";
                }
                MapObj.Layers.Add(tiledLayer);
            }

            lo = ConfigUtil.ImageLayer;
            if (lo != null)
            {
                var imageLayer = new ArcGISImageServiceLayer(lo.Uri)
                {
                    ID          = lo.Id,
                    DisplayName = lo.Name
                };
                MapObj.Layers.Add(imageLayer);
            }

            var los = ConfigUtil.DynamicLayer;

            if (los != null)
            {
                foreach (var l in los)
                {
                    var dynamicLayer = new ArcGISDynamicMapServiceLayer(l.Uri)
                    {
                        ID = l.Id
                    };
                    if (l.Token != null)
                    {
                        dynamicLayer.Token = l.Token.Replace("\r\n", "");;
                    }

                    dynamicLayer.DisplayName = l.Name;
                    MapObj.Layers.Add(dynamicLayer);
                }
            }

            _drawingLayer = new OverlayLayer(MapCtrl)
            {
                DisplayName     = "用户绘图",
                SceneProperties = { SurfacePlacement = SurfacePlacement.Absolute }
            };
            MapObj.Layers.Add(_drawingLayer);

            _highLightLayer = new OverlayLayer(MapCtrl)
            {
                DisplayName     = "查询高亮",
                SceneProperties = { SurfacePlacement = SurfacePlacement.Absolute }
            };
            MapObj.Layers.Add(_highLightLayer);


            MapView.SetViewAsync(ConfigUtil.InitCenter, ConfigUtil.InitScale, new TimeSpan(10000));

            LogUtil.Info(typeof(Map), "地图初始化完成");
        }
예제 #18
0
        public override void CreateLayerAsync(Resource resource, SpatialReference mapSpatialReference, object userState)
        {
            if (resource == null)
            {
                return;
            }

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (resource.ResourceType)
            {
            case ResourceType.MapServer:
            case ResourceType.FeatureServer:
            {
                string url = resource.Url;
                if (resource.ResourceType == ResourceType.FeatureServer)
                {
                    int i = url.LastIndexOf(string.Format("/{0}", ResourceType.FeatureServer.ToString()));
                    if (i >= 0)
                    {
                        url = url.Remove(i);
                        url = string.Format("{0}/{1}", url, ResourceType.MapServer.ToString());
                    }
                }

                _service = ServiceFactory.CreateService(ResourceType.MapServer, url, resource.ProxyUrl);
                if (_service != null)
                {
                    _service.ServiceDetailsDownloadFailed += (o, e) =>
                    {
                        OnCreateLayerFailed(e);
                    };
                    _service.ServiceDetailsDownloadCompleted += (o, e) =>
                    {
                        MapService mapService = o as MapService;
                        if (mapService.ServiceInfo == null)
                        {
                            OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveMapServiceDetails), e.UserState));
                            return;
                        }

                        if (mapService.ServiceInfo.TileInfo != null && mapService.ServiceInfo.SingleFusedMapCache)
                        {
                            #region Create tiled layer
                            if (mapSpatialReference != null && !mapSpatialReference.Equals(mapService.ServiceInfo.SpatialReference))
                            {
                                OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionCachedMapServiceSpatialReferenceDoesNotMatch), e.UserState));
                                return;
                            }
                            layer = new ArcGISTiledMapServiceLayer()
                            {
                                Url      = url,
                                ProxyURL = getCleanProxyUrl(mapService.ProxyUrl),
                            };

                            if (mapService.ServiceInfo.TileInfo.LODs != null)
                            {
                                double maxResolution = 0;
                                double minResolution = 0;
                                foreach (LODInfo lod in mapService.ServiceInfo.TileInfo.LODs)
                                {
                                    if (lod.Resolution > maxResolution)
                                    {
                                        maxResolution = lod.Resolution;
                                    }
                                    if (minResolution <= 0 || minResolution > lod.Resolution)
                                    {
                                        minResolution = lod.Resolution;
                                    }
                                }
                                if (maxResolution > 0)
                                {
                                    layer.MaximumResolution = maxResolution * 4;
                                }
                                if (minResolution > 0)
                                {
                                    layer.MinimumResolution = minResolution / 4;
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region create dynamic layer
                            layer = new ArcGISDynamicMapServiceLayer()
                            {
                                Url      = url,
                                ProxyURL = getCleanProxyUrl(mapService.ProxyUrl),
                            };
                            #endregion
                        }

                        //Set layer's attached properties
                        if (layer != null)
                        {
                            layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                            layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, url);
                            if (!string.IsNullOrEmpty(resource.ProxyUrl))
                            {
                                Core.LayerExtensions.SetUsesProxy(layer, true);
                            }
                            layer.ID = Guid.NewGuid().ToString("N");
                        }

                        OnCreateLayerCompleted(new CreateLayerCompletedEventArgs()
                            {
                                Layer = layer, UserState = e.UserState
                            });
                    };

                    _service.GetServiceDetails(null);
                }
            } break;

            case ResourceType.ImageServer:
            {
                layer = new ArcGISImageServiceLayer()
                {
                    Url      = resource.Url,
                    ProxyURL = getCleanProxyUrl(resource.ProxyUrl),
                    ID       = Guid.NewGuid().ToString("N"),
                };

                //Set layer's attached properties
                layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url);
                if (!string.IsNullOrEmpty(resource.ProxyUrl))
                {
                    Core.LayerExtensions.SetUsesProxy(layer, true);
                }

                // Need to declare handler separate from lambda expression to avoid erroneous
                // "use of unassigned variable" build error
                EventHandler <EventArgs> initialized = null;

                // Need to populate the layer's metadata to handle initialization of image format
                // and band IDs
                initialized = (o, e) =>
                {
                    layer.Initialized -= initialized;
                    ArcGISImageServiceLayer imageLayer = (ArcGISImageServiceLayer)layer;
                    if (imageLayer.Version < 10)
                    {
                        // Pre v10, band IDs must be specified explicitly.  But no more than
                        // 3 can be used.  Just take up to the first 3 by default.
                        List <int> bandIDs = new List <int>();
                        for (int i = 0; i < imageLayer.BandCount; i++)
                        {
                            bandIDs.Add(i);
                            if (i == 2)
                            {
                                break;
                            }
                        }

                        imageLayer.BandIds = bandIDs.ToArray();

                        // Use png format to support transparency
                        imageLayer.ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.PNG8;
                    }
                    else
                    {
                        // At v10 and later, band IDs do not need to be specified, and jpg/png
                        // format introduces some intelligence about which format is best
                        imageLayer.ImageFormat =
                            ArcGISImageServiceLayer.ImageServiceImageFormat.JPGPNG;
                    }

                    OnCreateLayerCompleted(new CreateLayerCompletedEventArgs()
                        {
                            Layer = layer, UserState = userState
                        });
                };

                EventHandler <EventArgs> initFailed = null;
                initFailed = (o, e) =>
                {
                    layer.InitializationFailed -= initFailed;
                    OnCreateLayerCompleted(new CreateLayerCompletedEventArgs()
                        {
                            Layer = layer, UserState = userState
                        });
                };

                layer.Initialized          += initialized;
                layer.InitializationFailed += initFailed;
                layer.Initialize();
            }
            break;

            case ResourceType.Layer:
            case ResourceType.EditableLayer:
            {
                featureLayer = new Layer(resource.Url, resource.ProxyUrl);
                featureLayer.GetLayerDetailsFailed += (o, e) =>
                {
                    OnCreateLayerFailed(e);
                };
                featureLayer.GetLayerDetailsCompleted += (o, e) =>
                {
                    if (e.LayerDetails == null)
                    {
                        OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveLayerDetails), e.UserState));
                        return;
                    }
                    if (Utility.RasterLayer.Equals(e.LayerDetails.Type))
                    {
                        OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionRasterLayersNotSupported), e.UserState));
                        return;
                    }
                    else if (Utility.ImageServerLayer.Equals(e.LayerDetails.Type))
                    {
                        OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionImageServerLayersNotSupported), e.UserState));
                        return;
                    }

                    if (Utility.CapabilitiesSupportsQuery(e.LayerDetails.Capabilities) == false)
                    {
                        OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionLayerDoesNotSupportQuery), e.UserState));
                        return;
                    }

                    GeometryType GeometryType = GeometryType.Unknown;
                    switch (e.LayerDetails.GeometryType)
                    {
                    case "esriGeometryPoint":
                        GeometryType = GeometryType.Point;
                        break;

                    case "esriGeometryMultipoint":
                        GeometryType = GeometryType.MultiPoint;
                        break;

                    case "esriGeometryPolyline":
                        GeometryType = GeometryType.Polyline;
                        break;

                    case "esriGeometryPolygon":
                        GeometryType = GeometryType.Polygon;
                        break;
                    }
                    FeatureLayer newFeatureLayer = new FeatureLayer()
                    {
                        Url      = featureLayer.Uri,
                        ProxyUrl = getCleanProxyUrl(featureLayer.ProxyUrl),
                        ID       = Guid.NewGuid().ToString("N"),
                        Mode     = FeatureLayer.QueryMode.OnDemand,
                        Renderer = new ESRI.ArcGIS.Mapping.Core.Symbols.HiddenRenderer()
                    };
                    newFeatureLayer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                    newFeatureLayer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url);
                    newFeatureLayer.SetValue(Core.LayerExtensions.GeometryTypeProperty, GeometryType);
                    if (!string.IsNullOrEmpty(resource.ProxyUrl))
                    {
                        Core.LayerExtensions.SetUsesProxy(newFeatureLayer, true);
                    }
                    if (e.LayerDetails.Fields != null)
                    {
                        Collection <ESRI.ArcGIS.Mapping.Core.FieldInfo> fields = FieldInfosFromFields(e.LayerDetails.Fields);
                        newFeatureLayer.SetValue(Core.LayerExtensions.FieldsProperty, fields);
                        Core.LayerExtensions.SetDisplayField(newFeatureLayer, e.LayerDetails.DisplayField);
                    }
                    newFeatureLayer.OutFields.Add("*");         // Get all fields at configuration time
                    OnCreateLayerCompleted(new CreateLayerCompletedEventArgs()
                        {
                            Layer = newFeatureLayer, UserState = e.UserState, GeometryType = GeometryType
                        });
                };
                featureLayer.GetLayerDetails(userState);
            } break;

            default:
                throw new Exception(string.Format(Resources.Strings.ExceptionCannotCreateLayerForResourceType, resource.ResourceType.ToString()));
            }
        }
예제 #19
0
 /// <summary>
 /// Determines the map units for the map
 /// </summary>
 /// <param name="map">The map to find map units for</param>
 /// <param name="callback">The method to invoke once map units have been retrieved</param>
 /// <param name="failedCallback">The method to invoke when map unit retrieval fails</param>
 public static void GetMapUnitsAsync(this Map Map, Action <MapUnit> callback,
                                     Action <object, ExceptionEventArgs> failedCallback = null)
 {
     if (Map != null)
     {
         Layer layer = Map.Layers.FirstOrDefault();
         if (layer != null)
         {
             ESRI.ArcGIS.Client.Bing.TileLayer tiledLayer = layer as ESRI.ArcGIS.Client.Bing.TileLayer;
             if (tiledLayer != null)
             {
                 // Bing is web mercator
                 callback(Core.DataSources.MapUnit.Meters);
             }
             else
             {
                 ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer osmLayer = layer as ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer;
                 if (osmLayer != null)
                 {
                     // Open Streem map is web mercator
                     callback(Core.DataSources.MapUnit.Meters);
                 }
                 else
                 {
                     // ArcGIS Server Base Map
                     string layerUrl = null;
                     ArcGISTiledMapServiceLayer agsTiledlayer = layer as ArcGISTiledMapServiceLayer;
                     if (agsTiledlayer != null)
                     {
                         layerUrl = agsTiledlayer.Url;
                     }
                     else
                     {
                         ArcGISDynamicMapServiceLayer agsDynamicLayer = layer as ArcGISDynamicMapServiceLayer;
                         if (agsDynamicLayer != null)
                         {
                             layerUrl = agsDynamicLayer.Url;
                         }
                         else
                         {
                             ArcGISImageServiceLayer agsImageLayer = layer as ArcGISImageServiceLayer;
                             if (agsImageLayer != null)
                             {
                                 layerUrl = agsImageLayer.Url;
                             }
                         }
                     }
                     if (!string.IsNullOrWhiteSpace(layerUrl))
                     {
                         DataSourceProvider agsDataSource = new DataSourceProvider();
                         IBaseMapDataSource dataSource    = agsDataSource.CreateDataSourceForBaseMapType(BaseMapType.ArcGISServer) as IBaseMapDataSource;
                         dataSource.GetMapServiceMetaDataCompleted += (o, args) =>
                         {
                             callback(args.MapUnit);
                         };
                         dataSource.GetMapServiceMetaDataFailed += (o, args) =>
                         {
                             if (failedCallback != null)
                             {
                                 failedCallback(Map, args);
                             }
                         };
                         dataSource.GetMapServiceMetaDataAsync(layerUrl, null);
                         return;
                     }
                 }
             }
         }
     }
 }
예제 #20
0
        /// <summary>
        /// Create ArcGIS Server Map Service Layer
        /// </summary>
        private Layer CreateArcGISMapLayer(ArcGISMapLayer layerConfig, double opacity)
        {
            Layer layer = null;

            if (layerConfig.ServiceType == ArcGISServiceType.Cached)
            {
                ArcGISTiledMapServiceLayer cachedLayer = new ArcGISTiledMapServiceLayer()
                {
                    Url      = layerConfig.RESTURL,
                    Visible  = layerConfig.VisibleInitial,
                    ProxyURL = layerConfig.ProxyURL,
                    Token    = (layerConfig.Token == null) ? "" : layerConfig.Token
                };

                layer = cachedLayer;
            }
            else if (layerConfig.ServiceType == ArcGISServiceType.Image)
            {
                ArcGISImageServiceLayer imageLayer = new ArcGISImageServiceLayer()
                {
                    Url      = layerConfig.RESTURL,
                    Visible  = layerConfig.VisibleInitial,
                    ProxyURL = layerConfig.ProxyURL,
                    Token    = (layerConfig.Token == null) ? "" : layerConfig.Token
                };

                layer = imageLayer;
            }
            else if (layerConfig.ServiceType == ArcGISServiceType.Dynamic)
            {
                ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer()
                {
                    Url      = layerConfig.RESTURL,
                    Visible  = layerConfig.VisibleInitial,
                    ProxyURL = layerConfig.ProxyURL,
                    Token    = (layerConfig.Token == null) ? "" : layerConfig.Token
                };

                layer = dynamicLayer;
            }
            else if (layerConfig.ServiceType == ArcGISServiceType.Feature)
            {
                FeatureLayer featureLayer = new FeatureLayer()
                {
                    Url      = layerConfig.RESTURL,
                    Visible  = layerConfig.VisibleInitial,
                    ProxyUrl = layerConfig.ProxyURL,
                    Token    = (layerConfig.Token == null) ? "" : layerConfig.Token
                };

                layer = featureLayer;
            }

            if (layer != null)
            {
                layer.ID                    = layerConfig.ID;
                layer.Opacity               = opacity;
                layer.Initialized          += new EventHandler <EventArgs>(MapLayer_Initialized);
                layer.InitializationFailed += new EventHandler <EventArgs>(MapLayer_InitializationFailed);
                myMap.Layers.Add(layer);
            }

            return(layer);
        }
예제 #21
0
        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ArcGISImageServiceLayer imageLayer    = MyMapView.Map.Layers["ImageServiceLayer"] as ArcGISImageServiceLayer;
                RenderingRule           renderingRule = new RenderingRule();
                renderingRule.VariableName = "Raster";

                Dictionary <string, object> rasterParams = new Dictionary <string, object>();

                string[] strArray = BandIDsTextBox.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (strArray.Length == 1 || strArray.Length == 2 || strArray.Length > 3)
                {
                    ValidBandIdsTextBlock.Visibility = Visibility.Visible;
                    return;
                }
                else
                {
                    ValidBandIdsTextBlock.Visibility = Visibility.Collapsed;
                }

                renderingRule.RasterFunctionName = "Stretch";
                renderingRule.VariableName       = "Raster";

                int stretchType = 0;
                if (StandardDevCheckBox.IsChecked.Value)
                {
                    stretchType = 3;
                }
                else if (HistogramCheckBox.IsChecked.Value)
                {
                    stretchType = 4;
                }
                else if (MinMaxCheckBox.IsChecked.Value)
                {
                    stretchType = 5;
                }

                rasterParams.Add("StretchType", stretchType);
                rasterParams.Add("NumberOfStandardDeviations",
                                 string.IsNullOrEmpty(StnDevTextBox.Text) ? 1 : double.Parse(StnDevTextBox.Text));

                double[][] statistics = new double[3][] {
                    new double[4] {
                        0.2, 222.46, 99.35, 1.64
                    },
                    new double[4] {
                        5.56, 100.345, 45.4, 3.96
                    },
                    new double[4] {
                        0, 352.37, 172.284, 2
                    }
                };
                rasterParams.Add("Statistics", statistics);

                double[] gamma = new double[] { 1.25, 2, 3.95 };
                rasterParams.Add("Gamma", gamma);


                int[] numArray = new int[strArray.Length];
                for (int i = 0; i < strArray.Length; i++)
                {
                    numArray[i] = int.Parse(strArray[i]);
                }

                imageLayer.BandIds = numArray.Length < 1 ? null : numArray;


                renderingRule.RasterFunctionArguments = rasterParams;
                imageLayer.RenderingRule = renderingRule;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        private void RefreshLayer(Layer layer, EventHandler refreshCompletedHander, EventHandler <TaskFailedEventArgs> refreshFailedHandler)
        {
            _isRefreshing = true;
            FeatureLayer featureLayer = layer as FeatureLayer;

            if (featureLayer != null && !string.IsNullOrEmpty(featureLayer.Url))
            {
                // temporarly unhook the AttributeDisplay's layer while we refresh feature layer
                if (View.Instance != null && View.Instance.AttributeDisplay != null && View.Instance.AttributeDisplay.FeatureDataGrid != null)
                {
                    ToggleTableCommand.SetTableVisibility(Visibility.Collapsed);

                    // Set FeatureDataGrid layer to null so that we don't incur the overhead
                    // of all the UpdateItemSource calls as the AttributeTable Graphics layer is
                    // being set to null.
                    View.Instance.AttributeDisplay.FeatureDataGrid.GraphicsLayer = null;
                    // Set the FilterSource to null to prevent potential GraphicsLayer reference exceptions
                    View.Instance.AttributeDisplay.FeatureDataGrid.FilterSource = null;
                    // Now set the AttributeDisplay GraphicsLayer to null so that it
                    // unhooks all the bindings and events
                    View.Instance.AttributeDisplay.GraphicsLayer = null;

                    // Hook up to the UpdateCompleted/UpdateFailed events so that the layer
                    // can be reset to the SelectedLayer
                    featureLayer.UpdateCompleted -= OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateCompleted += OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateFailed    -= OnFeatureLayerUpdateFailed;
                    featureLayer.UpdateFailed    += OnFeatureLayerUpdateFailed;
                }

                if (refreshCompletedHander != null)
                {
                    featureLayer.UpdateCompleted -= refreshCompletedHander;
                    featureLayer.UpdateCompleted += refreshCompletedHander;
                }
                if (refreshFailedHandler != null)
                {
                    featureLayer.UpdateFailed -= refreshFailedHandler;
                    featureLayer.UpdateFailed += refreshFailedHandler;
                }
                featureLayer.Update();
                return;
            }

            ArcGISDynamicMapServiceLayer dynamicLayer = layer as ArcGISDynamicMapServiceLayer;

            if (dynamicLayer != null)
            {
                dynamicLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISTiledMapServiceLayer tiledLayer = layer as ArcGISTiledMapServiceLayer;

            if (tiledLayer != null)
            {
                // Tiled layers do not support refreshing
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISImageServiceLayer imageServiceLayer = layer as ArcGISImageServiceLayer;

            if (imageServiceLayer != null)
            {
                imageServiceLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ICustomGraphicsLayer customGraphicsLayer = layer as ICustomGraphicsLayer;

            if (customGraphicsLayer != null)
            {
                customGraphicsLayer.ForceRefresh(refreshCompletedHander, refreshFailedHandler);
                return;
            }


            HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase;

            if (heatMapLayer != null)
            {
                heatMapLayer.Update();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            GeoRssLayer geoRssLayer = Layer as GeoRssLayer;

            if (geoRssLayer != null)
            {
                geoRssLayer.Update();
                return;
            }

            WmsLayer wmsLayer = Layer as WmsLayer;

            if (wmsLayer != null)
            {
                wmsLayer.Refresh();
                return;
            }

            GraphicsLayer graphicsLayer = layer as GraphicsLayer;

            if (graphicsLayer != null)
            {
                graphicsLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }
        }
예제 #23
0
        public void Add(string sLink, string sID)
        {
            ArcGISServiceType myType = ArcGISServiceType.Unknown;

            if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0)
            {
                myType = ArcGISServiceType.WMS;
            }
            else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0)
            {
                myType = ArcGISServiceType.ImageServer;
            }
            else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0)
            {
                if (sLink.ToUpper().IndexOf("MAPSERVER") > 0)
                {
                    myType = ArcGISServiceType.ArcGIS;
                }
            }


            _status = "Adding new service...";

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (myType)
            {
            case ArcGISServiceType.ArcGIS:
                layer = new ArcGISDynamicMapServiceLayer();
                ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer;
                temp.InitializationFailed += new EventHandler <EventArgs>(layer_InitializationFailed);
                temp.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                temp.Url = sLink;
                temp.ID  = sID;
                break;

            case ArcGISServiceType.ImageServer:
                layer = new ArcGISImageServiceLayer();
                ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer;
                imageServer.Url                   = sLink;
                imageServer.ID                    = sID;
                imageServer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                imageServer.InitializationFailed += new EventHandler <EventArgs>(imageServer_InitializationFailed);
                break;

            case ArcGISServiceType.WMS:
                layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
                ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
                wmsLayer.InitializationFailed += new EventHandler <EventArgs>(wmsLayer_InitializationFailed);
                wmsLayer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                string [] layers = new string[1];
                layers[0]       = "1";
                wmsLayer.Layers = layers;
                wmsLayer.Url    = CleanWMSSErvices(sLink);
                wmsLayer.ID     = sID;
                break;

            case ArcGISServiceType.IMS:
                layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer();
                ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer;
                imsLayer.InitializationFailed += new EventHandler <EventArgs>(imsLayer_InitializationFailed);
                imsLayer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                imsLayer.ID          = sID;
                imsLayer.ServiceHost = sLink;
                imsLayer.ServiceHost = sLink;
                break;
            }

            if (layer != null)
            {
                _mapServicesID.Add(layer.ID);
                _map.Layers.Add(layer);
            }
        }
        public override void CreateLayerAsync(Resource resource, SpatialReference mapSpatialReference, object userState)
        {
            if(resource == null)
                return;

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (resource.ResourceType)
            {
                case ResourceType.MapServer:
                case ResourceType.FeatureServer:
                    {
                        string url = resource.Url;
                        if (resource.ResourceType == ResourceType.FeatureServer)
                        {
                            int i = url.LastIndexOf(string.Format("/{0}", ResourceType.FeatureServer.ToString()));
                            if (i >= 0)
                            {
                                url = url.Remove(i);
                                url = string.Format("{0}/{1}", url, ResourceType.MapServer.ToString());
                            }
                        }

                        _service = ServiceFactory.CreateService(ResourceType.MapServer, url, resource.ProxyUrl);
                        if (_service != null)
                        {
                            _service.ServiceDetailsDownloadFailed += (o, e) =>
                            {
                                OnCreateLayerFailed(e);
                            };
                            _service.ServiceDetailsDownloadCompleted += (o, e) =>
                            {
                                MapService mapService = o as MapService;
                                if (mapService.ServiceInfo == null)
                                {
                                    OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveMapServiceDetails), e.UserState));
                                    return;
                                }

                                if (mapService.ServiceInfo.TileInfo != null && mapService.ServiceInfo.SingleFusedMapCache)
                                {
                                    #region Create tiled layer
                                    if (mapSpatialReference != null && !mapSpatialReference.Equals(mapService.ServiceInfo.SpatialReference))
                                    {
                                        OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionCachedMapServiceSpatialReferenceDoesNotMatch), e.UserState));
                                        return;
                                    }
                                    layer = new ArcGISTiledMapServiceLayer()
                                    {
                                        Url = url,
                                        ProxyURL = getCleanProxyUrl(mapService.ProxyUrl),
                                    };

                                    if (mapService.ServiceInfo.TileInfo.LODs != null)
                                    {
                                        double maxResolution = 0;
                                        double minResolution = 0;
                                        foreach (LODInfo lod in mapService.ServiceInfo.TileInfo.LODs)
                                        {
                                            if (lod.Resolution > maxResolution)
                                                maxResolution = lod.Resolution;
                                            if (minResolution <= 0 || minResolution > lod.Resolution)
                                                minResolution = lod.Resolution;
                                        }
                                        if (maxResolution > 0 )
                                            layer.MaximumResolution = maxResolution * 4;
                                        if (minResolution > 0)
                                            layer.MinimumResolution = minResolution / 4;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region create dynamic layer
                                    layer = new ArcGISDynamicMapServiceLayer()
                                    {
                                        Url = url,
                                        ProxyURL = getCleanProxyUrl(mapService.ProxyUrl),
                                    };
                                    #endregion
                                }

                                //Set layer's attached properties
                                if (layer != null)
                                {
                                    layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                                    layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, url);
                                    if (!string.IsNullOrEmpty(resource.ProxyUrl))
                                        Core.LayerExtensions.SetUsesProxy(layer, true);
                                    layer.ID = Guid.NewGuid().ToString("N");
                                }

                                OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = e.UserState });

                            };

                            _service.GetServiceDetails(null);
                        }

                    } break;

                case ResourceType.ImageServer:
                    {
                        layer = new ArcGISImageServiceLayer()
                        {
                            Url = resource.Url,
                            ProxyURL = getCleanProxyUrl(resource.ProxyUrl),
                            ID = Guid.NewGuid().ToString("N"),
                        };

                        //Set layer's attached properties
                        layer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                        layer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url);
                        if (!string.IsNullOrEmpty(resource.ProxyUrl))
                            Core.LayerExtensions.SetUsesProxy(layer, true);

                        // Need to declare handler separate from lambda expression to avoid erroneous
                        // "use of unassigned variable" build error
                        EventHandler<EventArgs> initialized = null;

                        // Need to populate the layer's metadata to handle initialization of image format
                        // and band IDs
                        initialized = (o, e) =>
                        {
                            layer.Initialized -= initialized;
                            ArcGISImageServiceLayer imageLayer = (ArcGISImageServiceLayer)layer;
                            if (imageLayer.Version < 10)
                            {
                                // Pre v10, band IDs must be specified explicitly.  But no more than 
                                // 3 can be used.  Just take up to the first 3 by default.
                                List<int> bandIDs = new List<int>();
                                for (int i = 0; i < imageLayer.BandCount; i++)
                                {
                                    bandIDs.Add(i);
                                    if (i == 2)
                                        break;
                                }

                                imageLayer.BandIds = bandIDs.ToArray();

                                // Use png format to support transparency
                                imageLayer.ImageFormat = ArcGISImageServiceLayer.ImageServiceImageFormat.PNG8;
                            }
                            else
                            {
                                // At v10 and later, band IDs do not need to be specified, and jpg/png
                                // format introduces some intelligence about which format is best
                                imageLayer.ImageFormat = 
                                    ArcGISImageServiceLayer.ImageServiceImageFormat.JPGPNG;
                            }

                            OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = userState });
                        };

                        EventHandler<EventArgs> initFailed = null;
                        initFailed = (o, e) =>
                        {
                            layer.InitializationFailed -= initFailed;
                            OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = layer, UserState = userState });
                        };

                        layer.Initialized += initialized;
                        layer.InitializationFailed += initFailed;
                        layer.Initialize();
                    }
                    break;
                case ResourceType.Layer:
                case ResourceType.EditableLayer:
                    {
                        featureLayer = new Layer(resource.Url, resource.ProxyUrl);
                        featureLayer.GetLayerDetailsFailed += (o, e) =>
                        {
                            OnCreateLayerFailed(e);
                        };
                        featureLayer.GetLayerDetailsCompleted += (o, e) =>
                        {
                            if (e.LayerDetails == null)
                            {
                                OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionUnableToRetrieveLayerDetails), e.UserState));
                                return;
                            }
                            if (Utility.RasterLayer.Equals(e.LayerDetails.Type))
                            {
                                OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionRasterLayersNotSupported), e.UserState));
                                return;
                            }
                            else if (Utility.ImageServerLayer.Equals(e.LayerDetails.Type))
                            {
                                OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionImageServerLayersNotSupported), e.UserState));
                                return;
                            }

                            if (Utility.CapabilitiesSupportsQuery(e.LayerDetails.Capabilities) == false)
                            {
                                OnCreateLayerFailed(new ExceptionEventArgs(new Exception(Resources.Strings.ExceptionLayerDoesNotSupportQuery), e.UserState));
                                return;
                            }

                            GeometryType GeometryType = GeometryType.Unknown;
                            switch (e.LayerDetails.GeometryType)
                            {
                                case "esriGeometryPoint":
                                    GeometryType = GeometryType.Point;
                                    break;
                                case "esriGeometryMultipoint":
                                    GeometryType = GeometryType.MultiPoint;
                                    break;
                                case "esriGeometryPolyline":
                                    GeometryType = GeometryType.Polyline;
                                    break;
                                case "esriGeometryPolygon":
                                    GeometryType = GeometryType.Polygon;
                                    break;
                            }
                            FeatureLayer newFeatureLayer = new FeatureLayer()
                            {
                                Url = featureLayer.Uri,
                                ProxyUrl = getCleanProxyUrl(featureLayer.ProxyUrl),
                                ID = Guid.NewGuid().ToString("N"),
                                Mode = FeatureLayer.QueryMode.OnDemand,
                                Renderer = new ESRI.ArcGIS.Mapping.Core.Symbols.HiddenRenderer()
                            };
                            newFeatureLayer.SetValue(MapApplication.LayerNameProperty, resource.DisplayName);
                            newFeatureLayer.SetValue(Core.LayerExtensions.DisplayUrlProperty, resource.Url);
                            newFeatureLayer.SetValue(Core.LayerExtensions.GeometryTypeProperty, GeometryType);
                            if (!string.IsNullOrEmpty(resource.ProxyUrl))
                                Core.LayerExtensions.SetUsesProxy(newFeatureLayer, true);
                            if (e.LayerDetails.Fields != null)
                            {
                                Collection<ESRI.ArcGIS.Mapping.Core.FieldInfo> fields = FieldInfosFromFields(e.LayerDetails.Fields);
                                newFeatureLayer.SetValue(Core.LayerExtensions.FieldsProperty, fields);
                                Core.LayerExtensions.SetDisplayField(newFeatureLayer, e.LayerDetails.DisplayField);
                            }
                            newFeatureLayer.OutFields.Add("*"); // Get all fields at configuration time
                            OnCreateLayerCompleted(new CreateLayerCompletedEventArgs() { Layer = newFeatureLayer, UserState = e.UserState, GeometryType = GeometryType });
                        };
                        featureLayer.GetLayerDetails(userState);
                    } break;

                default:
                    throw new Exception(string.Format(Resources.Strings.ExceptionCannotCreateLayerForResourceType, resource.ResourceType.ToString()));
            }
            
        }
        public static void SetProxyUrl(Layer layer, string proxyUrl)
        {
            ArcGISDynamicMapServiceLayer dmsLayer = layer as ArcGISDynamicMapServiceLayer;
            string url = null;

            if (dmsLayer != null)
            {
                if (dmsLayer.ProxyURL != proxyUrl)
                {
                    url = dmsLayer.Url;
                    try
                    {
                        dmsLayer.Url = "";
                    }
                    catch { }
                    dmsLayer.ProxyURL = proxyUrl;
                    dmsLayer.Url      = url;
                    dmsLayer.Refresh();
                }
                return;
            }
            ArcGISImageServiceLayer isLayer = layer as ArcGISImageServiceLayer;

            if (isLayer != null)
            {
                if (isLayer.ProxyURL != proxyUrl)
                {
                    url = isLayer.Url;
                    try
                    {
                        isLayer.Url = "";
                    }
                    catch { }
                    isLayer.ProxyURL = proxyUrl;
                    isLayer.Url      = url;
                    isLayer.Refresh();
                }
                return;
            }
            ArcGISTiledMapServiceLayer tmsLayer = layer as ArcGISTiledMapServiceLayer;

            if (tmsLayer != null)
            {
                if (tmsLayer.ProxyURL != proxyUrl)
                {
                    url = tmsLayer.Url;
                    try
                    {
                        tmsLayer.Url = "";
                    }
                    catch { }
                    tmsLayer.ProxyURL = proxyUrl;
                    tmsLayer.Url      = url;
                    tmsLayer.Refresh();
                }
                return;
            }
            FeatureLayer fLayer = layer as FeatureLayer;

            if (fLayer != null)
            {
                if (fLayer.ProxyUrl != proxyUrl)
                {
                    fLayer.ProxyUrl = proxyUrl;
                    fLayer.Update();
                }
                return;
            }
            HeatMapFeatureLayer hmfLayer = layer as HeatMapFeatureLayer;

            if (hmfLayer != null)
            {
                if (hmfLayer.ProxyUrl != proxyUrl)
                {
                    hmfLayer.ProxyUrl = proxyUrl;
                    hmfLayer.Update();
                }
                return;
            }
        }
예제 #26
0
        private void ConfigureApplication(ref Configuration xmlConfiguation)
        {
            Title  = xmlConfiguation.Title;
            Width  = xmlConfiguation.Width;
            Height = xmlConfiguation.Height;

            ParcelLines.MaxHeight = _xmlConfiguation.MaxGridHeight;

            // insert layer before [graphical] layers defined in xaml
            Int32  layerIndex = 0;
            String lastUnit   = "";

            foreach (LayerDefinition definition in xmlConfiguation.DisplayLayers)
            {
                if (definition.Type == "dynamic")
                {
                    ArcGISDynamicMapServiceLayer dynamicMS = new ArcGISDynamicMapServiceLayer();
                    dynamicMS.Url = definition.Url;
                    dynamicMS.ID  = definition.Id;
                    dynamicMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, dynamicMS);
                    if ((dynamicMS.Units != null) && (dynamicMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = dynamicMS.Units;
                    }
                }

                if (definition.Type == "feature")
                {
                    FeatureLayer featureMS = new FeatureLayer();
                    featureMS.Url = definition.Url + "/" + definition.Id.ToString();
                    featureMS.ID  = definition.Id;
                    featureMS.InitializationFailed += Layer_InitializationFailed;
                    featureMS.Mode = FeatureLayer.QueryMode.OnDemand;
                    ParcelMap.Layers.Insert(layerIndex++, featureMS);
                    // FOOBAR FeatureLayer does not support unit?
                }

                if (definition.Type == "tiled")
                {
                    ArcGISTiledMapServiceLayer tiledMS = new ArcGISTiledMapServiceLayer();
                    tiledMS.Url = definition.Url;
                    tiledMS.ID  = definition.Id;
                    tiledMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, tiledMS);
                    if ((tiledMS.Units != null) && (tiledMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = tiledMS.Units;
                    }
                }

                if (definition.Type == "image")
                {
                    ArcGISImageServiceLayer imageS = new ArcGISImageServiceLayer();
                    imageS.Url = definition.Url;
                    imageS.ID  = definition.Id;
                    imageS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, imageS);
                }
            }

            if (!xmlConfiguation.HasSpatialReferenceUnit)
            {
                xmlConfiguation.MapSpatialReferenceUnits = lastUnit;
            }

            ESRI.ArcGIS.Client.Geometry.Envelope extent = null;
            if (xmlConfiguation.IsExtentSet())
            {
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(xmlConfiguation.XMin, xmlConfiguation.YMin, xmlConfiguation.XMax, xmlConfiguation.YMax);
            }
            else
            {
                // Map will not zoom to, etc with out some value set.
                // Ideally we would like to set the extent to the full extent of the first
                // layer, but since they layer has hot been drawn yet null is returned.
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(100, 100, 100, 100);
            }

            // if zero, the first inserted layer is used
            if ((xmlConfiguation.SpatialReferenceWKT != null) && (xmlConfiguation.SpatialReferenceWKT != ""))
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKT);
            }
            else if (xmlConfiguation.SpatialReferenceWKID != 0)
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKID);
            }

            ParcelMap.Extent = extent;

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            parcelData.Configuration = xmlConfiguation;

            QueryLabel.Text = xmlConfiguation.QueryLabel;
        }
예제 #27
0
        public void Add(string sLink, string sID)
        {
            ArcGISServiceType myType = ArcGISServiceType.Unknown;

            if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0)
                myType = ArcGISServiceType.WMS;
            else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0)
                myType = ArcGISServiceType.ImageServer;
            else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0)
                if (sLink.ToUpper().IndexOf("MAPSERVER") > 0)
                    myType = ArcGISServiceType.ArcGIS;

            _status = "Adding new service...";

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (myType)
            {
                case ArcGISServiceType.ArcGIS:
                    layer = new ArcGISDynamicMapServiceLayer();
                    ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer;
                    temp.InitializationFailed += new EventHandler<EventArgs>(layer_InitializationFailed);
                    temp.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    temp.Url = sLink;
                    temp.ID = sID;
                    break;

                case ArcGISServiceType.ImageServer:
                    layer = new ArcGISImageServiceLayer();
                    ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer;
                    imageServer.Url = sLink;
                    imageServer.ID = sID;
                    imageServer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    imageServer.InitializationFailed += new EventHandler<EventArgs>(imageServer_InitializationFailed);
                    break;

                case ArcGISServiceType.WMS:
                    layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
                    ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
                    wmsLayer.InitializationFailed += new EventHandler<EventArgs>(wmsLayer_InitializationFailed);
                    wmsLayer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    string [] layers = new string[1];
                    layers[0] = "1";
                    wmsLayer.Layers = layers;
                    wmsLayer.Url = CleanWMSSErvices(sLink);
                    wmsLayer.ID = sID;
                    break;
                case ArcGISServiceType.IMS:
                    layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer();
                    ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer;
                    imsLayer.InitializationFailed += new EventHandler<EventArgs>(imsLayer_InitializationFailed);
                    imsLayer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    imsLayer.ID = sID;
                    imsLayer.ServiceHost = sLink;
                    imsLayer.ServiceHost = sLink;
                    break;
            }

            if (layer != null)
            {
                _mapServicesID.Add(layer.ID);
                _map.Layers.Add(layer);
            }
        }
예제 #28
0
        private void ConfigureApplication(ref Configuration xmlConfiguation)
        {
            Title = xmlConfiguation.Title;
              Width = xmlConfiguation.Width;
              Height = xmlConfiguation.Height;

              ParcelLines.MaxHeight = _xmlConfiguation.MaxGridHeight;

              // insert layer before [graphical] layers defined in xaml
              Int32 layerIndex = 0;
              String lastUnit = "";
              foreach (LayerDefinition definition in xmlConfiguation.DisplayLayers)
              {
            if (definition.Type == "dynamic")
            {
              ArcGISDynamicMapServiceLayer dynamicMS = new ArcGISDynamicMapServiceLayer();
              dynamicMS.Url = definition.Url;
              dynamicMS.ID = definition.Id;
              dynamicMS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, dynamicMS);
              if ((dynamicMS.Units != null) && (dynamicMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
            lastUnit = dynamicMS.Units;
            }

            if (definition.Type == "feature")
            {
              FeatureLayer featureMS = new FeatureLayer();
              featureMS.Url = definition.Url + "/" + definition.Id.ToString();
              featureMS.ID = definition.Id;
              featureMS.InitializationFailed += Layer_InitializationFailed;
              featureMS.Mode = FeatureLayer.QueryMode.OnDemand;
              ParcelMap.Layers.Insert(layerIndex++, featureMS);
              // FOOBAR FeatureLayer does not support unit?
            }

            if (definition.Type == "tiled")
            {
              ArcGISTiledMapServiceLayer tiledMS = new ArcGISTiledMapServiceLayer();
              tiledMS.Url = definition.Url;
              tiledMS.ID = definition.Id;
              tiledMS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, tiledMS);
              if ((tiledMS.Units != null) && (tiledMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
            lastUnit = tiledMS.Units;
            }

            if (definition.Type == "image")
            {
              ArcGISImageServiceLayer imageS = new ArcGISImageServiceLayer();
              imageS.Url = definition.Url;
              imageS.ID = definition.Id;
              imageS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, imageS);
            }
              }

              if (!xmlConfiguation.HasSpatialReferenceUnit)
            xmlConfiguation.MapSpatialReferenceUnits = lastUnit;

              ESRI.ArcGIS.Client.Geometry.Envelope extent = null;
              if (xmlConfiguation.IsExtentSet())
            extent = new ESRI.ArcGIS.Client.Geometry.Envelope(xmlConfiguation.XMin, xmlConfiguation.YMin, xmlConfiguation.XMax, xmlConfiguation.YMax);
              else
            // Map will not zoom to, etc with out some value set.
            // Ideally we would like to set the extent to the full extent of the first
            // layer, but since they layer has hot been drawn yet null is returned.
            extent = new ESRI.ArcGIS.Client.Geometry.Envelope(100, 100, 100, 100);

              // if zero, the first inserted layer is used
              if ((xmlConfiguation.SpatialReferenceWKT != null) && (xmlConfiguation.SpatialReferenceWKT != ""))
            extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKT);
              else if (xmlConfiguation.SpatialReferenceWKID != 0)
            extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKID);

              ParcelMap.Extent = extent;

              ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;
              parcelData.Configuration = xmlConfiguation;

              QueryLabel.Text = xmlConfiguation.QueryLabel;
        }