Esempio n. 1
0
 private void AddReportDataToLinesTable(LinesLayer layer, SpatialDataTable linesTable)
 {
     foreach (IReportScriptContext sc in ForeachReportDataRow())
     {
         AddLinesRow(layer, linesTable, sc);
     }
 }
Esempio n. 2
0
 private void AddReportDataToPointsTable(PointsLayer layer, SpatialDataTable pointsTable)
 {
     foreach (IReportScriptContext sc in ForeachReportDataRow())
     {
         AddPointsRow(layer, pointsTable, sc);
     }
 }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
 private void AddCustomDataToLinesTable(LinesLayer layer, SpatialDataTable linesTable)
 {
     using (var dtCustom = MakeCustomData(layer.RecordSource))
         foreach (IReportScriptContext sc in DataTableReportScriptContext.Foreach(dtCustom))
         {
             AddLinesRow(layer, linesTable, sc);
         }
 }
Esempio n. 5
0
        /// <summary>
        /// Gets the data table where each row describes a point that is to be plotted on the map.
        /// The columns of the table are as follows:
        /// <list type="bullet">
        ///
        /// <item><term>Latitude</term><description>Numeric latitude value.</description></item>
        /// <item><term>Longitude</term><description>Numeric longitude value.</description></item>
        /// <item><term>Caption</term><description>Point caption text.</description></item>
        ///
        /// </list>
        /// </summary>
        /// <param name="designTime"></param>
        /// <returns></returns>
        private List <SpatialDataTable> GetMapDatas(bool designTime)
        {
            List <SpatialDataTable> tables = new List <SpatialDataTable>();

            foreach (LayerBase l in Layers.FindAll((ll) => ll.Visible))
            {
                if (l is PointsLayer)
                {
                    var dtPoints = new SpatialDataTable(typeof(PointsDataRow), l.Key);
                    if (designTime)
                    {
                        AddSampleDataToPointsTable((PointsLayer)l, dtPoints);
                    }
                    else if (!string.IsNullOrEmpty(l.RecordSource))
                    {
                        AddCustomDataToPointsTable((PointsLayer)l, dtPoints);
                    }
                    else
                    {
                        AddReportDataToPointsTable((PointsLayer)l, dtPoints);
                    }
                    tables.Add(dtPoints);
                }
                else if (l is LinesLayer)
                {
                    var dtLines = new SpatialDataTable(typeof(LinesDataRow), l.Key);
                    if (designTime)
                    {
                        AddSampleDataToLinesTable((LinesLayer)l, dtLines);
                    }
                    else if (!string.IsNullOrEmpty(l.RecordSource))
                    {
                        AddCustomDataToLinesTable((LinesLayer)l, dtLines);
                    }
                    else
                    {
                        AddReportDataToLinesTable((LinesLayer)l, dtLines);
                    }
                    tables.Add(dtLines);
                }
                else if (l is KmlLayer)
                {
                    // nothing to do
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false, "unknown layer type");
                }
            }
            return(tables);
        }
Esempio n. 6
0
        private void AddSampleDataToLinesTable(LinesLayer layer, SpatialDataTable dt)
        {
            int nplines = 15 / Layers.CountAll((l) => l.Visible && l is LinesLayer);
            var rnd     = new Random(Layers.IndexOf(layer)); // this ensures same data for same layer but different points for different layers

            for (int i = 0; i < nplines; ++i)
            {
                LinesDataRow row       = (LinesDataRow)dt.NewRow();
                var          lineStyle = layer.LineStyle;
                row.Latitude0  = rnd.Next(SampleLatMin, SampleLatMax);
                row.Longitude0 = rnd.Next(SampleLonMin, SampleLonMax);
                row.Latitude1  = rnd.Next(SampleLatMin, SampleLatMax);
                row.Longitude1 = rnd.Next(SampleLonMin, SampleLonMax);
                row.LineStroke = lineStyle.StrokeColor;
                row.DashStyle  = lineStyle.DashStyle;
                dt.Add(row);
            }
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
        private void AddSampleDataToPointsTable(PointsLayer layer, SpatialDataTable dt)
        {
            int npoints = 15 / Layers.CountAll((l) => l.Visible && l is PointsLayer);
            var rnd     = new Random(Layers.IndexOf(layer)); // this ensures same data for same layer but different points for different layers

            for (int i = 0; i < npoints; ++i)
            {
                PointsDataRow row         = (PointsDataRow)dt.NewRow();
                var           markerStyle = layer.MarkerStyle;
                row.Latitude     = rnd.Next(SampleLatMin, SampleLatMax);
                row.Longitude    = rnd.Next(SampleLonMin, SampleLonMax);
                row.Caption      = string.Format(CultureInfo.InvariantCulture, "{0} {1}", layer.Caption, i);
                row.MarkerSize   = MarkerStyle.c_SizeValue;
                row.MarkerStroke = markerStyle.StrokeColor;
                row.MarkerFill   = markerStyle.FillColor;
                row.MarkerShape  = markerStyle.Shape;
                row.Font         = markerStyle.Font;
                row.TextColor    = markerStyle.TextColor;
                dt.Add(row);
            }
        }
Esempio n. 9
0
        private Image BuildMap(List <SpatialDataTable> datas, bool designTime)
        {
            if (designTime)
            {
                foreach (KmlLayer layer in Layers.FindAll((l) => l is KmlLayer))
                {
                    layer.RemoveFromOwner();
                }
            }
            else
            {
                var calcLayers = GetCalculatedKmlLayers();
                calcLayers.ForEach((l) => l.RemoveFromOwner());
            }

            _c1mapper.ClearMarks();
            _c1mapper.ResetBoundingPoints();

            _c1mapper.Width  = (this.Width * ScreenDpiX) / TwipsIn;
            _c1mapper.Height = (this.Height * ScreenDpiY) / TwipsIn;

            // 1st pass: add KML layers, retrieve coordinates from other layers for auto-zoom/center:
            foreach (LayerBase layer in Layers.FindAll((l) => l.Visible && (l is KmlLayer || l.Track)))
            {
                if (layer is KmlLayer)
                {
                    ((KmlLayer)layer).SetKmlOnOwner();
                }
                else // layer.Track
                {
                    SpatialDataTable dt = datas.Find((t) => t.LayerKey == layer.Key);
                    dt.ForEach((row) => row.ForAllPoints((lon, lat) => _c1mapper.AddBoundingPoint(lon, lat)));
                }
            }

            // now we can auto zoom/center as all relevant spatial data has been given to the mapper:
            _c1mapper.DoCenterAndZoom();

            // 2nd pass: add points/lines layers:
            foreach (LayerBase layer in Layers.FindAll((l) => l.Visible && !(l is KmlLayer)))
            {
                // considering that no of layers should not be large, this is ok:
                SpatialDataTable dt = datas.Find((t) => t.LayerKey == layer.Key);
                if (dt.RowType == typeof(PointsDataRow))
                {
                    var l = (PointsLayer)layer;
                    // clustering:
                    var clusterDist    = l.ClusterDistance;
                    var maxClusterSize = 0;
                    if (clusterDist > 0)
                    {
                        for (int i = 0; i < dt.Count; ++i)
                        {
                            var r = (PointsDataRow)dt[i];
                            for (int j = dt.Count - 1; j > i; --j)
                            {
                                var r2 = (PointsDataRow)dt[j];
                                if (_c1mapper.DistancePix(r.Longitude, r.Latitude, r2.Longitude, r2.Latitude) < clusterDist)
                                {
                                    maxClusterSize = Math.Max(maxClusterSize, ++r.Count);
                                    dt.RemoveAt(j);
                                }
                            }
                        }
                    }
                    // spread styles among clusters:
                    var styleCount = l.ClusterStyles != null ? l.ClusterStyles.Count : 0;
                    var q          = l.ClusterDistribution == ScaleType.Linear ? ((styleCount - 1f) / (maxClusterSize - 2f)) : 1f;
                    // add clustered points to the map:
                    dt.ForEach((row) =>
                    {
                        PointsDataRow r = (PointsDataRow)row;
                        if (r.Count > 1)
                        {
                            r.Caption = r.Count.ToString(CultureInfo.InvariantCulture);
                            if (styleCount > 0)
                            {
                                // we have a style to apply:
                                int idx;
                                if (l.ClusterDistribution == ScaleType.Linear)
                                {
                                    idx = (int)Math.Round((r.Count - 2) * q);
                                }
                                else
                                {
                                    var t = Math.Log(r.Count - 1, maxClusterSize - 1);
                                    if (double.IsNaN(t))
                                    {
                                        t = 0;
                                    }
                                    idx = (int)Math.Round(t * (styleCount - 1d));
                                }
                                var s         = l.ClusterStyles[idx];
                                r.Font        = s.Font;
                                r.TextColor   = s.TextColor;
                                r.MarkerShape = s.Shape;
                                // todo: eval expr here, allow to use Count?
                                r.MarkerSize   = Maps.Util.GetDouble(s.SizeExpr, MarkerStyle.c_SizeValue);
                                r.MarkerStroke = s.StrokeColor;
                                r.MarkerFill   = s.FillColor;
                            }
                        }
                        _c1mapper.DrawPoint(layer.Key, r.Longitude, r.Latitude, r.Caption, r.Font, r.TextColor, r.MarkerShape, r.MarkerSize, r.MarkerStroke, r.MarkerFill);
                    }
                               );
                }
                else if (dt.RowType == typeof(LinesDataRow))
                {
                    // add lines to the map:
                    dt.ForEach((row) =>
                    {
                        LinesDataRow r = (LinesDataRow)row;
                        _c1mapper.DrawLine(layer.Key, r.Longitude0, r.Latitude0, r.Longitude1, r.Latitude1, r.LineStroke, r.DashStyle, r.LineThickness);
                    }
                               );
                }
            }

            // done:
            return(_c1mapper.GetImage(TargetDpi, TargetDpi));
        }