
Quote from asmat on April 17, 2019, 4:24 pmHow can I convert the below script code to javascript subroutine?
https://tinyurl.com/y2lxz5r8
https://tinyurl.com/y4v96f97
How can I convert the below script code to javascript subroutine?

Quote from luishp on April 18, 2019, 7:36 pmHi @asmat,
Please take a look here to understand how to create a subroutine or a plugin from JavaScript function:
https://visualneo.com/forum/topic/plugin-generator-and-subroutines-sample
Hi @asmat,
Please take a look here to understand how to create a subroutine or a plugin from JavaScript function:
https://visualneo.com/forum/topic/plugin-generator-and-subroutines-sample

Quote from asmat on April 18, 2019, 10:16 pmI have made a simple plugin but it does not work look at following link:
https://tinyurl.com/yy9lfftn
Please mention my mistakes.
I have made a simple plugin but it does not work look at following link:
Please mention my mistakes.

Quote from luishp on April 19, 2019, 9:28 pmI'm answering from my phone so I can't test it, but the problem is you are returning the location value to nowhere.
Will get back to this as soon as I can but you are really close.
I'm answering from my phone so I can't test it, but the problem is you are returning the location value to nowhere.
Will get back to this as soon as I can but you are really close.

Quote from luishp on April 20, 2019, 8:26 pm@asmat, take a look at the attached documents (plugin and sample App).
This is a special case because you have choosen a JavaScript function that calls another one and we need some way to preserve the parameters between functions. There is probably a better solution than mine, but it works.
@asmat, take a look at the attached documents (plugin and sample App).
This is a special case because you have choosen a JavaScript function that calls another one and we need some way to preserve the parameters between functions. There is probably a better solution than mine, but it works.
Quote from clueadventures on April 29, 2019, 4:46 pmGreat plugin - do you know if anyone has created a 'haversine' plug to calculated distance between two geo locations?
I have the javascript code, just not overly sure how I'd turn it into a plug in:
function distance(lon1, lat1, lon2, lat2) { var R = 6371; // Radius of the earth in km var dLat = (lat2-lat1).toRad(); // Javascript functions in radians var dLon = (lon2-lon1).toRad(); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * Math.sin(dLon/2) * Math.sin(dLon/2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; // Distance in km return d; } /** Converts numeric degrees to radians */ if (typeof(Number.prototype.toRad) === "undefined") { Number.prototype.toRad = function() { return this * Math.PI / 180; } }
Great plugin - do you know if anyone has created a 'haversine' plug to calculated distance between two geo locations?
I have the javascript code, just not overly sure how I'd turn it into a plug in:
function distance(lon1, lat1, lon2, lat2) {
var R = 6371; // Radius of the earth in km
var dLat = (lat2-lat1).toRad(); // Javascript functions in radians
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
/** Converts numeric degrees to radians */
if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
}
}
Quote from Gaev on April 29, 2019, 7:37 pm@cluadventures:
I have the javascript code, just not overly sure how I'd turn it into a plug in:
Do you have a special requirement to invoke this functionality as a plugin ? ... note that VisualNEOWeb subroutines can be made with VisualNEOWeb commands or Javascript commands ... the code you posted can be setup as a Javascript subroutine (with 4 input and 1 output parameters) quite easily.
@cluadventures:
I have the javascript code, just not overly sure how I'd turn it into a plug in:
Do you have a special requirement to invoke this functionality as a plugin ? ... note that VisualNEOWeb subroutines can be made with VisualNEOWeb commands or Javascript commands ... the code you posted can be setup as a Javascript subroutine (with 4 input and 1 output parameters) quite easily.
Quote from clueadventures on April 30, 2019, 9:05 amThanks, yes I guess so. The help file seems to be somewhat lacking in how to set up subroutines, I'll see what I can find, thank you.
Has anyone had any luck combining this feature with a map?
Thanks, yes I guess so. The help file seems to be somewhat lacking in how to set up subroutines, I'll see what I can find, thank you.
Has anyone had any luck combining this feature with a map?

Quote from asmat on April 30, 2019, 2:12 pmQuote from luishp on April 20, 2019, 8:26 pm@asmat, take a look at the attached documents (plugin and sample App).
This is a special case because you have choosen a JavaScript function that calls another one and we need some way to preserve the parameters between functions. There is probably a better solution than mine, but it works.Thank you so much...
Quote from luishp on April 20, 2019, 8:26 pm@asmat, take a look at the attached documents (plugin and sample App).
This is a special case because you have choosen a JavaScript function that calls another one and we need some way to preserve the parameters between functions. There is probably a better solution than mine, but it works.
Thank you so much...
Quote from Gaev on April 30, 2019, 4:39 pm@clueadventures:
The help file seems to be somewhat lacking in how to set up subroutines
Project >>> Subroutines... (F12) >>> New Subroutine >>> New Javascript Subroutine >>> type name of subroutine (say myCalcDistance)
Since VisualNEOWeb subroutines can accept parameters, you use the section at the bottom right to define them ...
- Alias ... the variable you will use inside the subroutine to refer to the first parameter value
- Type ... defines the type of variable (string, integer etc.)
- Description ... optional but helpful when using the command wizard to compose the calling command- Hint ... optional but helpful when using the command wizard to compose the calling command
Since you will be invoking a subroutine like ...
myCalcDistance "[requestedLatitude1]" "[requestedLongitude1]" "[requestedLatitude2]" "[requestedLongitude2]" "[resultingDistance]"
... you will need 5 parameters e.g. ...
thisLat1 ... type FLOAT
thisLon1 ... type FLOAT
thisLat2 ... type FLOAT
thisLon2 ... type FLOAT
thisDistance ... type VARNAMENow, you add (javascript) commands just like with any other "event section code" (but without the wrapping BeginJS/EndJS) ... use javascript variables thisLat1, thisLat2 etc. inside the subroutine commands to reference the values passed through parameters.
Updated later ... the way to populate the result variable is ...
$App[thisDistance] = blah blah blah;
Hope this helps. If you need help with the Javascript commands, let us know.
@clueadventures:
The help file seems to be somewhat lacking in how to set up subroutines
Project >>> Subroutines... (F12) >>> New Subroutine >>> New Javascript Subroutine >>> type name of subroutine (say myCalcDistance)
Since VisualNEOWeb subroutines can accept parameters, you use the section at the bottom right to define them ...
- Alias ... the variable you will use inside the subroutine to refer to the first parameter value
- Type ... defines the type of variable (string, integer etc.)
- Description ... optional but helpful when using the command wizard to compose the calling command
- Hint ... optional but helpful when using the command wizard to compose the calling command
Since you will be invoking a subroutine like ...
myCalcDistance "[requestedLatitude1]" "[requestedLongitude1]" "[requestedLatitude2]" "[requestedLongitude2]" "[resultingDistance]"
... you will need 5 parameters e.g. ...
thisLat1 ... type FLOAT
thisLon1 ... type FLOAT
thisLat2 ... type FLOAT
thisLon2 ... type FLOAT
thisDistance ... type VARNAME
Now, you add (javascript) commands just like with any other "event section code" (but without the wrapping BeginJS/EndJS) ... use javascript variables thisLat1, thisLat2 etc. inside the subroutine commands to reference the values passed through parameters.
Updated later ... the way to populate the result variable is ...
$App[thisDistance] = blah blah blah;
Hope this helps. If you need help with the Javascript commands, let us know.
Quote from clueadventures on May 3, 2019, 2:10 pmGreat Thank you, I'll have a go
Great Thank you, I'll have a go