2

I use gwt-openlayers.
I still haven't found how to display a route.

Is it possible to display a route with gwt-openlayers?

AmanicA
  • 4,659
  • 1
  • 34
  • 49
ZehnVon12
  • 4,026
  • 3
  • 19
  • 23

2 Answers2

4

I managed to show the route:

KML: the KML-coordinates as String 6.646280,49.753730,0.000000 6.646020,49.753230,0.000000 6.645650,49.752700,0.000000 ... in this case.

Vector routeLayer = new Vector("route");

List<Point> pointList = new ArrayList<Point>();
Projection defaultProj = new Projection(DEFAULT_PROJECTION); 
  // DEFAULT_PROJECTION = "EPSG:4326"
Projection mapProj = new Projection(mapWidget.getMap().getProjection());
for (String coord : KML.split(" "))
{
  String[] xyz = coord.split(",");
  if (xyz.length == 3)
  {
    Point point = new Point(Double.parseDouble(xyz[0]), Double.parseDouble(xyz[1]));
      // lon,lat 
    point.transform(defaultProj, mapProj);
    pointList.add(point);
  }
}
LineString geometry = new LineString(pointList.toArray(new Point[pointList.size()]));
Style style = new Style();
style.setStrokeColor("#0033ff");
style.setStrokeWidth(5);

routeLayer.addFeature(new VectorFeature(geometry, style));

mapWidget.getMap().addLayer(routeLayer);
ZehnVon12
  • 4,026
  • 3
  • 19
  • 23
2

Depends on you rout format, but if you have KML use the GML layer.

Hilbrand Bouwkamp
  • 13,509
  • 1
  • 45
  • 52
  • Thanks, You may have more information for me? Will maps.addLayer(new GML("route", url) work, when url returns the kml? I use osm with projection EPSG:900913. My url returns kml in projection EPSG:4326 and it doesn't works. Is it possible to transform the kml or do you know a kml provider that return projection EPSG:900913 – ZehnVon12 Mar 08 '12 at 14:54
  • The GWT wrapper not yet covers all of open layers. So the best way is to first find out how to create a layer in openlayer JavaSCript. Start with openlayers examples if you not yet known how to do it: http://openlayers.org/dev/examples/. Next build it with GWT, and note that openlayer properties and parameters are in the GWT wrapper in classes of their own, like the class GMLProperties. If there is no named method for a specific property, you can use the generic method `setProperty` with the property name as the first parameter. – Hilbrand Bouwkamp Mar 08 '12 at 15:08