2012-03-08 46 views

回答

4

我設法顯示路線:

KML:將KML座標爲字符串 6.646280,49.753730,0.000000 6.646020,49.753230,0.000000 6.645650,49.752700,0.000000 ... 在這種情況下。

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); 
2

取決於您的路徑格式,但如果您有KML,請使用GML層。

+0

謝謝,您可能有更多的信息給我嗎?將maps.addLayer(新的GML(「路線」,網址)工作,當url返回kml?我使用osm與投影EPSG:900913。我的網址在投影EPSG:4326中返回kml並且它不起作用。改變kml或者你知道一個kml提供者返回投影EPSG:900913 – ZehnVon12 2012-03-08 14:54:36

+0

GWT包裝還沒有覆蓋所有的開放層,所以最好的方法是首先找出如何在開放層JavaSCript中創建一個圖層。例如,如果你還不知道如何去做:http://openlayers.org/dev/examples/接下來使用GWT構建它,並注意到,openlayer屬性和參數在它們自己的類中的GWT包裝中,比如類GMLProperties。如果沒有特定屬性的命名方法,你可以使用屬性名稱作爲第一個參數的通用方法'setProperty'。 – 2012-03-08 15:08:43

+0

有人可以發佈一個小例子,一些代碼行嗎? – ZehnVon12 2012-03-08 16:41:48