Google Earth JSNI Help?
Hi guys, I am working on a GWT project that when the application starts up, Google Earth is automatically loaded onto the page. After that, I want it that the user clicks a button that says enable polygon drawing, the application will allow the user to be able to draw polygons on Google Earth. I found an example online for creating polygons on Google Earth using JavaScript. (http://earth-api-samples.googlecode.com/svn/trunk/demos/ draw/index.html) However, now I need to add the JavaScript code in that example into a GWT class (which I'm trying to do with JSNI). The problem is, I'm not sure how to correctly do it, I've tried adding the JavaScript code from the example into GWT (see below) and then just opening Google Earth in the HTML document but it doesn't seem to work. If anyone can help me at all, that would be greatly appreciated! Thanks in advance, David CODE: private native void polygondraw(JavaScriptObject ge) /*-{ var ge = null; var isMouseDown = false; var lineStringPlacemark = null; var coords = null; var pointCount = 0; var doc = null; function init() { google.earth.createInstance(map3d, initCB, failureCB); } function initCB(object) { ge = object; ge.getWindow().setVisibility(true); doc = ge.createDocument(''); ge.getFeatures().appendChild(doc); google.earth.addEventListener(ge.getGlobe(), 'mousemove', onmousemove); google.earth.addEventListener(ge.getGlobe(), 'mousedown', onmousedown); } function onmousemove(event) { if (isMouseDown) { coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); } } function convertLineStringToPolygon(placemark) { var polygon = ge.createPolygon(''); var outer = ge.createLinearRing(''); polygon.setOuterBoundary(outer); var lineString = placemark.getGeometry(); for (var i = 0; i lineString.getCoordinates().getLength(); i++) { var coord = lineString.getCoordinates().get(i); outer.getCoordinates().pushLatLngAlt(coord.getLatitude(), coord.getLongitude(), coord.getAltitude()); } placemark.setGeometry(polygon); } function onmousedown(event) { if (isMouseDown) { isMouseDown = false; coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); convertLineStringToPolygon(lineStringPlacemark); } else { isMouseDown = true; lineStringPlacemark = ge.createPlacemark(''); var lineString = ge.createLineString(''); lineStringPlacemark.setGeometry(lineString); lineString.setTessellate(true); lineString.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND); lineStringPlacemark.setStyleSelector(ge.createStyle('')); var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle(); lineStyle.setWidth(4); lineStyle.getColor().set('ddff'); // aabbggrr formatx lineStyle.setColorMode(ge.COLOR_RANDOM); var polyStyle = lineStringPlacemark.getStyleSelector().getPolyStyle(); polyStyle.getColor().set('ddff'); // aabbggrr format polyStyle.setColorMode(ge.COLOR_RANDOM); coords = lineString.getCoordinates(); coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); doc.getFeatures().appendChild(lineStringPlacemark); } } function failureCB(object) { } }-*/; -- You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to google-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Google Earth JSNI Help?
Hi David, I suspect that you aren't getting much help because there are a bunch of issues with your code and it would take a while to identify them all and produce a working example. Here are a few things that might get you going in the right direction: 1) References to globals like google.earth... need to begin with $wnd because GWT javascript is loaded into a separate iframe. Any global APIs that you use will need $wnd in front of them like $wnd.google.earth.createInstance. 2) Your native function takes a JavaScriptObject ge and then declares a var ge that you set to null. I'm not sure what your plan is for this object, but setting it to null is probably not what you want. 3) Your method contains some var declarations and a bunch of function declarations, but as far as I can tell it doesn't do anything with them. Something needs to call your init() function. What I would suggest to get things going quickly is to move all of this Javascript into a separate javascript file included in your html page and then use $wnd.init() to call your init() method from a native JSNI method in your GWT code. Hope that helps, Andy On Jan 16, 6:27 pm, Daivd Lamm dgjst...@gmail.com wrote: Hi guys, I am working on a GWT project that when the application starts up, Google Earth is automatically loaded onto the page. After that, I want it that the user clicks a button that says enable polygon drawing, the application will allow the user to be able to draw polygons on Google Earth. I found an example online for creating polygons on Google Earth using JavaScript. (http://earth-api-samples.googlecode.com/svn/trunk/demos/ draw/index.html) However, now I need to add the JavaScript code in that example into a GWT class (which I'm trying to do with JSNI). The problem is, I'm not sure how to correctly do it, I've tried adding the JavaScript code from the example into GWT (see below) and then just opening Google Earth in the HTML document but it doesn't seem to work. If anyone can help me at all, that would be greatly appreciated! Thanks in advance, David CODE: private native void polygondraw(JavaScriptObject ge) /*-{ var ge = null; var isMouseDown = false; var lineStringPlacemark = null; var coords = null; var pointCount = 0; var doc = null; function init() { google.earth.createInstance(map3d, initCB, failureCB); } function initCB(object) { ge = object; ge.getWindow().setVisibility(true); doc = ge.createDocument(''); ge.getFeatures().appendChild(doc); google.earth.addEventListener(ge.getGlobe(), 'mousemove', onmousemove); google.earth.addEventListener(ge.getGlobe(), 'mousedown', onmousedown); } function onmousemove(event) { if (isMouseDown) { coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); } } function convertLineStringToPolygon(placemark) { var polygon = ge.createPolygon(''); var outer = ge.createLinearRing(''); polygon.setOuterBoundary(outer); var lineString = placemark.getGeometry(); for (var i = 0; i lineString.getCoordinates().getLength(); i++) { var coord = lineString.getCoordinates().get(i); outer.getCoordinates().pushLatLngAlt(coord.getLatitude(), coord.getLongitude(), coord.getAltitude()); } placemark.setGeometry(polygon); } function onmousedown(event) { if (isMouseDown) { isMouseDown = false; coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); convertLineStringToPolygon(lineStringPlacemark); } else { isMouseDown = true; lineStringPlacemark = ge.createPlacemark(''); var lineString = ge.createLineString(''); lineStringPlacemark.setGeometry(lineString); lineString.setTessellate(true); lineString.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND); lineStringPlacemark.setStyleSelector(ge.createStyle('')); var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle(); lineStyle.setWidth(4); lineStyle.getColor().set('ddff'); // aabbggrr formatx lineStyle.setColorMode(ge.COLOR_RANDOM); var polyStyle = lineStringPlacemark.getStyleSelector().getPolyStyle(); polyStyle.getColor().set('ddff'); // aabbggrr format polyStyle.setColorMode(ge.COLOR_RANDOM); coords = lineString.getCoordinates(); coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); doc.getFeatures().appendChild(lineStringPlacemark); } } function failureCB(object) { } }-*/; -- You
JSNI Help
Hi, I am trying to make a jsni method call and using the return value, I want to invoke another method in the calling html. Using the getData() method in the html, I am calling getId() whose implementation is in the gwt module. The getId returns an Id which is used to make another function call from the parent html. *JS in html* var id; function getData(){ getId(); if(typeof(id)!== 'undefined') { fetchData(id); } } function fetchData(id){ // Implementation here } *JSNI code* public native void publishGetId() /*-{ var jsId = th...@com.foo.test::instanceId; $wnd.getId = function() { $wnd.id = jsId; }; }-*/; the instanceId is an int and non static and on the pageload is not initialised, but is updated at a later stage. The method is publishGetId is called on the onModuleLoad. *The strange behavior that i am facing is that even though the instanceId is getting updated the jsId is not reflecting the same.It shows undefined all the time.* The getData() is called from the parent html after gwt module is loaded and after the instanceId is updated. Any help would be greatly appreciated. Thanks Sudeep --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~--~~~~--~~--~--~---
Re: JSNI Help
This the code that I am using currently. On Sat, Oct 17, 2009 at 5:12 PM, Sudeep S sudee...@gmail.com wrote: Hi, I am trying to make a jsni method call and using the return value, I want to invoke another method in the calling html. Using the getData() method in the html, I am calling getId() whose implementation is in the gwt module. The getId returns an Id which is used to make another function call from the parent html. *JS in html* var id; function getData(){ getId(); if(typeof(id)!== 'undefined') { fetchData(id); } } function fetchData(id){ // Implementation here } *JSNI code* public native void publishGetId() /*-{ $wnd.getId = function() { *var jsId = **th...@com.foo.test::instanceId*th...@com.foo.test::instanceId *; * $wnd.id = jsId; }; }-*/; the instanceId is an int and non static and on the pageload is not initialised, but is updated at a later stage. The method is publishGetId is called on the onModuleLoad. *The strange behavior that i am facing is that even though the instanceId is getting updated the jsId is not reflecting the same.It shows undefined all the time.* The getData() is called from the parent html after gwt module is loaded and after the instanceId is updated. Any help would be greatly appreciated. Thanks Sudeep --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to google-web-toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
Hi Guys, Iam Still Struck . can anyone provide some sample Code.or any articles to explan in detail Thank u, jagadesh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
Your snippet to create a New Person instance in jsni will not work. Whilst the compiler will not report a compile time error,your code will fail whenver some java code attempts to do anything with that instance. There are many wrong assumptions wwirh your advice... @ Properties and method names get mangled - you must jsni styled references to these rather than literals. @ The prototype is not set so any attempt to call real Person methods will also fail. Anything relati g to the type of the instance will also fail because the gwt emulation of java in is won't know what type your Person instance is. @ All you hav achieved is to create a fake but broken javascript object that is telling the compiler it's a Person but it's not... Hth On Mar 2, 8:01 pm, sutarsa giri sutarsa.g...@gmail.com wrote: sory, i make a mistake when pressing keyboard, so message sent before i finish typing sample is like this class Person extends JavaScriptObject{ protected Person(){} public native String getUserName ()/*-{return this.username.}-*/; public native void setUserName(String name)/*-{this.username=name;}-*/; } and on jsni method : private native Person test()/*-{ var a={username:some username} return a; }-*/; i think this trick will work On Mon, Mar 2, 2009 at 4:58 PM, sutarsa giri sutarsa.g...@gmail.com wrote: you may could set the jsni method return instance of subclass of com.google.gwt.core.client.JavaScriptObject for example : class Person extends JavaScriptObject{ } On Mon, Mar 2, 2009 at 4:34 PM, jagadesh jagadesh.manch...@gmail.comwrote: Hi i read the article. i was able to get the primitive values liks String , int e.t.c. i want an javascript object to be transmitted to java Code[Gwt ] . Thank u, jagadesh. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
On 3 mar, 14:07, mP miroslav.poko...@gmail.com wrote: Your snippet to create a New Person instance in jsni will not work. Whilst the compiler will not report a compile time error,your code will fail whenver some java code attempts to do anything with that instance. There are many wrong assumptions wwirh your advice... @ Properties and method names get mangled - you must jsni styled references to these rather than literals. Wrong; in that specific case, that's the other way around: wrapping a JavaScript object in Java code. The code is not trying to get/set a Java field's value from JavaScript, but getting/setting a JavaScript property from Java. However, I would have wrote the test() method in pure Java: private Person test() ' Person p = JavaScriptObject.createObject().cast(); o.setUserName(some username); return o; } @ The prototype is not set so any attempt to call real Person methods will also fail. Wrong (sort of). The Person Java class, can have any methods you like, provided they are 'final'. The corresponding/wrapped JS object may have methods too, either as own properties or inherited from its prototype (toString() for instance, as the prototype defaults to Object.prototype in the given code sample) and you'd call them using JSNI, the same way get/ setUserName accesses a property. Note that using the suggested approach of JavaScriptObject (JS overlay types) doesn't preclude setting the native JS prototypes if you do instantiate such overlay objects. Anything relati g to the type of the instance will also fail because the gwt emulation of java in is won't know what type your Person instance is. Right, JS overlay types are just syntactic sugar to help you work with pure JS objects from the Java world. @ All you hav achieved is to create a fake but broken javascript object that is telling the compiler it's a Person but it's not... Wrong. Maybe you should give a look at http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5t=DevGuideOverlayTypes --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
Hi i read the article. i was able to get the primitive values liks String , int e.t.c. i want an javascript object to be transmitted to java Code[Gwt ] . Thank u, jagadesh. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
you may could set the jsni method return instance of subclass of com.google.gwt.core.client.JavaScriptObject for example : class Person extends JavaScriptObject{ } On Mon, Mar 2, 2009 at 4:34 PM, jagadesh jagadesh.manch...@gmail.comwrote: Hi i read the article. i was able to get the primitive values liks String , int e.t.c. i want an javascript object to be transmitted to java Code[Gwt ] . Thank u, jagadesh. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
sory, i make a mistake when pressing keyboard, so message sent before i finish typing sample is like this class Person extends JavaScriptObject{ protected Person(){} public native String getUserName ()/*-{return this.username.}-*/; public native void setUserName(String name)/*-{this.username=name;}-*/; } and on jsni method : private native Person test()/*-{ var a={username:some username} return a; }-*/; i think this trick will work On Mon, Mar 2, 2009 at 4:58 PM, sutarsa giri sutarsa.g...@gmail.com wrote: you may could set the jsni method return instance of subclass of com.google.gwt.core.client.JavaScriptObject for example : class Person extends JavaScriptObject{ } On Mon, Mar 2, 2009 at 4:34 PM, jagadesh jagadesh.manch...@gmail.comwrote: Hi i read the article. i was able to get the primitive values liks String , int e.t.c. i want an javascript object to be transmitted to java Code[Gwt ] . Thank u, jagadesh. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
Thanks For The Help , sutarsa giri Let me work on the tip you provided. Thank u, jagadesh. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Jsni Help
HI Guys, i just started working with Jsni and Gwt. my requirement is i will be having a html page with 2 textboxes as firstName and lastName. i need to get the values entered in these textfields into my Gwt code. i was able to get the values as string .i have written 2 methods getFirstName () and getLastName() and got the values as Strings.now my need is i need to create a javascript object with both the values set and pass them to Gwt method. How can i do this . --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Jsni Help
Have you read http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5s=google-web-toolkit-doc-1-5t=DevGuideJavaScriptNativeInterface On Mon, Mar 2, 2009 at 3:21 PM, jagadesh jagadesh.manch...@gmail.com wrote: HI Guys, i just started working with Jsni and Gwt. my requirement is i will be having a html page with 2 textboxes as firstName and lastName. i need to get the values entered in these textfields into my Gwt code. i was able to get the values as string .i have written 2 methods getFirstName () and getLastName() and got the values as Strings.now my need is i need to create a javascript object with both the values set and pass them to Gwt method. How can i do this . --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Need some JSNI help/explanation
I am working on a new class and I want to expose instance fields and methods via a prototype via JSNI so I can call from third party script into my GWT code like this. var mySimpleObject = new Simple(test); test.callMyName(); I have been working through a series of examples that build on each other but I am not sure that my assumptions about why the ones that work really work and why the ones that fail really fail. Here they are -- JSNI experts please comment! Thanks! package com.test.client; public class Simple { public String name; public Simple(String name) { this.name = name; } public static Simple createSimple(String name) { return new Simple(name); } // this works becuase you are passing in the Simple reference public native void callMyNameWorks(Simple myInstance) /*-{ $wnd.callMyName = function(){ alert( [EMAIL PROTECTED]::name); } alert( [EMAIL PROTECTED]::name); $wnd.callMyName(); }-*/; // this works because we COPY the reference and store it in a closure. public native void callMyNameWorks() /*-{ var myInstance = this; $wnd.callMyName = function(){ alert( [EMAIL PROTECTED]::name); } //this in GWT entrypoint is the Simple object that called this method. alert( [EMAIL PROTECTED]::name); $wnd.callMyName(); }-*/; // this broken because this is not the right object when our new function // gets called. public native void callMyNameHalfBroken() /*-{ $wnd.callMyName = function(){ //this will break because at this is actually the window object now (or who called the method) alert( [EMAIL PROTECTED]::name); } //this works b/c GWT entrypoint is the Simple object that called this method. alert( [EMAIL PROTECTED]::name); $wnd.callMyName(); }-*/; public static native void callMyNameStaticGlobalWorks() /*-{ //--- //NOTE: this RETURNS the GWT Simple Object not a js object //--- $wnd.jsSimple = function (name){ return @com.siemens.soarian.sf.uiarch.client.Simple::createSimple(Ljava/lang/ String;)(name) } //myObject must be an instance of the GWT Simple Object $wnd.callMyNameGlobal = function(myGwtJavaObject){ alert([EMAIL PROTECTED]::name); } var myJsSimple = new $wnd.jsSimple(testing); //works bc we pass in the actual GWT Java Simple object $wnd.callMyNameGlobal(myJsSimple); }-*/; public static native void callMyNameStaticGlobalBroken() /*-{ debugger; //--- //NOTE: effectively assigns the value of var name = javascript instance of gwt java object //if you look at the object in debug you will see name.instance is now defined. //name.instance is a reference to the gwt object //--- $wnd.jsSimple = function (name){ this.instance = @com.siemens.soarian.sf.uiarch.client.Simple::createSimple(Ljava/lang/ String;)(name); } //myObject must be an instance of the GWT Simple Object $wnd.callMyNameGlobal = function(myobject){ alert([EMAIL PROTECTED]::name); } //debug shows that there is now a name.instance defined; var myJsSimple = new $wnd.jsSimple(testing); $wnd.callMyNameGlobal(myJsSimple); }-*/; public static native void callMyNameStaticLocalBroken() /*-{ debugger; //--- //NOTE: effectively assigns the value of var name = javascript instance of gwt java object //if you look at the object in debug you will see name.instance is now defined. //name.instance is a reference to the gwt object //--- $wnd.jsSimple = function (name){ this.instance = @com.siemens.soarian.sf.uiarch.client.Simple::createSimple(Ljava/lang/ String;)(name); } //store a copy of the prototype reference to use later var _= $wnd.jsSimple.prototype; _.callMyNameLocal = function(){ //who is this when its called? it won't be a GWT Java Simple object!!! //it is actually the javascript object -- So the myInstance[blah blah] will be undefined var myInstance = this; alert([EMAIL PROTECTED]::name); } var myJsSimple = new $wnd.jsSimple(testing); myJsSimple.callMyNameLocal(); }-*/; public static native void callMyNameStaticLocalWorks1() /*-{