Hi.
I have been searching how to add images to a map to represent some real world objects (for example buildings).
I found this example wiki.thinkgeo.com/wiki/Map_Suite_Desktop_Edition_All_Samples#Image_Style
In that example, it is possible add an image to a polygon (like rectangle, circle, etc).
My question is:
Is possible add an image to a polygon, and the image fill the polygon without repeat itself?
Thanks,
Ricardo
Advanced Image Style
Hi Ricardo,
We can follow the guide sample you found and do a little changes. In your CustomImageStyle, we can draw an image on the canvas with the polygon center point. Some codes are like:
canvas.DrawWorldImageWithoutScaling(image, point.X, point.Y, DrawingLevel, XOffsetInPixel, YOffsetInPixel, RotationAngle);
We can use polygon.GetCenterPoint to get the center point.
Please let us know if any questions its usage.
Thanks,
Troy
Hi.
I have tested your suggestion.
I have attached an image with what append with the following code:
canvas.DrawWorldImageWithoutScaling(geoImage,
polygonShape.GetCenterPoint().X, polygonShape.GetCenterPoint().Y,
DrawingLevel.LevelOne, 0, 0, 0);
canvas.DrawArea(polygonShape, new
GeoPen(GeoColor.SimpleColors.Red), new
GeoSolidBrush(GeoColor.SimpleColors.Transparent),
DrawingLevel.LevelTwo);
In the image, I put 3 polygons (circle, square, triangle). And in the center of witch polygon I put the house icon.
But It does not do want I looking for.
Maybe I did not explain. What I am looking for is the image stretch into the polygon.
So in the image, would like the icons stretch/re-size into each polygon. And it work with zoom.
Hi Ricardo,
I think I know what you want, but for circle and triangle I don’t think our APIs can implement that, unless we find a way to stretch the image based on target shape.
The code as below should can works for square, please let me know whether that works for you:
In CustomImageStyle.cs
protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
// Loop through all of the features being passed in to draw.
foreach (Feature feature in features)
{
WellKnownType shapeWellKnownType = feature.GetWellKnownType();
if (shapeWellKnownType == WellKnownType.Polygon)
{
PolygonShape polygonShape = new PolygonShape(feature.GetWellKnownBinary());
PointShape point = polygonShape.GetCenterPoint();
RectangleShape rect = polygonShape.GetBoundingBox();
float screenWidth = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, new Feature(rect.UpperLeftPoint), new Feature(rect.UpperRightPoint), canvas.Width, canvas.Height);
float screenHeight = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, new Feature(rect.UpperLeftPoint), new Feature(rect.LowerLeftPoint), canvas.Width, canvas.Height);
canvas.DrawWorldImage(geoImage, point.X, point.Y, screenWidth, screenHeight, DrawingLevel.LevelOne);
}
else if (shapeWellKnownType == WellKnownType.Multipolygon)
{
MultipolygonShape multiPolygonShape = new MultipolygonShape(feature.GetWellKnownBinary());
PointShape point = multiPolygonShape.GetCenterPoint();
RectangleShape rect = multiPolygonShape.GetBoundingBox();
float screenWidth = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, new Feature(rect.UpperLeftPoint), new Feature(rect.UpperRightPoint), canvas.Width, canvas.Height);
float screenHeight = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, new Feature(rect.UpperLeftPoint), new Feature(rect.LowerLeftPoint), canvas.Width, canvas.Height);
canvas.DrawWorldImage(geoImage, point.X, point.Y, screenWidth, screenHeight, DrawingLevel.LevelOne);
}
}
}
Regards,
Don
Hi Don.
I have tested your sugestion, and it works
I have attached an image with my result
Regards,
Ricardo
Hi Ricardo,
I am glad to hear that works for you.
And thanks for your share.
Regards,
Don