Exemple #1
0
        /// <summary>
        /// Add a list of wms layers to the map.
        /// </summary>
        /// <param name="wmsLayers"></param>
        public void AddWMSLayers(List <WMSInfo> wmsLayers)
        {
            wmsLayers = wmsLayers.OrderBy(layer => layer.zIndex).ToList();
            for (int i = 0; i < wmsLayers.Count; i++)
            {
                string      layername = "WMSLayer_" + i;
                DpiWmsLayer layer     = new DpiWmsLayer(layername, wmsLayers[i].url, exportItem.resolution);

                layer.SetImageFormat("image/png");
                layer.BgColor         = Color.White;
                layer.Transparent     = true;
                layer.Version         = "1.1.0";
                layer.ContinueOnError = false;

                for (int t = 0; t < wmsLayers[i].layers.Count; t++)
                {
                    string sublayerName = "";
                    sublayerName = wmsLayers[i].workspacePrefix != null ?
                                   wmsLayers[i].workspacePrefix + ":" + wmsLayers[i].layers[t] :
                                   wmsLayers[i].layers[t];

                    if (sublayerName != "")
                    {
                        layer.AddLayer(sublayerName);
                    }
                }
                layer.SRID = wmsLayers[i].coordinateSystemId;
                map.Layers.Add(layer);
            }
        }
Exemple #2
0
        /// <summary>
        /// Add a list of wms layers to the map.
        /// </summary>
        /// <param name="wmsLayers"></param>
        public void AddWMSLayers(List <WMSInfo> wmsLayers)
        {
            wmsLayers = wmsLayers.OrderBy(layer => layer.zIndex).ToList();
            try
            {
                //string path = @"C:\\log.txt";
                //StreamWriter file = new StreamWriter(path, true);

                //file.WriteLine("Starting to add layers");
                for (int i = 0; i < wmsLayers.Count; i++)
                {
                    //file.WriteLine("Found a layer");
                    string layername = "WMSLayer_" + i;

                    DpiWmsLayer layer = new DpiWmsLayer(layername, wmsLayers[i].url, exportItem.resolution);

                    layer.SetImageFormat("image/png");
                    layer.BgColor         = Color.White;
                    layer.Transparent     = true;
                    layer.Version         = "1.1.0";
                    layer.ContinueOnError = false;
                    for (int t = 0; t < wmsLayers[i].layers.Count; t++)
                    {
                        //file.WriteLine("Found a sublayer");
                        string sublayerName = "";
                        try
                        {
                            // Do not use workspace prefix, will return error
                            sublayerName = wmsLayers[i].workspacePrefix != null ?
                                           wmsLayers[i].workspacePrefix + ":" + wmsLayers[i].layers[t] :
                                           wmsLayers[i].layers[t];
                            //file.WriteLine("sublayername '" + sublayerName + "'");
                            if (sublayerName != "")
                            {
                                layer.AddLayer(sublayerName);
                            }
                        }
                        catch (Exception ex)
                        {
                            // TODO
                            //file.WriteLine("Error in adding subname.\n" + ex.ToString());
                            _log.ErrorFormat("Error in AddWMSLayers: {0}", ex.Message);
                        }
                    }
                    layer.SRID = wmsLayers[i].coordinateSystemId;
                    //file.WriteLine("Adding layer");
                    //file.Close();
                    map.Layers.Add(layer);
                    //using (StreamWriter sw = new StreamWriter(@"C:\\log.txt", true))
                    //{
                    //    sw.WriteLine("Layer added");
                    //}
                }
            }
            catch (Exception e)
            {
                _log.ErrorFormat("Error2 in AddWMSLayers: {0}", e.Message);

                /*
                 * using (StreamWriter sw = new StreamWriter(@"C:\\log.txt", true))
                 * {
                 *  sw.WriteLine("Got an error in add layers");
                 * }
                 */
                // TODO
            }
        }