Hexagon Geospatial
MENU

WebGIS

Need a push in the right direction when configuring WebMap, Portal or SDI services? Looking for hints and tips, or just looking for Ideas and information? The WebGIS discussion board is where you start those discussions, connect and share information.
Showing results for 
Search instead for 
Do you mean 
Reply
Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Get Geometry Of Selected Feature In Map

[ Edited ]

Hi Everyone,

Hope all is doing well.

 

Can someone please point me in the right direction.

I would like to get the geometry points of a selected feature in the map.(WMPS)

 

Maybe parse the geometry with geojson or something in that line.

Basically I need the points that makes up the closed polygon.

 

Anyhelp would be greatly appreciated.

 

Kind Regards

Jacques

Staff
Posts: 98
Registered: ‎02-10-2017

Re: Get Geometry Of Selected Feature In Map

Hi Jacques.

 

See if this helps you (it is done for only one selected polygon feature):

 

$GP.selectedFeatures.find({}, function (ret) {
	$GP.map.draw.clear();
	if (ret.features.length == 0) {
		alert("No feature selected!");
		return;
	} else if (ret.features.length > 1) {
		alert("It should only be one feature selected!");
		return;
	}
	var features = ret.features[0];
	var feature = features[0];

	feature.get_geoJSON(callback);

	function callback(a) {
		if (a.geometry.type != "Polygon") {
			alert("The selected element is not valid. Please select a polygon!");
		} else {
			//Get Points
			var points = [];
			a.geometry.coordinates[0].forEach(function (point) {
				points.push({
					x : point[0],
					y : point[1]
				})
			});
		}
	}
});
Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi Amarques,

 

Great, thanks a million.

I will test at latest tomorrow and get back to you.

 

Kind Regards

Jacques

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi Amarques,

 

Sorry for only repsonding now.

I have tested your snippet,thanks.

 

I am having some trouble with it.

It does not enter the callback function.

Did run fidlder on it,I can see the call being made , but no response get returned.(even waited for 15min...still nothing)

I am running Geospatial Portal 16 EP 04.

 

Any idea what can be causing this?

 

Kind Regards

Jacques

 

Highlighted
Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi,

 

Sorry we are using 16.00.0200 at this specific client.

 

Cant remember if that relates to Ep02 or 4,most probably 2.

 

Kind Regards

Jacques

 

 

Staff
Posts: 98
Registered: ‎02-10-2017

Re: Get Geometry Of Selected Feature In Map

Hi Jacques.

 

I did a quick test using this code in an 2016 EP04 installation and it worked fine.

The get_geoJSON request takes a while to execute (using the USA demo data with a state selected it took 25s) but it runs the callbak function.

I don't have any installation with the EP02 so I cannot do the same test.

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi Amarques,

 

Thanks for all the help I appreciate it.

I have tested this on 2 seperate Portal SDK instances.

No callback is generated and it causes IIS not to respond.

Have to restart IIS after each call.

Unfortunatly we cannot upgrade to the latest versions at this point due to development not meeting the deadline.

I will try to investigate the issue, maybe there is an error being raised somewhere.

Do you maybe have any other idea on how to get the geometry of a selected feature without a callback?

 

Kind Regards

Jacques

 

Staff
Posts: 98
Registered: ‎02-10-2017

Re: Get Geometry Of Selected Feature In Map

Hi Jacques.

 

Based on the SDK function get_geoJSON you must have the callback function to obtain this:

 

if (!isSet(callback)) warn("Deprecated: get_geoJSON on a proxy feature object without a callback function");

but you could try to pass another function for catching the error.

The signature of this function is:

get_geoJSON: function (callback, errback)

 

So, instead of passing only the first callback you can pass another on that will be called if an error occurs.

 

Hope this helps.

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi Amarques,

 

Yeah, I saw that it requires the callback.

I will add the error handler and see if I can get some more insight.

 

Thanks.

 

If everything else fails I will see if I can manage a workaround that will not be affected by future updates.

 

Will report back.

 

Kind Regards

Jacques

Regular Contributor
Posts: 207
Registered: ‎07-27-2016

Re: Get Geometry Of Selected Feature In Map

Hi Amarques,

 

Sorry for the delayed response.

So, thanks for all the help.

I did use part of your suggestions and you did help regarding what can be done.

 

So what I did at the end of the day was I added a function to my self contained WCF service that returns the geometry points in json format from SQL server.

In portal the user will click the feature and return the feature ID.I then call the service with the feature ID and work with the returned json object.

 

Thanks for all the help.

 

Kind Regards

Jacques

Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.