public MapServerDataset(string connection, string name) { _connection = connection; _name = name; _class = new MapServerClass(this); }
public static void CopyWebThemeProperties(IWebServiceClass wsClass, ILayer master) { if (wsClass == null || master == null) { return; } foreach (IWebServiceTheme theme in wsClass.Themes) { if (theme == null) { continue; } if (theme.Title == master.Title) { if (master is IFeatureLayer) { theme.FilterQuery = ((IFeatureLayer)master).FilterQuery; theme.FeatureRenderer = ((IFeatureLayer)master).FeatureRenderer; theme.SelectionRenderer = ((IFeatureLayer)master).SelectionRenderer; theme.LabelRenderer = ((IFeatureLayer)master).LabelRenderer; } theme.Visible = master.Visible; break; } } }
internal bool AppendGDIServers(IMap map) { if (map == null) { return(true); } foreach (IDatasetElement element in map.MapElements) { if (element != null && element.Class is IWebServiceClass) { IWebServiceClass wClass = (IWebServiceClass)element.Class; if (wClass.Dataset == null || wClass.Dataset.ConnectionString == null) { continue; } string connString = wClass.Dataset.ConnectionString.ToLower(); string server = ConfigTextStream.ExtractValue(connString, "server"); if (String.IsNullOrEmpty(server)) { server = ConfigTextStream.ExtractValue(connString, "wms"); } if (String.IsNullOrEmpty(server)) { server = ConfigTextStream.ExtractValue(connString, "wfs"); } if (String.IsNullOrEmpty(server)) { server = ConfigTextStream.ExtractValue(connString, "url"); } if (String.IsNullOrEmpty(server)) { server = ConfigTextStream.ExtractValue(connString, "uri"); } if (String.IsNullOrEmpty(server)) { continue; // eigentlich ungültig... solte Exception werfen... } if (server.StartsWith("http://") || server.StartsWith("https://")) { Uri uri = new Uri(server); server = uri.Host; } //if (!GDIServers.Contains(server) && // GDIServers.Count >= _maxGDIServers) ret = false; GDIServers.Add(server); } } //return (GDIServers.Count <= _maxGDIServers); return(true); }
public static List <ILayer> FindAdditionalWebServiceLayers(IWebServiceClass wsClass, List <ILayer> layers) { if (wsClass == null || layers == null) { return(layers); } List <ILayer> clonedLayers = ListOperations <ILayer> .Clone(layers); foreach (IWebServiceTheme theme in wsClass.Themes) { clonedLayers.Remove(theme); } return(clonedLayers); }
public static bool HasVisibleThemes(IWebServiceClass wsClass) { if (wsClass == null) { return(false); } foreach (IWebServiceTheme theme in wsClass.Themes) { if (theme == null) { continue; } if (theme.Visible) { return(true); } } return(false); }
public static IWebServiceClass CloneNonVisibleWebServiceClass(IWebServiceClass wsClass) { if (wsClass == null) { return(null); } IWebServiceClass clone = wsClass.Clone() as IWebServiceClass; if (clone == null) { return(null); } foreach (IWebServiceTheme theme in clone.Themes) { if (theme == null) { continue; } theme.Visible = false; } return(clone); }
public void Load(IPersistStream stream) { this.ConnectionString = (string)stream.Load("ConnectionString", ""); _class = new MapServerClass(this); Open(); }
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); } }
async override public Task <bool> RefreshMap(DrawPhase phase, ICancelTracker cancelTracker) { base.ResetRequestExceptions(); if (_canvas != null && phase == DrawPhase.Graphics) { return(true); } this.ZoomTo(m_actMinX, m_actMinY, m_actMaxX, m_actMaxY); if (cancelTracker == null) { cancelTracker = new CancelTracker(); } using (var datasetCachingContext = new DatasetCachingContext(this)) using (var geoTransformer = GeometricTransformerFactory.Create()) { //geoTransformer.ToSpatialReference = this.SpatialReference; if (_bitmap == null) { _bitmap = Current.Engine.CreateBitmap(iWidth, iHeight, PixelFormat.Rgba32); } _canvas = _bitmap.CreateCanvas(); //_canvas.CompositingMode = CompositingMode.SourceCopy; //this.dpi = _canvas.DpiX * this.ScaleSymbolFactor; if (BackgroundColor.A != 0 && !Display.MakeTransparent) { using (var brush = Current.Engine.CreateSolidBrush(BackgroundColor)) { _canvas.FillRectangle(brush, new CanvasRectangle(0, 0, _bitmap.Width, _bitmap.Height)); } } if (phase == DrawPhase.All || phase == DrawPhase.Geography) { this.GeometricTransformer = geoTransformer; // Thread für MapServer Datasets starten... #region WebServiceLayer List <IWebServiceLayer> webServices; if (this.TOC != null) { webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers); } else { webServices = new List <IWebServiceLayer>(); foreach (IDatasetElement layer in this.MapElements) { if (!(layer is IWebServiceLayer)) { continue; } if (((ILayer)layer).Visible) { webServices.Add((IWebServiceLayer)layer); } } } int webServiceOrder = 0, webServiceOrder2 = 1; foreach (IWebServiceLayer element in webServices) { if (!element.Visible) { continue; } IWebServiceLayer wsLayer = LayerFactory.Create(element.WebServiceClass.Clone() as IClass, element) as IWebServiceLayer; if (wsLayer == null || wsLayer.WebServiceClass == null) { continue; } wsLayer.WebServiceClass.SpatialReference = this.SpatialReference; List <IWebServiceClass> additionalWebServices = new List <IWebServiceClass>(); if (BeforeRenderLayers != null) { List <ILayer> modLayers = new List <ILayer>(); foreach (IWebServiceTheme theme in wsLayer.WebServiceClass.Themes) { if (theme is ILayer) { modLayers.Add(theme); } } BeforeRenderLayers(this, modLayers); foreach (ILayer additionalLayer in MapServerHelper.FindAdditionalWebServiceLayers(wsLayer.WebServiceClass, modLayers)) { IWebServiceClass additionalWebService = MapServerHelper.CloneNonVisibleWebServiceClass(wsLayer.WebServiceClass); MapServerHelper.CopyWebThemeProperties(additionalWebService, additionalLayer); if (MapServerHelper.HasVisibleThemes(additionalWebService)) { additionalWebServices.Add(additionalWebService); } } } var srt = new RenderServiceRequest(this, wsLayer, webServiceOrder++); srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished); //Thread thread = new Thread(new ThreadStart(srt.ImageRequest)); m_imageMerger.max++; //thread.Start(); var task = srt.ImageRequest(); // start Task and continue... foreach (IWebServiceClass additionalWebService in additionalWebServices) { wsLayer = LayerFactory.Create(additionalWebService, element) as IWebServiceLayer; if (wsLayer == null || wsLayer.WebServiceClass == null) { continue; } wsLayer.WebServiceClass.SpatialReference = this.SpatialReference; srt = new RenderServiceRequest(this, wsLayer, (++webServiceOrder2) + webServices.Count); srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished); //thread = new Thread(new ThreadStart(srt.ImageRequest)); m_imageMerger.max++; //thread.Start(); var additionalTask = srt.ImageRequest(); // start task and continue... } } #endregion List <ILayer> layers = new List <ILayer>(); if (this.TOC != null) { if (this.GetType().Equals(typeof(ServiceMap))) { layers = ListOperations <ILayer> .Swap(this.TOC.Layers); } else { layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers); } } else { layers = new List <ILayer>(); foreach (IDatasetElement layer in this.MapElements) { if (!(layer is ILayer)) { continue; } if (((ILayer)layer).Visible) { layers.Add((ILayer)layer); } } } if (BeforeRenderLayers != null) { // // Kopie der Original Layer erstellen // ACHTUNG: Renderer werden nicht kopiert! // dürfen in BeforeRenderLayers nicht verändert werden... // Eine zuweisung eines neuen Renderers ist jedoch legitim. // List <ILayer> modLayers = new List <ILayer>(); foreach (IDatasetElement element in layers) { if (!(element is ILayer) || element is IWebServiceTheme) { continue; } ILayer layer = (ILayer)element; if (layer.MinimumScale > 1 && layer.MinimumScale > this.mapScale) { continue; } if (layer.MaximumScale > 1 && layer.MaximumScale < this.mapScale) { continue; } modLayers.Add(LayerFactory.Create(layer.Class, layer)); } BeforeRenderLayers(this, modLayers); layers = modLayers; } //layers = ModifyLayerList(layers); List <IFeatureLayer> labelLayers = this.OrderedLabelLayers(layers); LabelEngine.Init(this.Display, false); foreach (IDatasetElement element in layers) { if (!cancelTracker.Continue) { break; } if (!(element is ILayer)) { continue; } ILayer layer = (ILayer)element; //if (_ceckLayerVisibilityBeforeDrawing) //{ // if (!LayerIsVisible(layer)) continue; //} if (!layer.Visible) { continue; } if (!layer.RenderInScale(this)) { continue; } #if (DEBUG) //Logger.LogDebug("Drawing Layer:" + element.Title); #endif SetGeotransformer((ILayer)element, geoTransformer); if (layer is IFeatureLayer) { if (layer.Class?.Dataset is IFeatureCacheDataset) { await((IFeatureCacheDataset)layer.Class.Dataset).InitFeatureCache(datasetCachingContext); } IFeatureLayer fLayer = (IFeatureLayer)layer; if (fLayer.FeatureRenderer == null && ( fLayer.LabelRenderer == null || (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode != LabelRenderMode.RenderWithFeature) )) { //continue; } else { RenderFeatureLayer rlt = new RenderFeatureLayer(this, datasetCachingContext, fLayer, cancelTracker, new FeatureCounter()); if (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode == LabelRenderMode.RenderWithFeature) { rlt.UseLabelRenderer = true; } else { rlt.UseLabelRenderer = labelLayers.IndexOf(fLayer) == 0; // letzten Layer gleich mitlabeln } if (rlt.UseLabelRenderer) { labelLayers.Remove(fLayer); } await rlt.Render(); } //thread = new Thread(new ThreadStart(rlt.Render)); //thread.Start(); } if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null) { IRasterLayer rLayer = (IRasterLayer)layer; if (rLayer.RasterClass.Polygon == null) { continue; } IEnvelope dispEnvelope = this.Envelope; if (Display.GeometricTransformer != null) { dispEnvelope = ((IGeometry)Display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope; } if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(rLayer.RasterClass.Polygon, dispEnvelope)) { if (rLayer.Class is IParentRasterLayer) { await DrawRasterParentLayer((IParentRasterLayer)rLayer.Class, cancelTracker, rLayer); } else { RenderRasterLayer rlt = new RenderRasterLayer(this, rLayer, rLayer, cancelTracker); await rlt.Render(); //thread = new Thread(new ThreadStart(rlt.Render)); //thread.Start(); } } } // Andere Layer (zB IRasterLayer) #if (DEBUG) //Logger.LogDebug("Finished drawing layer: " + element.Title); #endif } // Label Features if (labelLayers.Count != 0) { foreach (IFeatureLayer fLayer in labelLayers) { this.SetGeotransformer(fLayer, geoTransformer); if (!fLayer.Visible) { continue; } RenderLabel rlt = new RenderLabel(this, fLayer, cancelTracker, new FeatureCounter()); await rlt.Render(); } } LabelEngine.Draw(this.Display, cancelTracker); LabelEngine.Release(); if (cancelTracker.Continue) { while (m_imageMerger.Count < m_imageMerger.max) { await Task.Delay(10); } } if (_drawScaleBar) { m_imageMerger.mapScale = this.mapScale; m_imageMerger.dpi = this.dpi; } #if (DEBUG) //Logger.LogDebug("Merge Images"); #endif m_imageMerger.Merge(_bitmap, this.Display); m_imageMerger.Clear(); #if (DEBUG) //Logger.LogDebug("Merge Images Finished"); #endif } if (phase == DrawPhase.All || phase == DrawPhase.Graphics) { foreach (IGraphicElement grElement in Display.GraphicsContainer.Elements) { grElement.Draw(Display); } } base.AppendRequestExceptionsToImage(); if (_canvas != null) { _canvas.Dispose(); } _canvas = null; this.GeometricTransformer = null; } return(this.HasRequestExceptions == false); }