Select to view content in your preferred language

Search element and flash it, but different elements flash on the same point

597
1
05-22-2012 07:49 PM
guojing
New Contributor
ArcGiS engine 10
IDE??VS2010 C++

I search element(Geometry type is point), and want to flash it use FlashShape method. But i search different elements, the FlashShape always flash on the same point, why? I get point (X, Y) through point->get_X(&X) and point->get_Y(&Y), and compare it with mapX, mapY where i through mouse click event, they are different. The following is code snippet??


    CSearchDlg dlg;

    if (dlg.DoModal() == IDOK)
    {
        const CString layerName = dlg.m_layerName;
        const CString featureName = dlg.m_featureName;

        CString whereClause;
        whereClause.Format(_T("name = '%s'"), featureName);

        HRESULT hr;

        IQueryFilterPtr pQueryFilter(CLSID_QueryFilter);
        pQueryFilter->put_WhereClause(CComBSTR(whereClause));

        IMapPtr pMap;
        m_mapCtrl->get_Map(&pMap);

        long layerCount = 0;
        pMap->get_LayerCount(&layerCount);

        BSTR bsCurLayerName = NULL;
        BSTR bsLayerName = CComBSTR(layerName);
        int i;

        ILayerPtr pLayer = NULL;

        for (i = 0; i < layerCount; i++)
        {
            pMap->get_Layer(i, &pLayer);
            pLayer->get_Name(&bsCurLayerName);

            if (_tcsicmp(bsCurLayerName, bsLayerName) == 0)
            {
                break;
            }
        }

        if (layerCount == i)
        {
            CString msg;
            msg.Format(_T("Can not find layer %s"), layerName);
            AfxMessageBox(msg);
            return;
        }

        IFeatureLayerPtr pFeatureLayer(pLayer);
        if (pFeatureLayer == 0)
        {
            TRACE(_T("Not found\n"));
            return;
        }


        IFeatureSelectionPtr pFeatureSel(pFeatureLayer);
        hr = pFeatureSel->SelectFeatures(pQueryFilter, esriSelectionResultNew, VARIANT_FALSE);
        if (FAILED(hr))
        {
            TRACE(_T("hr %08X\n"), hr);
            return;
        }
       
        ISelectionSetPtr pSelectionSet;
        hr = pFeatureSel->get_SelectionSet(&pSelectionSet);
        if (FAILED(hr))
        {
            TRACE(_T("hr %08X\n"), hr);
            return;
        }

        esriICursorPtr pCursor;
        hr = pSelectionSet->Search(NULL, VARIANT_TRUE, &pCursor);
        if (FAILED(hr))
        {
            TRACE(_T("hr %08X\n"), hr);
            return;
        }

        IFeatureCursorPtr pFeatureCur = pCursor;

        IFeaturePtr pFeature;
        pFeatureCur->NextFeature(&pFeature);
        IActiveViewPtr pActiveView;
        m_mapCtrl->get_ActiveView(&pActiveView);

        IScreenDisplayPtr pScreenDisplay;
        pActiveView->get_ScreenDisplay(&pScreenDisplay);

        while (pFeature != NULL)
        {
            IGeometryPtr pGeometry;
            pFeature->get_Shape(&pGeometry);

            esriGeometryType ShapeType;
            pGeometry->get_GeometryType(&ShapeType);

            if (esriGeometryPoint == ShapeType)
            {
                ISimpleFillSymbolPtr pFillSymbol(CLSID_SimpleFillSymbol);
                IMarkerSymbolPtr pMarkSymbol(CLSID_SimpleMarkerSymbol);
                ISymbolPtr pSymbol;
                IRgbColorPtr pColor(CLSID_RgbColor);

                pColor->put_RGB(RGB(255, 0, 0));
                pMarkSymbol->put_Size(20);
                pMarkSymbol->put_Color(pColor);
                pSymbol = (ISymbolPtr) pMarkSymbol;
                pSymbol->put_ROP2(esriROPNotXOrPen);
                pScreenDisplay->UpdateWindow();

                m_mapCtrl->FlashShape(pGeometry, 10, 400,  _variant_t((IUnknown* )pSymbol));
            }

            pFeatureCur->NextFeature(&pFeature);
        }
    }
Tags (2)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus
You are posting to the the Flex API form... You need to be posting this to the dot NET forum instead.

http://forums.arcgis.com/forums/9-ArcGIS-Server-.NET
0 Kudos