private void AddPointsRow(PointsLayer layer, SpatialDataTable pointsTable, IReportScriptContext sc) { bool markVisible = Maps.Util.GetBool(ParentReport.Evaluate(layer.MarkerVisibleExpr, sc), true); if (markVisible) { bool pointsOk; var loc = GetLocations(layer, sc, out pointsOk)[0]; // If we got a location, add it (tbd: report misses?): if (pointsOk) { var row = (PointsDataRow)pointsTable.NewRow(); // evaluate marker style var markerStyle = EvalStyleExpr <MarkerStyle>(layer.MarkerStyleExpr, MarkerStyles, ExternalMarkerStyle, layer.MarkerStyle, sc); row.Latitude = loc.Latitude; row.Longitude = loc.Longitude; row.Caption = Maps.Util.GetString(ParentReport.Evaluate(markerStyle.CaptionExpr, sc)); row.MarkerSize = Maps.Util.GetDouble(ParentReport.Evaluate(markerStyle.SizeExpr, sc), MarkerStyle.c_SizeValue); row.MarkerStroke = markerStyle.StrokeColor; row.MarkerFill = markerStyle.FillColor; row.MarkerShape = markerStyle.Shape; row.Font = markerStyle.Font; row.TextColor = markerStyle.TextColor; pointsTable.Add(row); } } }
private TStyle EvalStyleExpr <TStyle>( string styleExpr, MapOwnedCollectionBase <TStyle> styles, Func <string, TStyle> externalStyleGetter, TStyle defaultStyle, IReportScriptContext sc) where TStyle : MapStyleBase { TStyle style = null; int intIdx; var strIdx = Maps.Util.GetIndex(ParentReport.Evaluate(styleExpr, sc), out intIdx); if (!string.IsNullOrEmpty(strIdx)) { style = styles[strIdx]; if (style == null && externalStyleGetter != null) { style = externalStyleGetter(strIdx); } } if (style == null && intIdx >= 0 && intIdx < styles.Count) { style = styles[intIdx]; } if (style == null) { style = defaultStyle; } return(style); }
/// <summary> /// Gets the geographical location of a point based on spatial data or location expression. /// If a data row is provided (not null), data (location expressions or spatial data) /// is assumed to be actual fields in that row, and is NOT evaluated. /// If the data row is null, data is evaluated against the ParentReport, so may /// constitute expressions. /// </summary> /// <param name="layer">The map layer for which location is retrieved.</param> /// <param name="source">The data row (of the layer's custom data source) or null.</param> /// <param name="allOk">OUT: true if all points have numeric coordinates, false if at least one is a NaN.</param> /// <returns>Location, in geographical coordinates (X is longitude, Y is latitude).</returns> private List <LonLat <double> > GetLocations(LayerBase layer, IReportScriptContext context, out bool allOk) { allOk = true; Func <LonLat <string>, List <string>, LonLat <double> > getLoc = (lonlat, locExpr) => { if (locExpr != null) { // Make address string: var sb = new StringBuilder(); for (int i = 0; i < locExpr.Count; ++i) { string s = ParentReport.Evaluate(locExpr[i], context) as string; if (!string.IsNullOrEmpty(s)) { sb.Append(s); if (i < locExpr.Count - 1) { sb.Append(", "); } } } return(_geocoder.GetLocation(sb.ToString())); } else { return(new LonLat <double>( Maps.Util.GetDouble(ParentReport.Evaluate(lonlat.Longitude, context)), Maps.Util.GetDouble(ParentReport.Evaluate(lonlat.Latitude, context)))); } }; var locExprs = layer.PointsLocationExpressions; var lonlats = layer.PointsLocations; var points = new List <LonLat <double> >(lonlats.Count); for (int i = 0; i < lonlats.Count; ++i) { LonLat <double> pt = getLoc(lonlats[i], locExprs[i]); points.Add(pt); if (allOk && (double.IsNaN(pt.Longitude) || double.IsNaN(pt.Latitude))) { allOk = false; } } return(points); }
private void AddLinesRow(LinesLayer layer, SpatialDataTable linesTable, IReportScriptContext sc) { bool pointsOk; var locs = GetLocations(layer, sc, out pointsOk); if (pointsOk) { var row = (LinesDataRow)linesTable.NewRow(); var lineStyle = EvalStyleExpr <LineStyle>(layer.LineStyleExpr, LineStyles, ExternalLineStyle, layer.LineStyle, sc); row.Longitude0 = locs[0].Longitude; row.Latitude0 = locs[0].Latitude; row.Longitude1 = locs[1].Longitude; row.Latitude1 = locs[1].Latitude; row.LineStroke = lineStyle.StrokeColor; row.DashStyle = lineStyle.DashStyle; row.LineThickness = Maps.Util.GetDouble(ParentReport.Evaluate(lineStyle.ThicknessExpr, sc), LineStyle.c_LineThickness); linesTable.Add(row); } }