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
Highlighted
Contributor
Posts: 22
Registered: ‎11-23-2015
Accepted Solution

GMSC - Saving queries in the legend panel

Hi,

 

some of our customers would like to save queries and change the color/styling of the selected objects for printing.

For example: Searching all properties of a minuicipality and create a map for this query.

 

Is it possible to temporarly save queries like the "Redlining" is saved in the legend panel?

Community Manager
Posts: 173
Registered: ‎10-09-2015

Re: GMSC - Saving queries in the legend panel

Something like this should do the job:

@Plugin(alias = "SearchResultLayerHandler",	vendor = "Hexagon Geospatial")
public class SearchResultLayerHandler extends AbstractPlugin
{
	private static final UUID	sStyleId	= UUID.fromString("d0c11722-2e5d-400d-97fc-e9d7f230ee1f");	
	private Storage storage;
	
		/**
		 * @see com.intergraph.web.core.kernel.plugin.AbstractPlugin#loadOnStart()
		 */
		@Override
		public void loadOnStart() throws Exception
		{
			SearchController searchController = ApplicationContext.getProject().getSearchController();
			searchController.addSearchListener(new ISearchListener()
			{
				@Override
				public void handleSearchResult(final SearchController queryController, final ISearch query, final SearchResult queryResult,
						final Map<String, String> searchCriterias, final Object[] selection)
				{
					SmartClientKernel.addPooledTask(new Runnable()
					{
						@Override
						public void run()
						{
							IFeatureTypeStyle featureTypeStyle = null;
							try
							{
								featureTypeStyle = GFeatureTypeStyleManager.getInstance().getStyle(sStyleId);
								getStorage().clear();								
								getStorage().getFeature().setVisible(true);
							} catch (SymbologyConfigurationException | JAXBException | IOException | StorageException e1)
							{
								Log.getLogger().log(Level.SEVERE, e1.getMessage(), e1);
							}
							List<Object> primaryValues = new ArrayList<Object>();
							
							//getIdsFromSelectedElements
							for(int row =0;row<queryResult.getRowCount();row++)
							{
								Object item = queryResult.getValueAt(row, getIndexOfPrimaryKey(queryResult));
								try
								{
									if (!primaryValues.contains(item))
									{
										primaryValues.add(item);								
										GPrimitive primitive = ApplicationContext.getBrowser().getElement(queryResult.getFeature().getID().toString(), item);		
										if(primitive!=null)
											getStorage().add(primitive.copy(new GAction(item), featureTypeStyle, 0.0, 0.0));
									}
								} catch (StorageException e)
								{
									Log.getLogger().log(Level.SEVERE, e.getMessage(), e);
								}						
							}
						}
					});
				}
			});
		}
		
		private static int getIndexOfPrimaryKey(SearchResult queryResult)
		{
			if (queryResult.getFeature() == null)
				return -1;
			
			int columnCount = queryResult.getColumnCount();
			for (int i = 0; i < columnCount; i++)
			{
				if (queryResult.getColumnName(i).equalsIgnoreCase(queryResult.getFeature().getPrimaryKey()))
					return i;
			}
			return -1;
		}
		
		private Storage getStorage() throws StorageException
		{
			if (storage != null)
				return storage;
			else
				return storage = context.createTemporaryDataStorage("Query Results", sStyleId);
		}
	}
Thomas Anzinger
Community Manager
thomas.anzinger@hexagongeospatial.com
Contributor
Posts: 22
Registered: ‎11-23-2015

Re: GMSC - Saving queries in the legend panel

Thank you, I will try it.

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