Picture Marker Symbols not appearing in ArcMap

1375
1
03-17-2011 07:46 AM
GaryBroyd
New Contributor
Hi Everybody,

I'm in the process of trying to port our VB6 code (which worked fine with 9.3) to .Net for use with ArcGIS 10 and am having problems.  I had an earlier post which dealt with some other problems but have now run into further issues.

It is to do with trying creating a feature class which is populated with a number of records (e.g. locations on a map) which is then added to a feature layer (supposedly fine but can't confirm this yet - but one problem at a time!!!)  I then create a UniqueValueRenderer (to attach to the featureLayer) and add a multi-field symbol to it and this is where I'm having problems.  The following code seems to run through fine without erroring and I can confirm things like file paths are valid etc)

private void SymbolLayer( IFeatureLayer featureLayer, string mapDataFilePath, IDictionary<string, Symbol> symbols )
{
 IFields fields = featureLayer.FeatureClass.Fields;

 //Get indexes of certain fields
 int mapStyle = fields.FindField( "MAP_STYLE" );
 int mapBMP = fields.FindField( "MAP_BMP" );
 int mapSymbol = fields.FindField( "MAP_SYMBOL" );

 IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
 IPictureMarkerSymbol pictureMarkSymbol;
 IUniqueValueRenderer uniqueValueRenderer;
 UID uid = new UID();
 IObjectFactory objectFactory = mApplication as IObjectFactory;

 uid.Value = "esriCarto.UniqueValueRenderer";
 uniqueValueRenderer = objectFactory.Create( uid ) as IUniqueValueRenderer;

 //The fields which are used to map to the symbol
 uniqueValueRenderer.FieldCount = 3;
 uniqueValueRenderer.FieldDelimiter = ",";
 uniqueValueRenderer.set_Field( 0, fields.get_Field( mapBMP ).Name );
 uniqueValueRenderer.set_Field( 1, fields.get_Field( mapStyle ).Name );
 uniqueValueRenderer.set_Field( 2, fields.get_Field( mapSymbol ).Name );

 //Create the symbol
 string bmpFile = "C:\ArcGIS Tests\place.bmp" );
 IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass();
 IRgbColor transparencyColour = new RgbColorClass();

 //Make the colour white
 transparencyColour.Blue = 255;
 transparencyColour.Green = 255;
 transparencyColour.Red = 255;

 //Generate the marker symbol from the bitmap filename
 pictureMarkerSymbol.CreateMarkerSymbolFromFile( esriIPictureType.esriIPictureBitmap, bmpFile );
 pictureMarkerSymbol.Angle = 0;
 pictureMarkerSymbol.BitmapTransparencyColor = transparencyColour;
 pictureMarkerSymbol.Size = symbol.MapSize;
 pictureMarkerSymbol.XOffset = 0;
 pictureMarkerSymbol.YOffset = 0;

 ISymbol iSymbol = pictureMarkerSymbol as ISymbol;
 uniqueValueRenderer.AddValue( "place,0,0", null, iSymbol );
 geoFeatureLayer.Renderer = uniqueValueRenderer as IFeatureRenderer;
}


What then happens in ArcMap is that I can see the feature layer listed in the Table of Contents pane, but there isn't an icon.  If I then edit the icon to bring up the "Symbol Selector" dialog and I notice that there isn't an image in the "Current Symbol" frame.  Clicking "Edit Symbol" seems to bring up an Open File dialog asking for the location of the bitmap - which I select before it continues onto the "Symbol Properties Editor" dialog.  Next to the "Picture..." button it says "No Picture Loaded" and again clicking on Picture asks for the bitmap location but when having chosen the correct file, it still doesn't update. 

The only way I can get it to pick up the bitmap is to change the type of the symbol (e.g. to Simple Marker Symbol) and then back again and can then select the bitmap successfully.  This implies that something is missing when I'm creating my Symbol and adding it to the UniqueValueRenderer via AddValue(). 

Are the symptoms I described in ArcMap familar to anyone as to what is going wrong for it to not know where the bitmap is.  Or is there some update code I need to call before it will work (I'm alread calling "document.UpdateContents()" followed by "document.ActiveView.Refresh()" at the end anyway)

Thanks,

Gary
0 Kudos
1 Reply
GaryBroyd
New Contributor
Solved now.

Turns out the problem was due to our code creating new instances of ESRI objects instead or getting an object factory to create them.

E.g.

Instead of doing things like:

IUniqueValueRenderer uniqueValueRenderer = new UniqueValueRendererClass();


I changed it to:

IObjectFactory objectFactory = mArcMapApplication as IObjectFactory;
UID uid = new UID();
uid.Value = "esriCarto.UniqueValueRenderer";
IUniqueValueRenderer uniqueValueRenderer = objectFactory.Create(uid) as IUniqueValueRenderer;
0 Kudos