04-20-2018 04:53 AM - edited 04-20-2018 04:54 AM
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
04-24-2018 04:01 AM
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] }) }); } } });
04-24-2018 04:23 AM
Hi Amarques,
Great, thanks a million.
I will test at latest tomorrow and get back to you.
Kind Regards
Jacques
04-30-2018 04:21 AM
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
04-30-2018 06:04 AM
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
04-30-2018 06:53 AM
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.
05-02-2018 12:06 AM
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
05-02-2018 05:59 AM
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.
05-02-2018 07:02 AM
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
05-21-2018 01:58 AM
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