Select to view content in your preferred language

Create a Add-in for ArcMap 10.2.2 using java

4908
5
Jump to solution
01-07-2015 07:55 AM
TerenceNero
Deactivated User

Hi guys.

I am new to programming for ArcGIS desktop.

I have worked on the Esri Javascript API.

 

Now i want to develope a search tool for ArcMap that will give the user a option to select a layer and enter a search keyword.

On submit the tool will search for the keyword on in all the fields of the selected layer and after sucessful search it should zoom to the result.

 

Can any help me please.

0 Kudos
1 Solution

Accepted Solutions
5 Replies
OwainCatton
Regular Contributor

You might want to have a look at this https://community.esri.com/thread/19758, as there was a bug with Java and Add-Ins meaning JTextFields are disabled. You can use a JOptionPane to grab the search text.

But I created a similar Add-In tool by using a Model View Controller.

Example here https://community.esri.com/thread/67843

Owain

0 Kudos
TerenceNero
Deactivated User

Thanks for your quick reply.

I would like to know how to query a feature layer/layer and zoom to the result of the query.

Can you please help me with that.

0 Kudos
OwainCatton
Regular Contributor

Morning Terence,

Here is how I am querying a feature in a layer and then zooming to it. You will need to pass the layer name and search string for the IQueryFilter to match your layer feaure properties.

public void listPerformZoom(String layerName, String searchString) throws AutomationException, IOException{
  Map map = (Map)mxDocument.getFocusMap();
  IFeatureLayer pLayer = null;
  IActiveView pActiveView = (IActiveView) map;
  try {
   map.clearSelection();
  } catch (AutomationException e1) {
   e1.printStackTrace();
  } catch (IOException e1) {
   e1.printStackTrace();
  }
  
  try{
   pLayer = (IFeatureLayer) gpUtils.findMapLayer(layerName);
  } catch(AutomationException e){}
   
  if (pLayer != null){
   IFeatureSelection featureSelection = (IFeatureSelection) pLayer;
   if (featureSelection != null){
    IQueryFilter pQF = new QueryFilter();
       
    String query = String.format("RECORD_KEY = '%s'", searchString); // Search Query String
    pQF.setWhereClause(query);
    featureSelection.selectFeatures(pQF, esriSelectionResultEnum.esriSelectionResultNew, true);
    pActiveView.partialRefresh(esriViewDrawPhase.esriViewGeoSelection, pLayer, null);
   
    MapSelection pMapSel = new MapSelection(map.getFeatureSelection());
    pMapSel.reset();
    
    IFeature pFeature = pMapSel.next();
    IGeometry pGeom = pFeature.getShape();
    IEnvelope pEnv;
    if (pGeom instanceof IPoint){
     pEnv = pGeom.getEnvelope();
     pEnv.expand(100, 100, false); // This is the extent of the zoom if a point feature is found
     pActiveView.setExtent(pEnv);
    } else {
     pEnv = pGeom.getEnvelope();
     pActiveView.setExtent(pEnv);
    }
    pActiveView.refresh();
   }
   featureSelection = null;
  }
 }

Hope that helps,

Owain

0 Kudos
TerenceNero
Deactivated User

Hi Owain

Thanky Very much for your help.

Can you provide me with some documentation and some examples of ArcMap Add-In Tool in java.

From where can I learn to develope more advanced Tools.

Kind Regards,

Terence

0 Kudos
OwainCatton
Regular Contributor
0 Kudos