protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers) { // Draw shape like area and point base.DrawCore(canvas, labelsInAllLayers); // Draw annotation label if (!ZoomLevelSet.CustomZoomLevels.Any(z => z.CustomStyles.OfType <CompositeStyle>().SelectMany(c => c.Styles).Any(s => s is TextStyle))) { Collection <Feature> annotationFeatures = ((TobinBasFeatureSource)FeatureSource).AnnotationFeatures; foreach (var item in annotationFeatures) { float textSize = float.Parse(item.ColumnValues["TextSize"].ToString()); double latDiff = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(textSize, DistanceUnit.Feet); PointShape startPoint = (PointShape)item.GetShape(); PointShape endPoint = new PointShape(startPoint.X, startPoint.Y + latDiff); float fontSize = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, startPoint, canvas.Width, canvas.Height).Y - ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, endPoint, canvas.Width, canvas.Height).Y; if (fontSize > minAnnotationFontSize) { TextStyle textStyle = new TextStyle("TextString", new GeoFont(), new GeoSolidBrush(GeoColor.SimpleColors.Black)); textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels; textStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping; textStyle.YOffsetInPixel = 1 * fontSize; textStyle.RotationAngle = double.Parse(item.ColumnValues["TextAngle"]); textStyle.Font = new GeoFont("Arial", fontSize); textStyle.Draw(new Collection <Feature> { item }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers); } } } }
protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers) { TextStyle clonedStyle = new TextStyle(this.TextColumnName, this.Font, this.TextSolidBrush); clonedStyle.HaloPen = this.HaloPen; clonedStyle.Mask = this.Mask; clonedStyle.GridSize = this.GridSize; clonedStyle.OverlappingRule = this.OverlappingRule; clonedStyle.DuplicateRule = this.DuplicateRule; float fontSize = Convert.ToInt32(50000 / canvas.CurrentScale); if (fontSize < minFontSize) { fontSize = minFontSize; } else if (fontSize > maxFontSize) { fontSize = maxFontSize; } clonedStyle.Font = new GeoFont(clonedStyle.Font.FontName, fontSize, clonedStyle.Font.Style); clonedStyle.Draw(features, canvas, labelsInThisLayer, labelsInAllLayers); }
/// <summary> /// Here in the DrawCore we cluster the features /// </summary> protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers) { // We get the scale to determine the grid. This scale property should really be on the Canvas! double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit); // Setup our grid for clustering the points. This is where we specify our cell size in pixels MapSuiteTileMatrix mapSuiteTileMatrix = new MapSuiteTileMatrix(scale, cellSize, cellSize, canvas.MapUnit); // Pass in the current extent to get our grid cells. All points in these cells will be consolidated IEnumerable <TileMatrixCell> tileMatricCells = mapSuiteTileMatrix.GetContainedCells(canvas.CurrentWorldExtent); // Create an unused features list, as we add them to clusters we will remove them from here // This is just for speed so we don't re-test lots of already associated features Dictionary <string, string> unusedFeatures = new Dictionary <string, string>(); foreach (Feature feature in features) { if (feature.GetWellKnownType() != WellKnownType.Point && feature.GetWellKnownType() != WellKnownType.Multipoint) { continue; } unusedFeatures.Add(feature.Id, feature.Id); } // Loop through each cell and find the features that fit inside of it foreach (TileMatrixCell cell in tileMatricCells) { int featureCount = 0; MultipointShape tempMultiPointShape = new MultipointShape(); foreach (Feature feature in features) { // Make sure the feature has not been used in another cluster if (unusedFeatures.ContainsKey(feature.Id)) { // Check if the cell contains the feature if (cell.BoundingBox.Contains(feature.GetBoundingBox())) { featureCount++; unusedFeatures.Remove(feature.Id); if (feature.GetWellKnownType() == WellKnownType.Multipoint) { MultipointShape multipointShape = feature.GetShape() as MultipointShape; foreach (var item in multipointShape.Points) { tempMultiPointShape.Points.Add(item); } } else { tempMultiPointShape.Points.Add(feature.GetShape() as PointShape); } } } } if (featureCount > 0) { // Add the feature count to the new feature we created. The feature will be placed // at the center of gravity of all the clustered features of the cell we created. Dictionary <string, string> featureValues = new Dictionary <string, string>(); featureValues.Add("FeatureCount", featureCount.ToString(CultureInfo.InvariantCulture)); bool isMatch = false; for (int i = 0; i < classBreakPoints.Count - 1; i++) { var startItem = classBreakPoints.ElementAt(i); var endItem = classBreakPoints.ElementAt(i + 1); if (featureCount >= startItem.Key && featureCount < endItem.Key) { // Draw the point shape startItem.Value.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); isMatch = true; break; } } if (!isMatch && featureCount >= classBreakPoints.LastOrDefault().Key) { classBreakPoints.LastOrDefault().Value.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); } if (featureCount != 1) { // Draw the text style to show how many feaures are consolidated in the cluster textSytle.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); } } } }
protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas , Collection <SimpleCandidate> labelsInThisLayer , Collection <SimpleCandidate> labelsInAllLayers) { foreach (Feature feature in features) { string fieldValue = string.Empty; if (feature.ColumnValues.ContainsKey(ColumnName)) { fieldValue = feature.ColumnValues[ColumnName].Trim(); } ValueItem valueItem = GetValueItem(fieldValue); Feature[] tmpFeatures = new Feature[1] { feature }; if (valueItem.CustomStyles.Count == 0) { if (valueItem.DefaultAreaStyle != null) { valueItem.DefaultAreaStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); } if (valueItem.DefaultLineStyle != null) { valueItem.DefaultLineStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); } if (valueItem.DefaultTextStyle != null && tmpFeatures.Any(f => f.ColumnValues.ContainsKey("NoteText") && !String.IsNullOrEmpty(f.ColumnValues["NoteText"]))) { valueItem.DefaultTextStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); } else if (valueItem.DefaultPointStyle != null) { if (feature.ColumnValues.ContainsKey("LinkFileName") && !string.IsNullOrEmpty(feature.ColumnValues["LinkFileName"])) { if (valueItem.DefaultTextStyle.Name == "FileLinkStyle" && valueItem.DefaultPointStyle.Name == "FileLinkStyle") { TextStyle textStyle = valueItem.DefaultTextStyle; textStyle.PointPlacement = PointPlacement.LowerCenter; if (valueItem.DefaultPointStyle.CustomPointStyles.Count > 0) { textStyle.YOffsetInPixel = -(valueItem.DefaultPointStyle.CustomPointStyles.FirstOrDefault().SymbolSize / 2); } else { textStyle.YOffsetInPixel = -(valueItem.DefaultPointStyle.SymbolSize / 2); } if (textStyle.CustomTextStyles.Count > 0) { foreach (var item in textStyle.CustomTextStyles) { item.YOffsetInPixel = textStyle.YOffsetInPixel; } } Feature cloneFeature = feature.CloneDeep(); string path = cloneFeature.ColumnValues["LinkFileName"]; string columnValue = cloneFeature.ColumnValues["LinkFileName"]; if (columnValue.Contains("||")) { int index = columnValue.IndexOf("||"); path = columnValue.Substring(index + 2, columnValue.Length - index - 2); } string fileName = Path.GetFileName(path); cloneFeature.ColumnValues["LinkFileName"] = fileName; Feature[] fileLinkFeatures = new Feature[1] { cloneFeature }; textStyle.Draw(fileLinkFeatures, canvas, labelsInThisLayer, labelsInAllLayers); valueItem.DefaultPointStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); } } else { valueItem.DefaultPointStyle.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); Console.Write(""); } } } else { foreach (Style style in valueItem.CustomStyles) { style.Draw(tmpFeatures, canvas, labelsInThisLayer, labelsInAllLayers); } } canvas.Flush(); } }
protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers) { double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit); MapSuiteTileMatrix mapSuiteTileMatrix = new MapSuiteTileMatrix(scale, cellSize, cellSize, canvas.MapUnit); IEnumerable <TileMatrixCell> tileMatricCells = mapSuiteTileMatrix.GetContainedCells(canvas.CurrentWorldExtent); Dictionary <string, string> unusedFeatures = new Dictionary <string, string>(); foreach (Feature feature in features) { if (feature.GetWellKnownType() != WellKnownType.Point && feature.GetWellKnownType() != WellKnownType.Multipoint) { continue; } unusedFeatures.Add(feature.Id, feature.Id); } foreach (TileMatrixCell cell in tileMatricCells) { int featureCount = 0; MultipointShape tempMultiPointShape = new MultipointShape(); foreach (Feature feature in features) { // Make sure the feature has not been used in another cluster if (unusedFeatures.ContainsKey(feature.Id)) { // Check if the cell contains the feature if (cell.BoundingBox.Contains(feature.GetBoundingBox())) { featureCount++; unusedFeatures.Remove(feature.Id); if (feature.GetWellKnownType() == WellKnownType.Multipoint) { MultipointShape multipointShape = feature.GetShape() as MultipointShape; foreach (var item in multipointShape.Points) { tempMultiPointShape.Points.Add(item); } } else { tempMultiPointShape.Points.Add(feature.GetShape() as PointShape); } } } } if (featureCount > 0) { // Add the feature count to the new feature we created. The feature will be placed // at the center of gravity of all the clustered features of the cell we created. Dictionary <string, string> featureValues = new Dictionary <string, string>(); featureValues.Add("FeatureCount", featureCount.ToString(CultureInfo.InvariantCulture)); bool isMatch = false; for (int i = 0; i < classBreakPoint.Count - 1; i++) { var startItem = classBreakPoint.ElementAt(i); var endItem = classBreakPoint.ElementAt(i + 1); if (featureCount >= startItem.Key && featureCount < endItem.Key) { //Draw the point shape startItem.Value.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); isMatch = true; break; } } if (!isMatch && featureCount >= classBreakPoint.LastOrDefault().Key) { classBreakPoint.LastOrDefault().Value.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); } if (featureCount != 1) { // Draw the text style to show how many feaures are consolidated in the cluster textSytle.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers); } } } }