ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2; IBoundsProperties bounds = legend as IBoundsProperties; bounds.FixedAspectRatio = false;
I just tested in 10.1 and had the same result as Robert: No exception was thrown, but FixedAspectRatio remained true even after setting it to false. However, I also found that the legend was able to adjust its width and height properties correctly without my intervention, so my solution of programmatically updating the size of the element containing the legend is no longer necessary in ArcGIS 10.1.
>>Would you mind taking a look at tomalley23's question?
Can you help me find it in this new forum? I don't remember the title of that post.
IWorkspaceFactory rasWkspFactory = new RasterWorkspaceFactory(); IWorkspace wksp = new RasterWorkspace(rasWkspFactory.openFromFile(aPath, 0));
Every once in a while I get into conversations like these. It usually starts and ends the same way every time where someone wants to get in a word battle with me over what did you call it - academic meanings? I'm just using the standard language that is out there and I always run into people who what to use a different language (not programming language) in which to communicate. If you have a better word for my use of the word "implement" for classes that need to provide the guts to the method signatures in Interfaces, let me hear it. I'd be glad to consider to start using it.
I think if people "want" to add default methods to Interfaces, then maybe they should be looking at extending an Abstract Class for that instead. Abstract Classes can have "implementation" code in their methods. And, since you can re-declare and re-define the default methods in Interfaces, what would be the point? You would be breaking the intent of having a default method in Interfaces in the first place.
Your auto-properties example works on classes, not Interfaces. Interfaces are abstract and only define method signatures. You can't instantiate an Interface, so if there was some kind of functionality provided by an auto-property inside an Interface, you would be breaking the nature of an Interface.
Because the forums shouldn't be vending machines for code samples. Why can't I answer the question the way I want to?
But at the end, he got a NotImplementedException because he assigned an Interface type (ILegend) which does not implement or even define FixedAspectRatio to a reference variable type of IBoundsProperties which does. The compiler is going to check the actual type of the reference and tell you: "hey, FixedAspectRatio is not implemented on the object type you have currently".
I disagree with you on the IGeometryInterface. Why couldn't it be possible for someone to create their own special geometry class that wants to provide implementation for the methods defined in the IGeometryInterface? Just because you don't do it, doesn't mean someone else might not want to.
You can define constants in Java Interfaces now and people abuse them.
CoClasses "implement" the behavior defined by the Interface. Interfaces only define a contract, there is nothing between the curly braces, i.e. no implementation.
It is correct to use Interface types as reference variables, but what I was trying to tell the original poster is that you cannot expect to assign Interface types to Interface types and expect to call a method that is only implemented on one of the CoClasses. I was hoping that by reading this he would know how to fix his problem. He needs to instantiate an instance of whatever CoClass he wants and assign it to an Interface. He was trying to get a Legend by calling some method that returns an Interface and then assign that Interface to his IBoundsProperty Interface and then he didn't know why he couldn't call FixedAspectRatio.
What do you expect to happen here?
I don't know about "half the time". Do you have a specific example of on which Interface that happens?
An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.
I also hate the way any time they need to add a new member to an interface, they just create a whole new interface ("IGeometry needs a new XYZ property? Say hello to IGeometry16!" ), which half the time doesn't even inherit from the previous interface!
Your original post wanted to call: FixedAspectRatioThat method is not implemented in the ILegend, IBoundsProperties or the other Interfaces you have used to create an instance of a legend using IMapSurroundFrame.CreateSurroundFrame and passing the uid of a Legend.
I see a lot of people on this forum, especially in the .NET user group, assign interface types to other interface variables. I honestly don't know how that works or why more people don't run into problems doing that.
If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface.
// Initialize a legend for the focus map IGraphicsContainer gc = ArcMap.Document.PageLayout as IGraphicsContainer; IActiveView av = gc as IActiveView; IMap map = av.FocusMap; IMapFrame mapFrame = gc.FindFrame(map) as IMapFrame; ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.Legend"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Size it IQuerySize querySize = mapSurroundFrame.MapSurround as IQuerySize; Double w = 0; Double h = 0; querySize.QuerySize(ref w, ref h); Double aspectRatio = w / h; IEnvelope envelope = new EnvelopeClass(); // The legend is anchored with bottom left corner at x=1, y=2 // Not sure why aspect ratio matters -- just following Esri's example envelope.PutCoords(1, 2, (1 + 1), (2 + 1 / aspectRatio)); IElement element = mapSurroundFrame as IElement; element.Geometry = envelope; // Get the legend object and do something with it ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2; // ... some work ... now assume the legend size has changed // Update size of element containing the legend querySize.QuerySize(ref w, ref h); // Convert from points to page units, e.g., inches w = av.ScreenDisplay.DisplayTransformation.FromPoints(w); h = av.ScreenDisplay.DisplayTransformation.FromPoints(h); envelope.PutCoords(1, 2, (1 + w), (2 + h)); element.Geometry = envelope; // Now add the element to the layout. // If you add it earlier, from my experience, sometimes // the new geometry you assign doesn't stick gc.AddElement(element, 0);
mapSurroundFrame.MapSurround returns an instance of the Legend coclass
"The MapSurround property allows you to retrieve or set the surround object (north arrow, legend, or scale bar) stored within the frame."
What I haven't attempted yet but may try is using IQuerySize to get the updated size in points for the legend, convert to page layout units, and assign that as the new geometry for the map surround frame element.
// Update size of element containing the legend // av is IActiveView on an instance of the page layout IQuerySize querySize = mapSurroundFrame.MapSurround as IQuerySize; Double w = 0; Double h = 0; querySize.QuerySize(ref w, ref h); // Convert from points to page units, e.g., inches w = av.ScreenDisplay.DisplayTransformation.FromPoints(w); h = av.ScreenDisplay.DisplayTransformation.FromPoints(h); IEnvelope envelope = new EnvelopeClass(); // The legend is anchored at x=1 inch, y=2 inch on the layout envelope.PutCoords(1, 2, (1 + w), (2 + h)); IElement element = mapSurroundFrame as IElement; element.Geometry = envelope;
You need a concrete Legend object to call fixedAspectRatio.
When I run the code, I get "The method or operation is not implemented."
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.