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

deleting from legend in SDK

[ Edited ]

I have a main legend and then various  custom queries that add new legends with one entry  to the legend display.

I came up with the code below to remove these custom queries but  leave the main legend displayed:

 

var ii = 0;
$GP.legend.find({}, function (ret) {
ii = 0;
ret.legendItems.forEach(function (item) {
ii  += 1;
if (ii>71)

   {ret.legendItems.slice(ii)[0].remove();
    }
});

 

The first time i run this code all the queriy legends are successfully removed and the main legend is not.  But subsequent tries to run additional queries are unsuccessfull - no legend is added and the query results are not displayed on the map.

 

****Important Note***

I find that if  I delete the legend added by running the query using "Remove" (right mouse click while pushing on upside down black triangle) the same problem occurs - in this case i am using no custom code to remove the legend entry.

 

What is the correct way to remove all legends but the default legend (which has 71 entries in it) and beable to have them add back when a new query (same query name, different selection) is run.  For example the "Address #" query finds all addresses with address "300", then remove the legend for it which also removes the map display, and then later run the query again but with address "400"

Technical Evangelist
Posts: 1,143
Registered: ‎09-11-2015

Re: deleting from legend in SDK

Hi Jane,

 

Regarding the impossibility of removing legend entries using GUI - I cannot reproduce that on normal or SDK Portal instance. I tried queries created both from GUI and from the code. The Remove button worked fine.

  • Could you provide more details on the workflow?
  • Can you reproduce that on plain Portal instance?

It could be some customization part, breaking the Portal behavior.

 

Thanks,

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

Thanks - The Remove option works fine except if i delete the legend I cannot recreate it by rerunning the query with the same name. I either delete the legend via code or by using the Remove option from the upside down black triangle you get when hovering over the legend item The query is done by code like below (will send in next message - i keep getting a formatting complaint) I used to give the query the name "OWNER_xxx" where xxx was the owner name being searched for but i changed it to just be "OWNER". Each time the query is run, it overwrites itself. But if I delete the query from the legend where it displays then running the query again results in no query being added to the legend. The same thing happens if i use the owner name as part of the legend entry name, delete from legend, run again; I just hadn't noticed it since i would query on a different owner each time so each query name was unique. If i removed the query from the legend i didn't run it it again with the same owner so didn't get problem.
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

 function FindbyOwner(owner) {
                document.getElementById('dialogbox').style.display = "none";
                document.getElementById('dialogoverlay').style.display = "none";
                iicount + iicount + 1;
                var queryName2 = "Owner_" + owner;
                qName = "Owner";
                queryName2 = qName;
                 // queryname is just "Owner"


                style4 = new Intergraph.WebSolutions.Core.WebClient.Platform.Style.AreaStyle(null, {
                    styles: [{
                        type: "SimpleLineStyle",
                        color: "#00ff00",
                        width: 3
                    }, {
                        type: "SimpleFillStyle",
                    //    color: "#00ff00",
                        //    translucency: 0.7,
                        translucency: 1.0,
                        color: "#ffffff"
                    }]

                });
                //findowners_list();
                //$GP.ui.info("list of owners: " + a);
                owner = owner.replace("'", "''");
                $GP.crs.setCurrent("EPSG:3436", function () {
                    $GP.queries.add({
                        queryName: queryName2,
                        featureClassId: "34644522FD66F454EFD7A34AC7AA1F373C41D430|Parcels_with_Labels",
                        url: "http://cthse-gis/JD1/MapService.svc",
                        applicationId: "JD1_GeomediaWebMap_Source",
                        definitionName: "MapPublisher",
                        style: style4,
                        addToLegend: true,
                        filters: [
                            {
                                operator: "like",
                                operands: ["Owner_Name", "*"+owner+"*"]
                            }],
                    },
                 function (result) {
                     $GP.queries.find({
                         analysisId: result.analysisId,
                     }, function (result2) {
                         result2.analysis.addToDataView(),
                         $GP.legend.find({
                             name: qName
                         }, function (result) {
                             //alert(result.legendItems.length);
                             if (result.legendItems && result.legendItems.length > 0)
                                 result.legendItems[0].set_name("Owner Query");
                         });
                     });
                 });
               });
            }

Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

legend.png

Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

Above is a screenshot with legends include Parcels - Line (parcels overlapping user entered line string), Address #, and Owner (code in previous post) as well as the Government Base Map, I have a clear all command that deletes red-lining and measurement text, and i would like it to also delete all queries (and leave Government Base Map legend)When i did this with code i found that i could not repeat a query once the legend had been deleted...then i found that even deleting it using the Remove option has the same affect.
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

I kind of see the problem - in GeoMedia you cannot create a query, delete it from the legend, and then run the query again giving it the same name.Each query has to have a uniqe name. In the SDK, the query just replaces the previous one, But if you delete the legend entry before recreating the query it causes an error.
Technical Evangelist
Posts: 1,143
Registered: ‎09-11-2015

Re: deleting from legend in SDK

Hi Jane,

 

If you wish to delete a query, you should use Analysis.remove(), then you should be able to overcome the issue with existing queryName

You can call this function

  • during the complete map cleanup
  • or just before creating the query which will have the same name

 

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: deleting from legend in SDK

That is exactly what i want to do - Is there a code snippet that loops through all the queries and does an analysis.remove of each one? Also can I tell from the analysisID which query i am at?  If i can understand how to do this i can add a lot more functionality to my SDK app. Thanks!