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
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

SDK 16.00.04.00 Query Problem After Deleting Queries - Solved

[ Edited ]

 *****The problem was that i was reusing the query name and that was causing an error  when i deleted the query.  The query was deleted but the code terminated so the new query wasn't created.  On the next round, the query to delete was gone so the code carried through..  Need to increment the query name each time a new query is created and then delete the previous query.  All working well now****




I have 8 different queries that i run based on user's choice. Each has parameters that the user can specify.
When a new query is run, the previous queries are first deleted so there are no queries displaying on the map.
If same query is run twice in a row (parameters can be same or different) then an error occurs stopping the query from completing. 
I think the code i am using to delete the query succeeeds but then it encounters an error before it completes. So the query is gone and the next time
the querydelete runs there is no query so the code is able to continue. The code i am using to delete the queries is below the QueryFind code
function QueryFind(aparcel) {
    var string3;
    clearall();   
    $GP.ui.info("Queries cleared");
    iicount + iicount + 1;    //iicount is global and starts at -1
    var qName = "QueryByParcel";
    style = new Intergraph.WebSolutions.Core.WebClient.Platform.Style.AreaStyle(null, {
        styles: [{
            type: "SimpleLineStyle",
            color: "#00ff00",
            width: 3
        }, {
            type: "SimpleFillStyle",
            translucency: 1.0,
            color: "#ffffff"
        }]

    });

    $GP.crs.setCurrent("EPSG:3436", function () {
        $GP.queries.add({
            queryName: qName,

            featureClassId: "D982BC597ACE629341904ADA4C432B175CC79CFA|MasterParcels_View",

            url: "http://cthse-gis/jd1/MapService.svc",
            applicationId: "JD_GOV",
            definitionName: "MapPublisher",
            style: style,
            addToLegend: true, filters: [
            {
                operator: "like",
                operands: ["Parcel_ID", aparcel]
            }],
        },
         function (result) {
             $GP.queries.find({
                 analysisId: result.analysisId,
             }, function (result2) {

                 if (result.updated) {
                     $GP.ui.info("Analysis updated");

              
                 }
            
                 $GP.queries.find({
                     analysisId: result.analysisId,
                 }, function (result2) {
                     result2.analysis.getData(

                     function (res) {
                         var i = 0;
                         do {
                             i += 1;
                         } while (res.data[i]);
                         $GP.ui.info("Total # of queries = " + i);

                         iicount = i - 1;
                         var string1 = JSON.stringify(res.data[iicount].features);
                         var string2 = string1;
                         $GP.ui.info("length of string2 = " + string2.length);
             
                     }
                     );
                 });
             });
         }
   
)})}



///////////////////////////////code to clear queries

    function clearall() {

                $GP.ui.info("Clearing queries...")
                deleteQuery("hiliteQuery");
                deleteQuery("QueryByRoad");
                deleteQuery("QueryByOwner");
                deleteQuery("QueryByParcel");
                deleteQuery("QueryBySubdivision");
                deleteQuery("QueryByAddress");
                deleteQuery("SelectByLine");
                deleteQuery("SelectByPolygon");
                deleteQuery("SelectByCircle");
                $GP.ui.info("All Clear");
                $event.notify("measureClear", {});
                $GP.map.draw.clear();
            }

            function getAnalysisId(name) {
           //       GP.ui.info("Name of query is " + name);
                var a = $analysisManager.findAnalysisByName(name);
            //      $GP.ui.info("Analysis ID is " + a);
                return a && a.get_id();
            }


            function deleteQuery(myQuery) {
                $GP.queries.find({
                    analysisId: getAnalysisId(myQuery)
                }, function (q) {
                    q.analysis.remove();
                }, function (e) {
    //                console.log("Unable to find analysis ")
                })

 

 

 

 

 

Untitled.png