We have recently started using a new external utility to produce shape files for our product. The shape files appear to be correct and are valid in every way we can see when viewed in a Shape file viewer. However, when we use these same shape files in our product, we get a pink block drawn on the map. No errors reported, no exceptions thrown, just a pink rectangle. It took a while, but I eventually chased this down to a scale bar adornment layer that I based on your samples. If I simply don’t add that adornment, no problem, no pink rectangle. Add it back, and the pink rectangle is back. I thought maybe there was some invalid feature in the shape file or something that broke my drawing code in the adornment (very small and simple thing really, at least my code). So I wrapped all my code in a try/catch-all to see what I might see. No exception, still got the pink block.
So I’m out of ideas. Please see attached project. I’ve knocked together a very simple map project that just loads a single shape file and the custom adornment layer. As delivered, it loads a simple polygon shape file that has one big square feature. As displayed, it will be a large red square. The small pink rectangle that is also visible is NOT in the shape file, it’s coming from the adornment layer, which appears to be working otherwise. In the code, simply comment out the call to “LoadScaleBarLayer” to see that the pink rectangle goes away (along with the scale bar, but no surprise there).
So first off, please tell me what it is about that shape file that causes the pink block/brick/rectangle to draw on the map. Apparently it’s some sort of error flag, but how am I supposed to use that to debug and correct whatever the problem may be? Is there an error log somewhere? And searching for “pink rectangle” didn’t provide any help either. So my second question is, short of posting a question here and waiting till the next day, how could this have been diagnosed and corrected independently?
Pink Block on map with scale bar adornment
Also, there are several shape files included, some that work ok, some that don’t. In the code loading the shape file you’ll find 2 appropriately/obviously named arrays that provide easy access to load these files, and clear indication of whether they display the problem or not.
Russ,
I checked your sample and found the pink rectangle is drawing from the CustomUnitScaleBarAdornmentLayer.cs with the below codes:
const int padding = 40;
double xmin = xPos - padding;
double ymax = yPos + padding;
double xmax = xPos + barLength + padding;
double ymin = yPos - 10 - padding;
RectangleShape rectangle = new RectangleShape(xmin, ymax, xmax, ymin); //Xpos - padding, linePoints[2].Y + padding, linePoints[3].X + padding, linePoints[0].Y - padding );
GeoSolidBrush brush = new GeoSolidBrush(GeoColor.StandardColors.Pink);
canvas.DrawArea( rectangle, brush, DrawingLevel.LevelOne );
I am guessing you want to add a background area for the scale bar, however, you may have a wrong use on the DrawArea method. We shouldn’t use the RectangleShape as their values are not map unit but screen position. Please try the below codes:
ScreenPointF[] areaPoints = new ScreenPointF[]{
new ScreenPointF( xPos - padding, yPos - padding ),
new ScreenPointF( xPos - padding, yPos + padding + 10),
new ScreenPointF( xPos + (float)barLength + padding, yPos + padding + 10),
new ScreenPointF( xPos + (float)barLength + padding, yPos - padding),
new ScreenPointF( xPos - padding, yPos - padding )
};
canvas.DrawArea(new Collection<
ScreenPointF
[]>() { areaPoints }, new GeoPen(GeoColor.StandardColors.Black, 1F), brush, DrawingLevel.LevelOne, 0, 0, PenBrushDrawingOrder.PenFirst);
canvas.DrawLine(linePoints, pen, DrawingLevel.LevelOne, 2, 2);
Here is the result:
Thanks,
Troy
Wow, talk about getting some blinders on! I didn’t even notice I had that “pink” code in there, and don’t recall writing it. It must have been a try/test/experiment code fragment from back when I was playing around with concepts in the original prototype. Looking at it now, I don’t remember it, but it must have been along the idea of putting a background colored block behind the scale so it wouldn’t get lost against unfortunately positioned map elements. That’s exactly the kind of thing I do so that I can easily see exactly where/what got drawn, and then work out proper brushes/pens/whatever once it is proven to work as desired. But for whatever reason in the original shape files (wow, that’s a LOT of shape files!) it wasn’t visible, and obviously I forgot to remove that bit of test code that I obviously thought didn’t work. Color me embarrassed…
If I had even paid attention to what I was looking at, it would have been painfully obvious that *I* was the one drawing that block. Thanks for the help and basically doing my job for me. And also pointing out the coordinate system mistake in earlier code.
You are welcome and we are happy to help you solve issues.
Thanks,
Troy