Пример #1
0
        public Task <bool> SetConnectionString(string value)
        {
            _class      = null;
            _wfsDataset = null;
            switch (ConfigTextStream.ExtractValue(value, "service").ToUpper())
            {
            case "WMS":
                _type       = SERVICE_TYPE.WMS;
                _connection = ConfigTextStream.ExtractValue(value, "wms");
                _class      = new WMSClass(this);
                break;

            case "WFS":
                _type       = SERVICE_TYPE.WFS;
                _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs"));
                break;

            case "WMS_WFS":
                _type       = SERVICE_TYPE.WMS_WFS;
                _connection = ConfigTextStream.ExtractValue(value, "wms");
                _class      = new WMSClass(this);
                _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs"));
                break;

            default:
                return(Task.FromResult(false));
            }
            _connectionString = value;

            return(Task.FromResult(true));
        }
Пример #2
0
        public object Clone()
        {
            WMSClass clone = new WMSClass(_dataset);

            clone._clonedThemes = new List <IWebServiceTheme>();

            foreach (IWebServiceTheme theme in Themes)
            {
                if (theme == null || theme.Class == null)
                {
                    continue;
                }

                WebServiceTheme clonedTheme = new WebServiceTheme(
                    theme.Class, theme.Title, theme.LayerID, theme.Visible, clone);
                clonedTheme.ID = theme.ID;
                clone._clonedThemes.Add(clonedTheme);
            }

            clone._exceptions               = this._exceptions;
            clone._srs                      = (SRS)this._srs.Clone();
            clone._sRef                     = this._sRef;
            clone._envelope                 = this._envelope;
            clone._getCapabilities          = this._getCapabilities;
            clone._getFeatureInfo           = this._getFeatureInfo;
            clone._getMap                   = this._getMap;
            clone._userDefinedSymbolization = this._userDefinedSymbolization;
            clone.AfterMapRequest           = AfterMapRequest;
            clone.BeforeMapRequest          = BeforeMapRequest;
            return(clone);
        }
Пример #3
0
        public bool ApplyTo(object Object)
        {
            if (Object is IServiceMap)
            {
                _map = (IServiceMap)Object;
                if (ServiceMapIsSVC(_map.MapServer, _map))
                {
                    foreach (IDatasetElement element in _map.MapElements)
                    {
                        if (element.Class is WMSClass)
                        {
                            WMSClass wmsClass = (WMSClass)element.Class;
                            _srsCodes        = wmsClass.SRSCodes;
                            _getFeatureInfos = wmsClass.FeatureInfoFormats;
                            _getMapInfos     = wmsClass.GetMapFormats;
                            return(true);
                        }
                    }
                }

                _map = null;
                return(false);
            }
            else if (Object is IMap && _map != null &&
                     ((IMap)Object).Name == _map.Name)
            {
                foreach (IDatasetElement element in _map.MapElements)
                {
                    if (element.Class is WMSClass)
                    {
                        WMSClass wmsClass = (WMSClass)element.Class;
                        if (!String.IsNullOrEmpty(_srsCode))
                        {
                            wmsClass.SRSCode = _srsCode;
                        }
                        if (!String.IsNullOrEmpty(_getMapInfo))
                        {
                            wmsClass.SRSCode = _getMapInfo;
                        }
                        if (!String.IsNullOrEmpty(_getFeatureInfo))
                        {
                            wmsClass.FeatureInfoFormat = _getFeatureInfo;
                        }

                        // SpatialReference gleich auf Karte übernehmen...
                        ISpatialReference sRef = wmsClass.SpatialReference;
                        if (sRef != null)
                        {
                            ((IMap)Object).Display.SpatialReference = sRef;
                        }
                        break;
                    }
                }
                _map = null;
                return(true);
            }
            return(false);
        }
Пример #4
0
        async public Task <bool> Open(gView.MapServer.IServiceRequestContext context)
        {
            string url = String.Empty;

            try
            {
                _isOpened = true;
                bool ret = true;

                if (_wfsDataset != null)
                {
                    ret = _wfsDataset.Open();
                }
                if (_class != null)
                {
                    string param = "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";

                    url = Append2Url(_connection, param);
                    string response = WebFunctions.HttpSendRequest(url, "GET", null,
                                                                   ConfigTextStream.ExtractValue(_connectionString, "usr"),
                                                                   ConfigTextStream.ExtractValue(_connectionString, "pwd"));

                    response = RemoveDOCTYPE(response);

                    _class.Init(response, _wfsDataset);
                }

                _state = (ret) ? DatasetState.opened : DatasetState.unknown;

                return(ret);
            }
            catch (Exception ex)
            {
                await WMSClass.ErrorLogAsync(context, "GetCapabilities", url, ex);

                _class      = null;
                _wfsDataset = null;

                return(false);
            }
        }
Пример #5
0
        public bool MapRequest(gView.Framework.Carto.IDisplay display)
        {
            if (_srs == null)
            {
                return(false);
            }

            if (!_dataset.IsOpened)
            {
                if (!_dataset.Open())
                {
                    return(false);
                }
            }

            List <IWebServiceTheme> themes = Themes;

            if (themes == null)
            {
                return(false);
            }

            #region Check for visible Layers
            bool visFound = false;
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible)
                {
                    continue;
                }
                if (theme.MinimumScale > 1 && theme.MinimumScale > display.mapScale)
                {
                    continue;
                }
                if (theme.MaximumScale > 1 && theme.MaximumScale < display.mapScale)
                {
                    continue;
                }

                visFound = true;
                break;
            }
            if (!visFound)
            {
                if (_image != null)
                {
                    _image.Dispose();
                    _image = null;
                }
                return(true);
            }
            #endregion

            int iWidth  = display.iWidth;
            int iHeight = display.iHeight;

            if (BeforeMapRequest != null)
            {
                ISpatialReference sRef = this.SpatialReference;
                BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight);
                if (sRef != null && sRef.Name.ToLower() != this.SRSCode.ToLower())
                {
                    this.SRSCode = sRef.Name;
                }
            }

            IEnvelope displayEnv = display.Envelope;

            if (display.SpatialReference != null && !display.SpatialReference.Equals(this.SpatialReference))
            {
                displayEnv = GeometricTransformer.Transform2D(displayEnv, display.SpatialReference, this.SpatialReference).Envelope;
                iHeight    = (int)((displayEnv.Height / displayEnv.Width) * iWidth);
            }

            StyledLayerDescriptorWriter sldWriter = null;
            StringBuilder request = new StringBuilder("VERSION=1.1.1&REQUEST=GetMap");
            StringBuilder layers = new StringBuilder(), styles = new StringBuilder();
            foreach (IWebServiceTheme theme in themes)
            {
                if (!theme.Visible || theme.Locked ||
                    (!(theme.Class is WMSThemeClass) &&
                     !(theme.Class is WFSFeatureClass)))
                {
                    continue;
                }

                if (layers.Length > 0)
                {
                    layers.Append(",");
                    styles.Append(",");
                }
                layers.Append(theme.Class.Name);
                if (theme.Class is IWMSStyle)
                {
                    styles.Append(((IWMSStyle)theme.Class).Style);
                }
                if (theme.FeatureRenderer != null &&
                    _userDefinedSymbolization.SupportSLD &&
                    _userDefinedSymbolization.UserStyle)
                {
                    SLDRenderer sldRenderer = null;
                    if (theme.FeatureRenderer is SLDRenderer)
                    {
                        sldRenderer = (SLDRenderer)theme.FeatureRenderer;
                    }
                    else
                    {
                        //if (theme.FilterQuery is ISpatialFilter)
                        //{
                        //    IGeometry pGeometry = GeometricTransformer.Transform2D(
                        //        ((ISpatialFilter)theme.FilterQuery).Geometry,
                        //        display.SpatialReference,
                        //        this.SpatialReference);

                        //    IGeometry oGeometry = ((ISpatialFilter)theme.FilterQuery).Geometry;
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = pGeometry;
                        //    sldRenderer = new SLDRenderer(theme);
                        //    ((ISpatialFilter)theme.FilterQuery).Geometry = oGeometry;
                        //}
                        //else
                        {
                            sldRenderer = new SLDRenderer(theme);
                            if (display.SpatialReference != null)
                            {
                                sldRenderer.SetDefaultSrsName(display.SpatialReference.Name);
                            }
                        }
                    }
                    if (sldWriter == null)
                    {
                        sldWriter = new StyledLayerDescriptorWriter();
                    }

                    sldWriter.WriteNamedLayer(theme.Class.Name, sldRenderer);
                }
            }
            request.Append("&LAYERS=" + layers.ToString());
            if (sldWriter != null)
            {
                string sld = sldWriter.ToLineString();
                if (!_use_SLD_BODY && !string.IsNullOrEmpty(MapServerConfig.DefaultOutputPath))
                {
                    string       sldFilename = "style_" + Guid.NewGuid().ToString("N") + ".sld";
                    StreamWriter sw          = new StreamWriter(MapServerConfig.DefaultOutputPath + @"\" + sldFilename);
                    sw.WriteLine(sldWriter.ToString());
                    sw.Close();

                    request.Append("&SLD=" + MapServerConfig.DefaultOutputUrl + "/" + sldFilename);
                }
                else
                {
                    request.Append("&SLD_BODY=" + sld.Replace("#", "%23"));
                }
            }
            else
            {
                request.Append("&STYLES=" + styles.ToString());
            }
            if (_exceptions != null && _exceptions.Formats.Count > 0)
            {
                request.Append("&EXCEPTIONS=" + _exceptions.Formats[0]);
            }
            request.Append("&SRS=" + _srs.Srs[_srs.SRSIndex]);
            request.Append("&WIDTH=" + iWidth);
            request.Append("&HEIGHT=" + iHeight);
            request.Append("&FORMAT=" + _getMap.Formats[_getMap.FormatIndex]);
            request.Append("&BBOX=" +
                           displayEnv.minx.ToString(_nhi) + "," +
                           displayEnv.miny.ToString(_nhi) + "," +
                           displayEnv.maxx.ToString(_nhi) + "," +
                           displayEnv.maxy.ToString(_nhi));
            //request.Append("&BGCOLOR=FFFFFF");
            request.Append("&TRANSPARENT=TRUE");

            if (_image != null)
            {
                _image.Dispose();
                _image = null;
            }
            System.Drawing.Bitmap bm = null;
            //if (_getMap.Post_OnlineResource != String.Empty && sldWriter != null)
            //{
            //    //bm = WebFunctions.DownloadImage(WMSDataset.Append2Url(_getMap.Post_OnlineResource, request.ToString() + "&SLD="),
            //    //    UTF8Encoding.UTF8.GetBytes(sldWriter.ToString()));
            //    bm = WebFunctions.DownloadImage(_getMap.Post_OnlineResource,
            //        UTF8Encoding.UTF8.GetBytes(request.ToString()));
            //}
            //else
            {
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("Start WMS DownloadImage");
#endif
                string url = WMSDataset.Append2Url(_getMap.Get_OnlineResource, request.ToString());
                try
                {
                    bm = WebFunctions.DownloadImage(url,
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "usr"),
                                                    ConfigTextStream.ExtractValue(_dataset._connectionString, "pwd"));
                }
                catch (Exception ex)
                {
                    WMSClass.ErrorLog(display.Map as IServiceRequestContext, "MapRequest", url, ex);
                    return(false);
                }
#if (DEBUG)
                gView.Framework.system.Logger.LogDebug("WMS DownloadImage Finished");
#endif
            }
            if (bm != null)
            {
                _image                  = new GeorefBitmap(bm);
                _image.Envelope         = displayEnv;
                _image.SpatialReference = this.SpatialReference;

                if (AfterMapRequest != null)
                {
                    AfterMapRequest(this, display, _image);
                }
            }
            return(_image != null);
        }