public bool MapRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null || Themes == null) { return(false); } List <IWebServiceTheme> themes = Themes; #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 string server = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service"); string user = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd"); IServiceRequestContext context = display.Map as IServiceRequestContext; if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } dotNETConnector connector = new dotNETConnector(); if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd)) { connector.setAuthentification(user, pwd); } if (_dataset.State != DatasetState.opened) { if (!_dataset.Open(context)) { return(false); } } ISpatialReference sRef = (display.SpatialReference != null) ? display.SpatialReference.Clone() as ISpatialReference : null; int iWidth = display.iWidth; int iHeight = display.iHeight; if (BeforeMapRequest != null) { BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight); } try { StringBuilder sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='utf-8'?>"); sb.Append("<ARCXML version='1.1'>"); sb.Append("<REQUEST>"); sb.Append("<GET_IMAGE>"); sb.Append("<PROPERTIES>"); IEnvelope bounds = display.DisplayTransformation.TransformedBounds(display); if (display.DisplayTransformation.UseTransformation == true) { iWidth = (int)(bounds.Width * display.dpm / display.mapScale); iHeight = (int)(bounds.Height * display.dpm / display.mapScale); } sb.Append("<ENVELOPE minx='" + bounds.minx.ToString() + "' miny='" + bounds.miny.ToString() + "' maxx='" + bounds.maxx.ToString() + "' maxy='" + bounds.maxy.ToString() + "' />"); sb.Append("<IMAGESIZE width='" + iWidth + "' height='" + iHeight + "' />"); sb.Append("<BACKGROUND color='" + Color2AXL(display.BackgroundColor) + "' transcolor='" + Color2AXL(display.TransparentColor) + "' />"); string propertyString = _dataset._properties.PropertyString; if (propertyString != String.Empty) { sb.Append(_dataset._properties.PropertyString); } else { if (sRef != null) { //if (this.SpatialReference != null && !display.SpatialReference.Equals(this.SpatialReference)) { string wkt = gView.Framework.Geometry.SpatialReference.ToESRIWKT(sRef); string geotranwkt = gView.Framework.Geometry.SpatialReference.ToESRIGeotransWKT(sRef); if (wkt != null) { //wkt = "PROJCS[\"MGI_M31\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",450000],PARAMETER[\"False_Northing\",-5000000],PARAMETER[\"Central_Meridian\",13.3333333333333],PARAMETER[\"Scale_Factor\",1],PARAMETER[\"latitude_of_origin\",0],UNIT[\"Meter\",1]]"; //wkt = "PROJCS[\"MGI_M31\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",450000.0],PARAMETER[\"False_Northing\",-5000000.0],PARAMETER[\"Central_Meridian\",13.33333333333333],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]"; //geotranwkt = "GEOGTRAN[\"MGISTMK_To_WGS_1984\",GEOGCS[\"MGISTMK\",DATUM[\"Militar_Geographische_Institute_STMK\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],METHOD[\"Position_Vector\"],PARAMETER[\"X_Axis_Translation\",577.326],PARAMETER[\"Y_Axis_Translation\",90.129],PARAMETER[\"Z_Axis_Translation\",463.919],PARAMETER[\"X_Axis_Rotation\",5.1365988],PARAMETER[\"Y_Axis_Rotation\",1.4742],PARAMETER[\"Z_Axis_Rotation\",5.2970436],PARAMETER[\"Scale_Difference\",2.4232]]"; wkt = wkt.Replace("\"", """); geotranwkt = geotranwkt.Replace("\"", """); if (!String.IsNullOrEmpty(geotranwkt)) { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); } else { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" />"); } //sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformid=\"8415\" />"); //sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformid=\"8415\" />"); } } } } sb.Append("<LAYERLIST>"); foreach (IWebServiceTheme theme in themes) { sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'"); XmlNode xmlnode; if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode)) { sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>"); } else if (theme.FeatureRenderer != null) { string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer); sb.Append(">\n" + renderer + "\n</LAYERDEF>"); } else { sb.Append("/>"); } } sb.Append("</LAYERLIST>"); sb.Append("</PROPERTIES>"); foreach (XmlNode additional in this.AppendedLayers) { if (additional != null) { sb.Append(additional.OuterXml); } } sb.Append("</GET_IMAGE>"); sb.Append("</REQUEST>"); sb.Append("</ARCXML>"); #if (DEBUG) gView.Framework.system.Logger.LogDebug("Start ArcXML SendRequest"); #endif ArcIMSClass.Log(display as IServiceRequestContext, "GetImage Request", server, service, sb); string resp = connector.SendRequest(sb, server, service); ArcIMSClass.Log(display as IServiceRequestContext, "GetImage Response", server, service, resp); #if (DEBUG) gView.Framework.system.Logger.LogDebug("ArcXML SendRequest Finished"); #endif XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); XmlNode outputNode = doc.SelectSingleNode("//IMAGE/OUTPUT"); XmlNode envelopeNode = doc.SelectSingleNode("//IMAGE/ENVELOPE"); if (ModifyResponseOuput != null) { ModifyResponseOuput(this, new ModifyOutputEventArgs(outputNode)); } if (_image != null) { _image.Dispose(); _image = null; } #if (DEBUG) //gView.Framework.system.Logger.LogDebug("Start ArcXML DownloadImage"); #endif System.Drawing.Bitmap bm = null; if (outputNode != null) { #if (DEBUG) gView.Framework.system.Logger.LogDebug("Start ArcXML DownloadImage"); #endif bm = WebFunctions.DownloadImage(outputNode /*_dataset._connector.Proxy*/); #if (DEBUG) gView.Framework.system.Logger.LogDebug("ArcXML DownloadImage Finished"); #endif } else { bm = null; } #if (DEBUG) //gView.Framework.system.Logger.LogDebug("ArcXML DownloadImage Finished"); #endif if (bm != null) { _image = new GeorefBitmap(bm); //_image.MakeTransparent(display.TransparentColor); if (envelopeNode != null && envelopeNode.Attributes["minx"] != null && envelopeNode.Attributes["miny"] != null && envelopeNode.Attributes["maxx"] != null && envelopeNode.Attributes["maxy"] != null) { _image.Envelope = new Envelope( Convert.ToDouble(envelopeNode.Attributes["minx"].Value.Replace(".", ",")), Convert.ToDouble(envelopeNode.Attributes["miny"].Value.Replace(".", ",")), Convert.ToDouble(envelopeNode.Attributes["maxx"].Value.Replace(".", ",")), Convert.ToDouble(envelopeNode.Attributes["maxy"].Value.Replace(".", ","))); } _image.SpatialReference = display.SpatialReference; if (AfterMapRequest != null) { AfterMapRequest(this, display, _image); } } return(_image != null); } catch (Exception ex) { ArcIMSClass.ErrorLog(context, "MapRequest", server, service, ex); return(false); } }
public bool LegendRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null) { 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 (_legend != null) { _legend.Dispose(); _legend = null; } return(true); } #endregion string server = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service"); string user = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd"); IServiceRequestContext context = display.Map as IServiceRequestContext; if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } dotNETConnector connector = new dotNETConnector(); if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd)) { connector.setAuthentification(user, pwd); } if (_dataset.State != DatasetState.opened) { if (!_dataset.Open(context)) { return(false); } } try { StringBuilder sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='utf-8'?>"); sb.Append("<ARCXML version='1.1'>"); sb.Append("<REQUEST>"); sb.Append("<GET_IMAGE>"); sb.Append("<PROPERTIES>"); sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />"); sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />"); sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />"); sb.Append(_dataset._properties.PropertyString); sb.Append("<LAYERLIST>"); foreach (IWebServiceTheme theme in themes) { sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'"); XmlNode xmlnode; if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode)) { sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>"); } else if (theme.FeatureRenderer != null) { string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer); sb.Append(">\n" + renderer + "\n</LAYERDEF>"); } else { sb.Append("/>"); } } sb.Append("</LAYERLIST>"); sb.Append("<DRAW map=\"false\" />"); sb.Append("<LEGEND font=\"Arial\" autoextend=\"true\" columns=\"1\" width=\"165\" height=\"170\" backgroundcolor=\"255,255,255\" layerfontsize=\"11\" valuefontsize=\"10\">"); sb.Append("<LAYERS />"); sb.Append("</LEGEND>"); sb.Append("</PROPERTIES>"); foreach (XmlNode additional in this.AppendedLayers) { sb.Append(additional.OuterXml); } sb.Append("</GET_IMAGE>"); sb.Append("</REQUEST>"); sb.Append("</ARCXML>"); ArcIMSClass.Log(display as IServiceRequestContext, "GetLegend Request", server, service, sb); string resp = connector.SendRequest(sb, server, service); ArcIMSClass.Log(display as IServiceRequestContext, "GetLegend Response", server, service, resp); XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); XmlNode output = doc.SelectSingleNode("//LEGEND"); if (ModifyResponseOuput != null) { ModifyResponseOuput(this, new ModifyOutputEventArgs(output)); } if (_legend != null) { _legend.Dispose(); } _legend = WebFunctions.DownloadImage(output /*_dataset._connector.Proxy*/); return(true); } catch (Exception ex) { ArcIMSClass.ErrorLog(context, "LegendRequest", server, service, ex); return(false); } }
public bool MapRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null) { return(false); } if (!_dataset._opened) { _dataset.Open(); } IServiceRequestContext context = display.Map as IServiceRequestContext; try { ISpatialReference sRef = (display.SpatialReference != null) ? display.SpatialReference.Clone() as ISpatialReference : null; StringBuilder sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='utf-8'?>"); sb.Append("<ARCXML version='1.1'>"); sb.Append("<REQUEST>"); sb.Append("<GET_IMAGE>"); sb.Append("<PROPERTIES>"); sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />"); sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />"); sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />"); //if (display.SpatialReference != null && !display.SpatialReference.Equals(_sRef)) //{ // string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference); // sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />"); //} if (sRef != null) { string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference); sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />"); string wkt = gView.Framework.Geometry.SpatialReference.ToESRIWKT(sRef); string geotranwkt = gView.Framework.Geometry.SpatialReference.ToESRIGeotransWKT(sRef); if (wkt != null) { wkt = wkt.Replace("\"", """); geotranwkt = geotranwkt.Replace("\"", """); if (!String.IsNullOrEmpty(geotranwkt)) { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); } else { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" />"); } } } sb.Append("<LAYERLIST>"); foreach (IWebServiceTheme theme in Themes) { sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "' />"); } sb.Append("</LAYERLIST>"); sb.Append("</PROPERTIES>"); sb.Append("</GET_IMAGE>"); sb.Append("</REQUEST>"); sb.Append("</ARCXML>"); string user = ConfigTextStream.ExtractValue(_dataset._connection, "user"); string pwd = Identity.HashPassword(ConfigTextStream.ExtractValue(_dataset._connection, "pwd")); if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } #if (DEBUG) //Logger.LogDebug("Start gView Mapserver Request"); #endif MapServerConnection service = new MapServerConnection(ConfigTextStream.ExtractValue(_dataset._connection, "server")); string resp = service.Send(_name, sb.ToString(), "BB294D9C-A184-4129-9555-398AA70284BC", user, pwd); #if (DEBUG) //Logger.LogDebug("gView Mapserver Request Finished"); #endif XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); System.Drawing.Bitmap bm = null; XmlNode output = doc.SelectSingleNode("//OUTPUT[@file]"); if (_image != null) { _image.Dispose(); _image = null; } try { System.IO.FileInfo fi = new System.IO.FileInfo(output.Attributes["file"].Value); if (fi.Exists) { bm = System.Drawing.Bitmap.FromFile(fi.FullName) as System.Drawing.Bitmap; } } catch { } if (bm == null) { bm = WebFunctions.DownloadImage(output); } if (bm != null) { _image = new GeorefBitmap(bm); _image.SpatialReference = display.SpatialReference; _image.Envelope = display.Envelope; if (AfterMapRequest != null) { AfterMapRequest(this, display, _image); } } return(_image != null); } catch (Exception ex) { MapServerClass.ErrorLog(context, "MapRequest", ConfigTextStream.ExtractValue(_dataset._connection, "server"), _name, ex); return(false); } }
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); }
async public Task <bool> MapRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null) { return(false); } List <IWebServiceTheme> themes = Themes; if (themes == null) { return(false); } #region Check for visible Layers bool visFound = this.Themes.Where(l => l.Visible).Count() > 0; if (!visFound) { if (_image != null) { _image.Dispose(); _image = null; } return(true); } #endregion Check for visible Layers var serviceUrl = _dataset.ServiceUrl(); //IServiceRequestContext context = display.Map as IServiceRequestContext; var jsonExportMap = new JsonExportMap(); if (display?.Envelope != null) { var env = display.Envelope; jsonExportMap.BBox = $"{env.minx.ToDoubleString()},{env.miny.ToDoubleString()},{env.maxx.ToDoubleString()},{env.maxy.ToDoubleString()}"; } var sRef = display.SpatialReference ?? this.SpatialReference; if (sRef != null) { jsonExportMap.BBoxSRef = sRef.Name.ToLower().Replace("epsg:", ""); } jsonExportMap.Size = $"{display.iWidth},{display.iHeight}"; var layerIds = this.Themes .Where(l => l.Visible && (l.Class is IWebFeatureClass || l.Class is IWebRasterClass)) .Select(l => { if (l.Class is IWebFeatureClass) { return(((IWebFeatureClass)l.Class).ID); } if (l.Class is IWebRasterClass) { return(((IWebRasterClass)l.Class).ID); } return(String.Empty); }); jsonExportMap.Layers = $"show:{String.Join(",", layerIds)}"; var urlParameters = SerializeToUrlParameters(jsonExportMap); var response = await _dataset.TryPostAsync <JsonExportResponse>( serviceUrl .UrlAppendPath("export") .UrlAppendParameters("f=json") .UrlAppendParameters(urlParameters)); bool hasImage = false; if (!String.IsNullOrWhiteSpace(response.Href)) { var bm = WebFunctions.DownloadImage(response.Href); if (bm != null) { hasImage = true; _image = new GeorefBitmap(bm); if (response.Extent != null) { _image.Envelope = new Envelope(response.Extent.Xmin, response.Extent.Ymin, response.Extent.Xmax, response.Extent.Ymax); } _image.SpatialReference = sRef; } } if (!hasImage) { if (_image != null) { _image.Dispose(); _image = null; } return(false); } return(true); return(true); }
public bool MapRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null || _dataset._mapServer == null || _dataset._mapDescription == null || Themes == null) { return(false); } List <IWebServiceTheme> themes = Themes; #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 ISpatialReference sRef = (display.SpatialReference != null) ? display.SpatialReference.Clone() as ISpatialReference : null; int iWidth = display.iWidth; int iHeight = display.iHeight; if (BeforeMapRequest != null) { BeforeMapRequest(this, display, ref sRef, ref iWidth, ref iHeight); } try { #region Extent _dataset._mapDescription.MapArea.Extent = ArcServerHelper.EnvelopeN(display.Envelope); if (display.DisplayTransformation.UseTransformation) { _dataset._mapDescription.Rotation = display.DisplayTransformation.DisplayRotation; } #endregion #region Back/Transparent Color RgbColor backColor = ArcServerHelper.RgbColor(display.BackgroundColor); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.Color = backColor; fillSymbol.Outline = null; _dataset._mapDescription.BackgroundSymbol = fillSymbol; _dataset._mapDescription.TransparentColor = backColor; #endregion #region Layer Visibility LayerDescription[] layerDescriptions = _dataset._mapDescription.LayerDescriptions; foreach (LayerDescription layerDescr in layerDescriptions) { IWebServiceTheme theme = GetThemeByLayerId(layerDescr.LayerID.ToString()); if (theme == null) { continue; } layerDescr.Visible = theme.Visible; if (layerDescr.Visible) { foreach (int parentLayerId in _dataset.ParentLayerIds(layerDescr.LayerID)) { LayerDescription parent = _dataset.LayerDescriptionById(parentLayerId); if (parent != null) { parent.Visible = true; } } } } #endregion #region ImageDescription ImageType imgType = new ImageType(); imgType.ImageFormat = esriImageFormat.esriImagePNG24; imgType.ImageReturnType = esriImageReturnType.esriImageReturnURL; ImageDisplay imgDisp = new ImageDisplay(); imgDisp.ImageWidth = iWidth; imgDisp.ImageHeight = iHeight; imgDisp.ImageDPI = display.dpi; imgDisp.TransparentColor = backColor; ImageDescription imgDescr = new ImageDescription(); imgDescr.ImageDisplay = imgDisp; imgDescr.ImageType = imgType; #endregion MapImage mapImg = _dataset._mapServer.ExportMapImage(_dataset._mapDescription, imgDescr); if (mapImg != null && !String.IsNullOrEmpty(mapImg.ImageURL)) { System.Drawing.Bitmap bm = WebFunctions.DownloadImage(mapImg.ImageURL, _dataset._proxy, System.Net.CredentialCache.DefaultNetworkCredentials); if (bm != null) { _image = new GeorefBitmap(bm); _image.Envelope = new gView.Framework.Geometry.Envelope(new gView.Framework.Geometry.Envelope(display.Envelope)); _image.SpatialReference = display.SpatialReference; if (AfterMapRequest != null) { AfterMapRequest(this, display, _image); } } } else { if (_image != null) { _image.Dispose(); _image = null; } } return(_image != null); } catch (Exception ex) { //ArcIMSClass.ErrorLog(context, "MapRequest", server, service, ex); return(false); } }