Hexagon Geospatial
MENU

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: 223
Registered: ‎05-01-2016

Custom Feature Info Override

I am trying to use the javascript example  

 

$GP.map.featureInfo({
    preventDefaults: true // prevents the default feature info
}, function (result) {
	// placeholder for custom feature info implementation
	var serializedResult = $GP.utils.serialize(result); 
	var browserConfig = {
		title: "My Custom Feature Info",
		html: "<html><body><h1>Feature Info</h1>" + serializedResult + "</body></html>"
	};

	$GP.ui.browser.show(browserConfig);
});

to override the default Feature Info display.  I have several features that are being located when the user clicks.  It seems like i have to put an alert at the top of the code to get this override to work for the feature in question.  The other located features display their standard Feature Info dialog boxes.  Without the delay the feature i want to override (I check from its serialization that it is the right one) is just skipped over and the code i have to process the deserialized info is skipped.  If i put an alert at the top and wait for a bit, then the code is processed.  However the default feature info boxes for the features I don't want to display feature info for are  still displayed.

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Custom Feature Info Override

Hi.

 

When I need to override the feature info control, I do it this way:

 

$event.register('showFeatureInfo', function (eventName, eventArgs, sender) {
            var originalFeatureInfoController = $GP.internal.featureInfoController._control;
 
            if (/*CONDITION TO VALIDADE IF IS YOUR PSS FC*/) {
                /*REGISTER YOUR CONTROL AND EXECUTE THE CODE INSIDE IT TO SHOW CUSTOM CONTROL*/
                $GP.internal.featureInfoController.registerControl(CustomHotspots.Hotspots.prototype);
            } else {
                /*EXECUTE THE STANDARD CONTROL*/
                $GP.internal.featureInfoController.registerControl(originalFeatureInfoController);
            }
        }, this);

With this and can show both controls, standard and my custom control based on some conditions, just the way you mentioned.

 

HTH.

 

António

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

Re: Custom Feature Info Override

Thanks that is very helpful.

 I found that my problem in part was that i am using sqlserver views and i was getting different lists of attributes in the serialized string than when querying the sqlserver database.

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

Re: Custom Feature Info Override

Can you explain this part?

 

$GP.internal.featureInfoController.registerControl(CustomHotspots.Hotspots.prototype);

 

Where do i put the code that i want to run when the feature is the one i am looking for?

I just have about 10 lines of code that i want to run for a specific feature - it opens a window with information about the selected feature

Highlighted
Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Custom Feature Info Override

[ Edited ]

That line will replace the default control that Portal brings.

That is why if the conditions are not checked I register the default control:

 

$GP.internal.featureInfoController.registerControl(originalFeatureInfoController);

This is my code. HTH.

 

I have a control called 

CustomHotspotsUI.Hotspots

where I have the following code:

 

CustomHotspotsUI.Hotspots = function (element) {
    CustomHotspotsUI.Hotspots.initializeBase(this, [element]);
};

CustomHotspotsUI.Hotspots.prototype = {
    initialize: function () {
         CustomHotspotsUI.Hotspots.callBaseMethod(this, 'initialize');
    }

    $event.register('showFeatureInfo', function (eventName, eventArgs, sender) {
this._eventArgs = eventArgs; var originalFeatureInfoController = $GP.internal.featureInfoController._control; if (this._isCustomHotspot()) { $GP.internal.featureInfoController.registerControl(CustomHotspots.Hotspots.prototype); } else { /*EXECUTE THE STANDARD CONTROL*/ $GP.internal.featureInfoController.registerControl(originalFeatureInfoController); } }, this); }

As you can see in the intialize method I register the custom control depending on some conditions that I checked in the isCustomHotspot function. You have to replace this isCustomHotspot function by the conditions that you need.

 

Also you must have this function in your control:

addItems: function (featureInfo) {
}

Inside it you will check if the feature that called the controller is the one that you want and set breakOnPreShow to true.

This is my code in the function above and with the function called inside it. As you can see bellow, if the condition is checked I will set the creakOnPreShow to true and call an handler that will, on sucess, build my custom window.

 

    addItems: function (featureInfo) {
        var breakOnPreShow = false;

        if (/*YOUR CONDITION*/) {
            breakOnPreShow = CustomHotspotsUI.Hotspots.prototype.showCustomFeatureInfo(featureInfo);
        }
        return breakOnPreShow;
    },

    showCustomFeatureInfo: function (featureInfo) {
        var breakOnPreShow = true;
        Ext.Ajax.request({
            url: 'CustomHandler.WebClient.ashx',
            method: 'POST',
            timeout: 300000,
            params: {
                action: 'get',
                value: Ext.util.JSON.encode(attributeValue),
                attributes: Ext.util.JSON.encode(featureInfo[0].attributeGroups[0].attributes),
                title: formattedTitle,
                crsId: $crs.getCurrent().get_id()
            },
            failure: function (request) {
                $log.writeError("Hotspot: failure in {0} request. \"{1}\"", 'CustomHandler.WebClient.ashx', String(request));
                return;
            },
            success: function (result) {
                try {
                    if (result.responseText != "") {
                        var res = Ext.decode(result.responseText);
                        if (res.success) {
                            this._currentWindow = CustomHotspotsUI.Hotspot.AdvancedModel.AdvancedModel.get(featureInfo, res.result);
                            this._currentWindow.doLayout();
                            this._currentWindow.show();
                        }
                    }
                } catch (e) {
                    $log.writeError("Hotspot: failure in {0} _preShow. \"{1}\"", 'CustomHandler.WebClient.ashx', e.message);
                } finally {
                    mask.hide();
                }
            },
            scope: this
        });
        return breakOnPreShow;
    },

Best regards

 

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

Re: Custom Feature Info Override

Thanks again!  I have some simple code that works fine except i get both the custom and the default display for the parcel that the user clicks (Parcel with Labels is name in legend).  If the test is met that user has clicked on a parcel, I  would like only the custom display to be shown.  The function ParcelInfo() is the handler for a  custom toolbar command designed to show custom attribute info display if a parcel is clicked.  This is working.  But I need to surpress the default attribute box from displaying as well - i thought it would not display because preventDefaults is set to True.  I think i am not fully understanding the timing of how this works.

 $GP.ui.toolbar.add({
                categoryIndex: 11,
                xtype: "tbbutton",
                tooltip: "Parcel Information",
                iconCls: "x-btn-icon",
                icon: "img/parcel.gif",
                handler: ParcelInfo
            });

 

 

function ParcelInfo() {
                $GP.map.featureInfo({
                    preventDefaults: true // prevents the default feature info
                }, function (result) {
                    // placeholder for custom feature info implementation

                    var serializedResult = $GP.utils.serialize(result);

                    var string1 = serializedResult.slice(1, 200);
                    //alert(string1);
                
                    if (string1.indexOf("Parcels with Labels") > 0) {
                     
                        var p1 = string1.indexOf("Parcel_ID") - 9;
                        var p2 = string1.indexOf(":false}") + 7;
                        var string3 = string1.slice(p1, p2);
                        var obj = JSON.parse(string3);
                        var Parcel_ID = obj.Value;
                        $GP.ui.info("Processing Parcel " + Parcel_ID);

                        window.open("http://cthse-gis/jd_portal/getParcelInfo.asp?parcelid=" + Parcel_ID, "Parcel Information", "location=1,status=1,scrollbars=1, width=300,height=800");
                        $GP.ui.info("Parcel Information displayed");

                    }
                }
                )
            }

 

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

Re: Custom Feature Info Override

I know your time out was for a different purpose but i added one to my code and it is working now!  I only have to click my PARCEL INFO toolbar once and then all subsequent clicks on a parcel give the custom dialog box (and the default one no longer displays).  Is there somewhere i could put the code so i would not need to click the toolbar even once?  The only attribute info i want to display is the custom info for parcels.

Contributor
Posts: 65
Registered: ‎02-10-2017

Re: Custom Feature Info Override

Have you tried to put the code in MapConfig.js file?

In a

Sys.Application.add_init(function() {
}

 ?

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.