Thanks for your help Alexandre, I would like to add more context to
the issue I'm facing:
I have a domain object called Location, with the following structure:
public class Location{
Double latitude;
Double longitude;
(...)
}
**********************************************************************************************
public class Test implements EntryPoint {
MapWrapper map = MapWrapper.getMapWrapper();
map.getMap();
Collection<Location> locations = new ArrayList<Location>();
locations.add(timbuktu);
locations.add(kabara);
//Routes section - Polyline
JsArrayString locationsJS = JsArrayString.createArray().cast();
for (Location location : locations) {
locationsJS.push("{latitude:"+ location.getLatitude() +",
longitude:"+location.getLongitude()+"}");
}
map.addPolyline(locationsJS);
}
**********************************************************************************************
And this is what addPolyline does:
public native void addPolyline(JsArrayString locations)/*-{
var locationsArray = new Array();
for (var i=0; i<locations.length; i++) {
var parsedJSON = eval('('+locations[i]+')');
var latitude=parsedJSON.latitude;
var longitude=parsedJSON.longitude;
var locationMS = new $wnd.Microsoft.Maps.Location(latitude,
longitude);
locationsArray[i] = locationMS;
}
var line = new $wnd.Microsoft.Maps.Polyline(locationsArray);
var firstLocation = locationsArray[0];
map.setView( {zoom:8, center:firstLocation});
map.entities.push(line);
}-*/;
**********************************************************************************************
I would like to know if there is a better way for handling the array
of Java objects. The thing here is that I wouldn't be working with
single objects like numbers or strings, but with a custom Java object.
Do I need to build a wrapper for doing It? -something like
JsLocationArray-, and add in there the possibility of pushing a
Location instead of the JSON structure I'm using?
Jésica.
On Sep 7, 5:13 am, Alexandre Ardhuin <[email protected]>
wrote:
> Hi,
>
> As said
> inhttp://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI...,
> Java arrays appear to javascript as "opaque value that can only be passed
> back into Java code".
> You have to use JsArray, JsArrayBoolean, JsArrayInteger, JsArrayNumber or
> JsArrayString to pass javascript arrays.
>
> Alexandre.
>
> 2011/9/6 Jésica <[email protected]>
>
> > Hi, I'm having a JS exception saying "null" when running the following
> > code:
>
> > //Java Code
> > bingMap.addPolyline(locationsArray);
>
> > //JSNI Code
> > public native void addPolyline(Location[] locations)/*-{
> > for (var i = 0; i < locations.length; i++){
> > alert(locations[i]);
> > }
> > }-*/
>
> > Is an extra processing required when managing arrays passed by
> > parameter to a native method?
> > Thanks in advance!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.