Hi,

You should use Overlays (see
http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOverlay.html
)

In your case :

public class Location extends JavaScriptObject {
  public static final native Location create(double latitude, double
longitude) /*-{ return $wnd.Microsoft.Maps.Location(latitude, longitude);
}-*/;

  // Typically, methods on overlay types are JSNI
  public final native String getLatitude() /*-{ return this.latitude; }-*/;
  public final native void setLatitude(String latitude)  /*-{ this.latitude
= latitude;  }-*/;
}

// push them in an JsArray
Location timbuktu = Location.create(lat1, lng1);
Location kabara = Location.create(lat2, lng2);
JsArray<Location> locations = JsArray.createArray().cast();
locations.push(timbuktu);
locations.push(kabara);

// and with JSNI
public native void addPolyline(JsArray<Location> locations)/*-{
    var line = new $wnd.Microsoft.Maps.Polyline(locations);
    var firstLocation = locations[0];
    map.setView( {zoom:8, center:firstLocation});
    map.entities.push(line);
}-*/;


Alexandre.


2011/9/7 Jésica <cuello.jes...@gmail.com>

> 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 <alexandre.ardh...@gmail.com>
> 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 <cuello.jes...@gmail.com>
> >
> > > 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
> 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.
> >
> >
>
> --
> 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.
>
>

-- 
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.

Reply via email to