public bool Open() { try { _opened = true; _themes.Clear(); MapServerConnection server = new MapServerConnection(ConfigTextStream.ExtractValue(_connection, "server")); string axl = "<ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO fields=\"true\" envelope=\"true\" renderer=\"false\" extensions=\"false\" gv_meta=\"true\" /></REQUEST></ARCXML>"; axl = server.Send(_name, axl, "BB294D9C-A184-4129-9555-398AA70284BC", ConfigTextStream.ExtractValue(_connection, "user"), ConfigTextStream.ExtractValue(_connection, "pwd")); XmlDocument doc = new XmlDocument(); doc.LoadXml(axl); if (_class == null) { _class = new MapServerClass(this); } double dpi = 96.0; XmlNode screen = doc.SelectSingleNode("//ENVIRONMENT/SCREEN"); if (screen != null) { if (screen.Attributes["dpi"] != null) { dpi = Convert.ToDouble(screen.Attributes["dpi"].Value.Replace(".", ",")); } } double dpm = (dpi / 0.0254); XmlNode spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE"); if (spatialReference != null) { if (spatialReference.Attributes["param"] != null) { SpatialReference sRef = new SpatialReference(); gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value); if (spatialReference.Attributes["name"] != null) { sRef.Name = spatialReference.Attributes["name"].Value; } _class.SpatialReference = sRef; } } else { XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS"); if (FeatureCoordSysNode != null) { if (FeatureCoordSysNode.Attributes["id"] != null) { _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value); } else if (FeatureCoordSysNode.Attributes["string"] != null) { _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value); } // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring" //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null) //{ //} } } foreach (XmlNode envelopeNode in doc.SelectNodes("//ENVELOPE")) { if (_envelope == null) { _envelope = (new Envelope(envelopeNode)).MakeValid(); } else { _envelope.Union((new Envelope(envelopeNode)).MakeValid()); } } foreach (XmlNode layerNode in doc.SelectNodes("//LAYERINFO[@id]")) { bool visible = true; ISpatialReference sRef = _class.SpatialReference; /* * spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE"); * if (spatialReference != null) * { * if (spatialReference.Attributes["param"] != null) * { * sRef = new SpatialReference(); * gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value); * * if (spatialReference.Attributes["name"] != null) * ((SpatialReference)sRef).Name = spatialReference.Attributes["name"].Value; * } * } * else * { * XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS"); * if (FeatureCoordSysNode != null) * { * if (FeatureCoordSysNode.Attributes["id"] != null) * { * sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value); * } * else if (FeatureCoordSysNode.Attributes["string"] != null) * { * sRef = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value); * } * * // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring" * //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null) * //{ * * //} * } * } */ if (layerNode.Attributes["visible"] != null) { bool.TryParse(layerNode.Attributes["visible"].Value, out visible); } IClass themeClass = null; IWebServiceTheme theme = null; if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "featureclass") { themeClass = new MapThemeFeatureClass(this, layerNode.Attributes["id"].Value); ((MapThemeFeatureClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; ((MapThemeFeatureClass)themeClass).fieldsFromAXL = layerNode.InnerXml; ((MapThemeFeatureClass)themeClass).SpatialReference = sRef; XmlNode FCLASS = layerNode.SelectSingleNode("FCLASS[@type]"); if (FCLASS != null) { ((MapThemeFeatureClass)themeClass).fClassTypeString = FCLASS.Attributes["type"].Value; } theme = LayerFactory.Create(themeClass, _class) as IWebServiceTheme; if (theme == null) { continue; } theme.Visible = visible; } else if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "image") { if (layerNode.SelectSingleNode("gv_meta/class/implements[@type='gView.Framework.Data.IPointIdentify']") != null) { themeClass = new MapThemeQueryableRasterClass(this, layerNode.Attributes["id"].Value); ((MapThemeQueryableRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; } else { themeClass = new MapThemeRasterClass(this, layerNode.Attributes["id"].Value); ((MapThemeRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; } theme = new WebServiceTheme( themeClass, themeClass.Name, layerNode.Attributes["id"].Value, visible, _class); } else { continue; } try { if (layerNode.Attributes["minscale"] != null) { theme.MinimumScale = Convert.ToDouble(layerNode.Attributes["minscale"].Value.Replace(".", ",")) * dpm; } if (layerNode.Attributes["maxscale"] != null) { theme.MaximumScale = Convert.ToDouble(layerNode.Attributes["maxscale"].Value.Replace(".", ",")) * dpm; } } catch { } _themes.Add(theme); } _state = DatasetState.opened; return(true); } catch (Exception ex) { _state = DatasetState.unknown; _class = null; return(false); } }
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); } }
async public Task <bool> Open(IServiceRequestContext context) { if (_class == null) { _class = new GeoServicesClass(this); } _class.Themes.Clear(); _themes = new List <IWebServiceTheme>(); string serviceUrl = ServiceUrl(); string user = ConfigTextStream.ExtractValue(ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(ConnectionString, "pwd"); var jsonMapService = await TryPostAsync <JsonMapService>($"{serviceUrl}?f=json"); var jsonLayers = await TryPostAsync <JsonLayers>($"{serviceUrl}/layers?f=json"); if (jsonMapService != null) { _class.Name = jsonMapService.MapName; if (jsonMapService.FullExtent != null) { _class.Envelope = new Envelope( jsonMapService.FullExtent.XMin, jsonMapService.FullExtent.YMin, jsonMapService.FullExtent.XMax, jsonMapService.FullExtent.YMax); } if (jsonMapService.SpatialReferenceInstance != null && jsonMapService.SpatialReferenceInstance.Wkid > 0) { var sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + jsonMapService.SpatialReferenceInstance.Wkid); this.SetSpatialReference(sRef); _class.SpatialReference = sRef; } if (jsonLayers?.Layers != null) { foreach (var jsonLayer in jsonLayers.Layers) { IClass themeClass = null; IWebServiceTheme theme = null; if (jsonLayer.Type.ToLower() == "feature layer") { themeClass = await GeoServicesFeatureClass.CreateAsync(this, jsonLayer); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } // ToDo Raster classes if (themeClass == null) { continue; } theme.Visible = true; //false; _class.Themes.Add(theme); } } } return(true); }
public bool Open(gView.MapServer.IServiceRequestContext context) { if (_class == null) { _class = new AGSClass(this); } #region Parameters string server = ConfigTextStream.ExtractValue(ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(ConnectionString, "service"); string user = ConfigTextStream.ExtractValue(ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(ConnectionString, "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; } #endregion try { _proxy = ProxySettings.Proxy(server); _themes.Clear(); _parentIds.Clear(); _mapServer = new gView.Interoperability.AGS.Proxy.MapServer(service); _mapServer.Proxy = gView.Framework.Web.ProxySettings.Proxy(service); MapServerInfo msi = _mapServer.GetServerInfo(_mapServer.GetDefaultMapName()); _mapDescription = msi.DefaultMapDescription; MapLayerInfo[] mapLayerInfos = msi.MapLayerInfos; foreach (MapLayerInfo layerInfo in mapLayerInfos) { if (layerInfo.Extent is EnvelopeN) { EnvelopeN env = (EnvelopeN)layerInfo.Extent; if (_envelope == null) { _envelope = new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax); } else { _envelope.Union(new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax)); } } CalcParentLayerIds(mapLayerInfos, layerInfo.LayerID); IClass themeClass = null; IWebServiceTheme theme = null; LayerDescription ld = LayerDescriptionById(layerInfo.LayerID); if (ld == null) { continue; } if (layerInfo.LayerType == "Feature Layer") { #region Geometry Type (Point, Line, Polygon) geometryType geomType = geometryType.Unknown; if (layerInfo.Fields != null) { foreach (Proxy.Field fieldInfo in layerInfo.Fields.FieldArray) { if (fieldInfo.Type == esriFieldType.esriFieldTypeGeometry && fieldInfo.GeometryDef != null) { switch (fieldInfo.GeometryDef.GeometryType) { case esriGeometryType.esriGeometryMultipoint: case esriGeometryType.esriGeometryPoint: geomType = geometryType.Point; break; case esriGeometryType.esriGeometryPolyline: geomType = geometryType.Polyline; break; case esriGeometryType.esriGeometryPolygon: geomType = geometryType.Polygon; break; case esriGeometryType.esriGeometryMultiPatch: break; } } } } #endregion themeClass = new AGSThemeFeatureClass(this, layerInfo, geomType); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } else if (layerInfo.LayerType == "Raster Layer" || layerInfo.LayerType == "Raster Catalog Layer") { themeClass = new AGSThemeRasterClass(this, layerInfo); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } else { MapLayerInfo parentLayer = MapLayerInfoById(mapLayerInfos, layerInfo.ParentLayerID); if (parentLayer != null && parentLayer.LayerType == "Annotation Layer") { themeClass = new AGSThemeFeatureClass(this, layerInfo, geometryType.Polygon); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } } if (theme != null) { theme.MinimumScale = layerInfo.MaxScale; theme.MaximumScale = layerInfo.MinScale; theme.Visible = ld.Visible; _themes.Add(theme); } } _state = DatasetState.opened; return(true); } catch (Exception ex) { _state = DatasetState.unknown; _errMsg = ex.Message; return(false); } }