how to call click event on marker using java arc objects

544
1
04-10-2014 02:03 AM
neerajbharti
New Contributor
Hii I am new in GIS and java arcobjects. I have to call a click event on simple marker element
on mapbean using java arc objects but i dont know how to do it.

in my application I put approx 200 markers in mapbean now i have to select few of them approx 6 marker which is selected by user but i dont know how to select this particular marker I think if i am able to call click event on marker. then I would select it .

putiing a marker on mapbean code is there.

public static void  drawBlackPoint(IPoint fpoint, double hieght,double prev_hieght) {
    try {


        ////for Starting point
        ISimpleMarkerSymbol markerSymbol2 = new SimpleMarkerSymbol();
        markerSymbol2.setStyle(esriSimpleMarkerStyle.esriSMSCircle);


        IRgbColor rgbColor2 = new RgbColor();
        if (hieght!=prev_hieght) {
            count1++;
        }
        if(count1==1){
            rgbColor2.setRed(34);
            rgbColor2.setBlue(139);
            rgbColor2.setGreen(24);
        }else if(count1==2){
            rgbColor2.setRed(0);
            rgbColor2.setBlue(0);
            rgbColor2.setGreen(205);
        }else if(count1==3){
            rgbColor2.setRed(112);
            rgbColor2.setBlue(219);
            rgbColor2.setGreen(147);
        }else if(count1==4){
            rgbColor2.setRed(255);
            rgbColor2.setBlue(255);
            rgbColor2.setGreen(0);
        }else if(count1==5){
            rgbColor2.setRed(127);
            rgbColor2.setBlue(0);
            rgbColor2.setGreen(255);
}else if(count1==6){
            rgbColor2.setRed(138);
            rgbColor2.setBlue(69);
            rgbColor2.setGreen(19);
        }else if(count1==7){
            rgbColor2.setRed(139);
            rgbColor2.setBlue(131);
            rgbColor2.setGreen(120);
        }else{
            rgbColor2.setRed(255);
            rgbColor2.setBlue(255);
            rgbColor2.setGreen(255);
        }
        markerSymbol2.setColor(rgbColor2);
        markerSymbol2.setSize(5.0);
        IMarkerElement markerElementOne2 =  new MarkerElement();
        markerElementOne2.setSymbol(markerSymbol2);
     IElement elementOne2 = (IElement) markerElementOne2;
        IElementProperties elementPropertiesTwo = (IElementProperties) elementOne2;
        elementPropertiesTwo.setName("FP");
        elementOne2.setGeometry(fpoint);



        ILayer layer;
        int count = BasicViewer.getMapBean().getLayerCount();



        if (hieght!=prev_hieght) {

            ICompositeGraphicsLayer cgl=new CompositeGraphicsLayer();
            IGraphicsContainer gl=(IGraphicsContainer)cgl;
            gl.addElement(elementOne2, 0);
            layer = (ILayer) gl;
            layer.setName("hieght_"+hieght);    
            BasicViewer.getMapBean().addLayer(layer, 0);
            BasicViewer.getMapBean().getActiveView().partialRefresh(esriViewDrawPhase.esriViewGeography,layer, null);

        }else{


            for (int i = 0; i < count; i++) {
                if(BasicViewer.getMapBean().getLayer(i).getName().equals("hieght_"+hieght))
                {
                    System.out.println("--Layer Name- if-"+BasicViewer.getMapBean().getLayer(i).getName());
                    layer=BasicViewer.getMapBean().getMap().getLayer(i);

                    IGraphicsContainer gl=(IGraphicsContainer)layer;

                    gl.addElement(elementOne2, 0);

                }
            }

        }

    } catch (Exception e) {
        System.out.println("Exception In drawPoint :: " + e.toString());
        e.printStackTrace();
    }
}
0 Kudos
1 Reply
LeoDonahue
Occasional Contributor III
Hii I am new in GIS and java arcobjects. I have to call a click event on simple marker element
on mapbean using java arc objects but i dont know how to do it.

in my application I put approx 200 markers in mapbean now i have to select few of them approx 6 marker which is selected by user but i dont know how to select this particular marker I think if i am able to call click event on marker. then I would select it .


No such thing as a SimpleMarkerElement.  You have SimpleMarkerSymbol or MarkerElement.  Neither of them have a click event.  They have a hit test method, but not sure that is what you wanted.

You can find marker elements by iterating over them and getting their name, assuming you set the name of each marker element.

Or if you want to look at ISelection or ElementSelection.

Also, the ActiveView has a getSelection method which returns a reference to ISelection.

And, if you google, then you could have found this sample.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/0048/00480000006z000000.htm

Scroll down to the MoveGraphics and SelectElements methods for examples.
0 Kudos