This project has moved and is read-only. For the latest updates, please go here.

SymbolRotation issue

Topics: General Topics
Mar 29, 2007 at 12:06 PM

I'm showing a Point on a map with a symbol set in the layer's style:
layerGps.Style.Symbol = Properties.Resources.maparrow;
That works fine.

I'm now trying to get that symbol to rotate by setting the
_layerGps.Style.SymbolRotation property according to the gps direction.
However, the symbol does not rotate, but disappears. It sometimes shows at the edge of the map, when the rotation degrees hit a certain value.
Only a SymbolRotation of 0 will get the symbol to show at the actual point.

Is that behavior a bug or a feature?

Or maybe does the symbol rotate around something else that its own origin?

Thanks, Jo
Mar 29, 2007 at 10:49 PM
It sounds like the order of the Matrix transformation on the symbol isn't being computed in the right order, and the rotation is being taken at 0, 0.

If you could post the example code, it would help me make a more correct observation...
Mar 30, 2007 at 7:39 AM
Actually, the code i posted was almost all thats neccessary to reproduce the effect.
Defining the layer:
_layerGps = new SharpMap.Layers.VectorLayer("GPS");
_layerGps.DataSource = new SharpMap.Data.Providers.GeometryProvider(geometryLines);
_layerGps.Style.Symbol = Properties.Resources.maparrow;
_layerGps.Style.SymbolRotation = 200;
_layerGps.Style.SymbolOffset = new PointF(0, 0);

geometryLines contains several linestrings and one point, which is always the last element of the collection, and which should be displayed as an arrow, showing in the same direction as the last linestring.

On each update of the collection, I want to set the SymbolRotation property of the layer, which does the trick since there's only one point affected from that change.

In the code sample above, setting the SymbolRotation to a fix 200 degrees with no changes afterwards will remove the symbol from its associated point.

Setting the symbol offset to (0,0) doesn't bring it back either.
Apr 4, 2007 at 8:31 AM
Hi jo2007

I had the same problem and managed to find a solution by changing some of the code in the VectorRenderer.cs file. This is for drawing a Point on the map with the rotation.

Hope this helps.

if (rotation != 0 && rotation != float.NaN)
g.TranslateTransform(pp.X, pp.Y);
//g.TranslateTransform(-symbol.Width / 2, -symbol.Height / 2);
if (symbolscale == 1f)
g.DrawImageUnscaled(symbol, (int)(0-symbol.Width / 2 + offset.X), (int)(0-(symbol.Height / 2) + offset.Y));
float width = symbol.Width * symbolscale;
float height = symbol.Height * symbolscale;
g.DrawImage(symbol, (int)(0 - width / 2 + offset.X * symbolscale), (int)(0 - height / 2 + offset.Y * symbolscale), width, height);
g.Transform = map.MapTransform;

Apr 4, 2007 at 9:04 AM
Actually, you need that translate there to center the point. The actual fix is very similar, but I concatenated the transforms using the Matrix.RotateAt method. I'll commit the fix tonight. Check the WorkItem for the ChangeSet Id.
Apr 4, 2007 at 9:06 AM
This discussion has been copied to Work Item 9353. You may wish to continue further discussion there.
Apr 4, 2007 at 9:11 AM

wynandjordaan wrote:

Hope this helps.

Sure did... thanks for improving SharpMap!
Apr 4, 2007 at 1:25 PM

codekaizen wrote:

Sure did... thanks for improving SharpMap!

It's a pleasure. Will check the work item tonight.