0

我想将 JXMaps 中的 MapView 添加到 JavaFX 中的 VBox,我尝试将 MapView 添加到边框面板,然后添加到 VBox,但我找不到任何解决方案,希望你能帮助我,这个是我的代码:

 public class ControlerMap
 {
     @FXML private BorderPane borderPanel;
     @FXML private Button butom;
     @FXML VBox cosa;

     @FXML public void initialize() 
     {
         MapView sample = new MapView();
         sample.setMaxHeight(394.0);
         sample.setPrefWidth(704.0);
         sample.setVisible(true);
         borderPanel = new BorderPane(sample);
         borderPanel.setVisible(true);
         borderPanel.setLayoutX(76.0);
         borderPanel.setLayoutY(134.0);
         borderPanel.setPrefHeight(200.0);
         borderPanel.setPrefWidth(467.0);
         cosa.getChildren().add(borderPanel);
     }
}

这是我的 .FXML 文件中的代码:

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" 
minWidth="-Infinity" prefHeight="496.0" prefWidth="757.0" 
xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="prueba.web.googleMap.ControlerMap">
<children>
      <Button fx:id="butom" layoutX="25.0" layoutY="14.0" 
     mnemonicParsing="false" text="Button" />
     <VBox fx:id="cosa" layoutX="32.0" layoutY="68.0" prefHeight="394.0" 
      prefWidth="704.0">
      <children>
         <BorderPane fx:id="borderPanel" prefHeight="400.0" 
             prefWidth="704.0" />
      </children>
     </VBox>
  </children>
</AnchorPane>
4

1 回答 1

1

正如我所看到的,您创建了空的 MapView。

MapView sample = new MapView();

只有在初始化其属性(至少是缩放和中心)之后才会实际绘制地图。您必须按以下方式设置它:

sample.setOnMapReadyHandler(new MapReadyHandler() {
       @Override
       public void onMapReady(MapStatus status) {
          if (status == MapStatus.MAP_STATUS_OK) {
              final Map map = mapView.getMap();
              map.setCenter(new LatLng(35.91466, 10.312499));
              map.setZoom(2.0);
          }
       }
});
于 2017-11-02T15:37:27.600 回答