I'm working on a GIS application using a program called Manifold, scripted in Javascript. The app works fine but I need to customize part of it and have been told that the best way to handle the problem is in .Net. So I've figured out how to write a freestanding
.Net function that does the job -- but I'm not sure how to integrate it into my Javascript.
More specifically: The Mapping program creates a loop spits out a bunch of .png files that contain pieces of the map. What I need to do is insert a routine that crops each .png file as part of the loop.
Right now the javascript concludes with
// Spit out the map
Response.BinaryWrite(mapserver.Render());
What I need to do is save this information into a variable and run my .Net routine. As a freestanding app, it looks like this....
dim myBitmap as New Bitmap(server.mappath("images/theimage.jpg"))
dim memStream As New MemoryStream()
dim myBitmapCropped as New Bitmap(128,128)
dim myGraphic = Graphics.FromImage(myBitmapCropped)
myGraphic.DrawImage(myBitmap, new Rectangle(0,0,128,128),40,40,128,128,GraphicsUnit.Pixel)
myGraphic.dispose()
response.contenttype="image/jpeg"
myBitmapCropped.save(memStream, imageformat.png)
memStream.WriteTo(response.outputStream)
'tidy up
myBitmap.dispose()
myBitmapCropped.dispose()
End Sub
</script>
So in sum, I need to learn how to a) integrate a .Net function into my javascript and b) carry over info from javascript into a .Net variable.
The only ways to integrate a .NET function (server-side function I'm assuming) into JavaScript is to do a PostBack, calling the server-side function, or use AJAX/ATLAS with a server-side function callback.
Example using a PostBack:
In the JavaScript function when you want to call the server-side function, add:
__doPostBack('CallSpecialFunction', 'any arguments necessary');
In the Page_Load event handler:
if ( IsPostBack )
{
object eventTargetObject = this.Request["__EVENTTARGET"];
object eventArgumentObject = this.Request["__EVENTARGUMENT"];
Somebody on the GIS side suggested that I rewrite the Javascript stuff in .Net so I don't have to do the switch... Manifold scripts can be written in either, so that sounds like the logical way to go-- I just have to deal with syntax issues -- so I'm going
to give that a shot... thanks...
I think that you might be confusing Java server-side code with JavaScript. JavaScript is a scripting language that runs on the client. Java server-side code is regular Java code that runs on the server.
There is not much conversion (or let's say it would be very a tough task) that you could do between JavaScript and .NET (server-side) code as they basically do different things.
None
0 Points
4 Posts
Inserting .Net function into Javascript
May 31, 2006 11:18 AM|gebelo|LINK
I'm working on a GIS application using a program called Manifold, scripted in Javascript. The app works fine but I need to customize part of it and have been told that the best way to handle the problem is in .Net. So I've figured out how to write a freestanding .Net function that does the job -- but I'm not sure how to integrate it into my Javascript.
More specifically: The Mapping program creates a loop spits out a bunch of .png files that contain pieces of the map. What I need to do is insert a routine that crops each .png file as part of the loop.
Right now the javascript concludes with
// Spit out the map
Response.BinaryWrite(mapserver.Render());
What I need to do is save this information into a variable and run my .Net routine. As a freestanding app, it looks like this....
<%@ Page Language="vb" Debug="true" Trace="true" %>
<%@ import Namespace="system.drawing" %>
<%@ import Namespace="system.drawing.imaging" %>
<%@ import Namespace="system.io" %>
<script runat="server">
Sub Page_Load
dim myBitmap as New Bitmap(server.mappath("images/theimage.jpg"))
dim memStream As New MemoryStream()
dim myBitmapCropped as New Bitmap(128,128)
dim myGraphic = Graphics.FromImage(myBitmapCropped)
myGraphic.DrawImage(myBitmap, new Rectangle(0,0,128,128),40,40,128,128,GraphicsUnit.Pixel)
myGraphic.dispose()
response.contenttype="image/jpeg"
myBitmapCropped.save(memStream, imageformat.png)
memStream.WriteTo(response.outputStream)
'tidy up
myBitmap.dispose()
myBitmapCropped.dispose()
End Sub
</script>
So in sum, I need to learn how to a) integrate a .Net function into my javascript and b) carry over info from javascript into a .Net variable.
Any assistance would be greatly appreciated...
All-Star
40630 Points
15348 Posts
Re: Inserting .Net function into Javascript
May 31, 2006 12:20 PM|NC01|LINK
The only ways to integrate a .NET function (server-side function I'm assuming) into JavaScript is to do a PostBack, calling the server-side function, or use AJAX/ATLAS with a server-side function callback.
Example using a PostBack:
In the JavaScript function when you want to call the server-side function, add:
__doPostBack('CallSpecialFunction', 'any arguments necessary');
In the Page_Load event handler:
if ( IsPostBack )
{
object eventTargetObject = this.Request["__EVENTTARGET"];
object eventArgumentObject = this.Request["__EVENTARGUMENT"];
if ( (eventTargetObject != null) && (eventTargetObject.ToString() == "CallSpecialFunction" ) )
{
string eventArgument = eventArgumentObject.ToString();
specialFunction(eventArgument);
}
}
For AJAX/ATLAS, here are some informational links:
http://ajax.schwarz-interactive.de/csharpsample/default.aspx
http://atlas.asp.net/Default.aspx?tabid=47
http://atlas.asp.net/docs/Walkthroughs/GetStarted/ServerAutoComplete.aspx
BTW, you would have to have access to the JavaScript to insert the call.
NC...
None
0 Points
4 Posts
Re: Inserting .Net function into Javascript
May 31, 2006 12:35 PM|gebelo|LINK
Somebody on the GIS side suggested that I rewrite the Javascript stuff in .Net so I don't have to do the switch... Manifold scripts can be written in either, so that sounds like the logical way to go-- I just have to deal with syntax issues -- so I'm going to give that a shot... thanks...
All-Star
40630 Points
15348 Posts
Re: Inserting .Net function into Javascript
May 31, 2006 12:44 PM|NC01|LINK
I think that you might be confusing Java server-side code with JavaScript. JavaScript is a scripting language that runs on the client. Java server-side code is regular Java code that runs on the server.
There is not much conversion (or let's say it would be very a tough task) that you could do between JavaScript and .NET (server-side) code as they basically do different things.
NC...