2016-04-30 18 views
1

GoogleマップAPIを使用すると、ポイントをリンクするポリラインを含むマップ上にレイヤを作成することができます。グルーオンでポリラインを作成するmapLayer

私はグルーオンのmapLayerのサンプルまたは実装をどこから見つけることができるのか検索しました。 MapViewの上にライン、ポリラインまたはポリゴンを描画するための明示的なAPIはありませんしながら

答えて

3

をアドバイスしてください、MapLayerは、あなたがそれをスケーリングの世話を提供し、あなたはどのJavaFXのShapeを描くことができる層であり、マップ座標。そのため

もしPoiLayerclassを見ている場合、あなたは(緯度および経度によって定義される)任意MapPointためあなたは(xとyによって定義された)2次元ポイントを得ることができることを確認することができ、あなたが描くことができますその位置のノード:今

public class PoiLayer extends MapLayer { 

    private final Polygon polygon; 

    public PoiLayer() { 
     polygon = new Polygon(); 
     polygon.setStroke(Color.RED); 
     polygon.setFill(Color.rgb(255, 0, 0, 0.5)); 
     this.getChildren().add(polygon); 
    } 

    @Override 
    protected void layoutLayer() { 
     polygon.getPoints().clear(); 
     for (Pair<MapPoint, Node> candidate : points) { 
      MapPoint point = candidate.getKey(); 
      Node icon = candidate.getValue(); 
      Point2D mapPoint = baseMap.getMapPoint(point.getLatitude(), point.getLongitude()); 
      icon.setTranslateX(mapPoint.getX()); 
      icon.setTranslateY(mapPoint.getY()); 

      polygon.getPoints().addAll(mapPoint.getX(), mapPoint.getY()); 
     } 
    } 
} 

MapPoint point = new MapPoint(37.396256,-121.953847); 
Node icon = new Circle(5, Color.BLUE); 
Point2D mapPoint = baseMap.getMapPoint(point.getLatitude(), point.getLongitude()); 
icon.setTranslateX(mapPoint.getX()); 
icon.setTranslateY(mapPoint.getY()); 

は、作成したいのであれば、例えば、点の集合に基づいてPolygonは、あなたが持っている層にPolygonオブジェクトを追加します、デモクラスは、mapPointsのセットを作成し、マップに追加します:

private final List<MapPoint> polPoints = Arrays.asList(
     new MapPoint(37.887242, -122.178799), new MapPoint(37.738729, -121.921567), 
     new MapPoint(37.441704, -121.921567), new MapPoint(37.293191, -122.178799), 
     new MapPoint(37.441704, -122.436031), new MapPoint(37.738729, -122.436031)); 

private MapLayer myDemoLayer() { 
    PoiLayer poi = new PoiLayer(); 
    for (MapPoint mapPoint : polPoints) { 
     poi.addPoint(mapPoint, new Circle(5, Color.BLUE)); 
    } 
    return poi; 
} 

そして、あなたはそれの上にあなたの地理的位置ポリゴンで地図を持っています。

poi

+0

ありがとう、優れた答えと実行可能な例:) – Ron

関連する問題