ThinkGeo.com    |     Documentation    |     Premium Support

Rotating the feature text (similar to wordwrap)

I have a RectangleShape feature that the end-user can rotate using the EditOverlay. Here's my challenge:


1) grab or calculate the rotation of the RectangleShape when the end-user completes the rotation


2) draw the text at the same rotation when the feature is drawn.


A further challenge is that I must word-wrap the text to fit inside the RectangleShape.


I've customized the TextStyle class following the WordWrappedTextStyle online project. In the DrawCore override I call base.DrawCore to draw the feature and then call canvas.DrawText to draw the text using a bogus rotation to emulate the RectangleShape's rotation. Is this the right approach? Is there to draw the text inside the RectangleShape using GDI, rather than have to brute-force the word-wrapping as the sample shows?



Greg, 
  
   Can you share the changes you have made to enhance the Style?  Is what you have done working and are you just looking for a different way?  I have some ideas that a bit different but want to see what you are really want and how you expect to get it.  I am not sure what GDI will allow you to do.  They about the same API as us and don’t have any word wrap or fit text in box APIs that I know of. 
  
 What I might have done is to on the draw of the polygon if I know it is a rectangle that is rotated would be to find the center and figure out the rotation angle and then create a line feature that I would label that would being the center.  I could measure the line and get the font test width and find how to wrap the text that way.  I think it is basically the same way. 
  
   This kind of labeling is more like that of flow charts and visio type stuff then GIS type labeling.  Of course people annotate maps so maybe this is some stuff we could make a mice style for.  What is the rotation used for if I may ask? 
  
 David

The end-users take advantage of the rotation so they can align their notes with POIs on the map, such as roads or utilities. I had this working using ThinkGeo 2.0 by overriding the CustomDraw event and using a Transform. 
  
 I guess I’m just checking whether it’s okay to override the DrawCore in the TextStyle to call the base.DrawCore to draw the feature, then the canvas.DrawText to draw the text with some kind of rotation. I’ll attach a sample…

Attached is the version of WordWrappedTextStyle I am trying to munge together.



1467-WordWrappedTextStyle.cs (6.73 KB)

 


Gregory,
 
I have created a sample that demonstrates the RotatingTextStyle which can rotate text according to the shape.
 
Original:
 
 
 Rotated:

 
 
Thanks
James

1473-RotatingFeatureText.zip (12.5 KB)

Wow! Thanks, James! You guys are just like Santa’s elves. I can’t wait to unwrap the sample project…

You're welcome Gregory, we are not so old :)


James



You know, the sample project works when you manually update the shape’s rotation programatically, but it would be nice if you could tie this together with the EditOverlay.  
  
 I allow my users to rotate RectangleShapes using the EditOverlay. When the user is finished rotating the RectangleShape, I copy the feature and shape from the EditOverlay into another map layer that contains  BaseMapShapes, similar to the MapShapeLayer project. I also use the EditOverlay_FeatureRotating event to calculate the rotation angle using the target and source control points. This works well the first time you rotate the text box. The problem comes when you try to rotate the text box the second time because I’ve already copied the feature and shape from the EditOverlay into my BaseMapShape. 
  
 As confusing as this sounds, I figure it would be best if there happened to be a sample project of the rotating text that uses the TrackOverlay and works no matter how many times you do it… 
  
 Thanks!

Gregory,


I have updated my sample and fit your requirement, but I think it still not perfect, you know every thing can not be perfect, we try to let most of users satisfied, if you still feel not good that maybe your requirement is special which we don't consider that at our Desgin time. If you consist make it better, I am also glad to help you.



Thanks


James


 



1508-RotatingFeatureText.zip (12.2 KB)

James, thanks for your efforts! I look forward to trying this out. Don’t worry about “getting it perfect” - after all, this is software!

Gregory, 
  
 You’re so welcome. If you have more questions, just let me know. 
  
 James