Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 79
Registered: ‎05-30-2016
Accepted Solution

Issue Setting MapView Control Legend in Console App

I have a c# app that runs as a command that creates a windows form with a Map View control on it. It works fine. So now I'm trying to create a command line utility that opens the same form and does something with the map. However, when I set the map view control legend using a named legend, the legend property fails silently. The property remains null.

 

I've attached the project file.

 

So the only difference that comes to mind, is the app command runs within the GeoMedia exe process, whereas the command line utiltiy does not. Maybe a com interop issue?

 

Or, maybe I'm missing a reference?

 

Any suggestions?

 

Technical Evangelist
Posts: 531
Registered: ‎09-11-2015

Re: Issue Setting MapView Control Legend in Console App

Hi Xguy,

 

what GeoMedia version is the project targeted to?

 

Pavel

Technical Evangelist
Posts: 531
Registered: ‎09-11-2015

Re: Issue Setting MapView Control Legend in Console App

Well, I have reviewed the code and it looks like you are facing classical marshaling problem - so you are right, the legend object is created in GM memory space, while the MapView is in your application memory space. I don't know an easy solution. The only which I can think of is to recreate all objects in the application memory space - starting with connection, recordsets, legend, legend entries and symbology. Although some steps might not be necessary. Perhaps it would only be sufficient to create the legend, legend entries and symbology, and assign the existing recordsets from GeoMedia memory space. This should be a subject of tests.

 

Pavel

Contributor
Posts: 79
Registered: ‎05-30-2016

Re: Issue Setting MapView Control Legend in Console App

6.1 thru 2016

Contributor
Posts: 79
Registered: ‎05-30-2016

Re: Issue Setting MapView Control Legend in Console App

I found that if I set the mapView.Legend to new Legend it's ok. So, as a workaround I tried to copy all the properties from the Named Legend to a new Legend. The Copy method failed, so I tried doing it Legend Entry prop by Legend Entry prop. I got as far as setting a Legend Entry Style property from a copy of the Named Legend Legend Entry Style. 

 

This part seems ok:

 

PView.StyleDefinition style = (PView.StyleDefinition)le.Style;

 

But then this part fails:

namedLegendEntry.Style = style;

 

Exception from HRESULT: 0x80040202

 

Once again, I noticed that setting the LegendEntry style to a New StyleDefinition() works. Just fails when I copied it over from the Named Legend.

 

I tried using the style Copy method as well, to no avail.

 

I guess maybe I could try iterating recursively through all the Style props and copying them over one at a time as well. I suspect as long as they are primitive types it might work.

 

So, I'm curious though. What do custom app developers do? There must be custom apps pulling legends from a Named Legend. 

Technical Evangelist
Posts: 531
Registered: ‎09-11-2015

Re: Issue Setting MapView Control Legend in Console App

What you are trying to do is by no mean a standard programming task. This is so called driving type application and I would recommend you to avoid it if possible, just because of the problems you are experiencing.

 

If you need to exchange some information with a geoworkspace, then I would recommend you to output the gws information you need into a library. Then using library API, you can quickly recreate the gws content as stored in the library, without a need to instantiate GeoMedia application. All objects will be created in your app memory space and there will be no problems. So I suggest you to look at Library automation API to investigate whether it could solve your problem or not.

 

Pavel

Contributor
Posts: 79
Registered: ‎05-30-2016

Re: Issue Setting MapView Control Legend in Console App

Pavel,

 

Thanks for your suggestions on this. Your suggestion about the library got me thinking about how to cross that boundary, and I decided to try something else so I wouldn't have to do that.

 

Here's what I came up with.

 

First step is to save the command line args to a special file.

Next, call the GeoMedia application object's InvokeCommand method to launch my command.

When my command Activates, I look for the file. If it exists, I operate in command line mode and pull the args from the file.

If not, I operate as normal.

 

Doing this everything operates within the context of the GeoMedia process, and I now have it working.

 

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.