我正在使用GMapsFX创建一个简单的地图。此地图应显示两个带有不同图标的标记:红色圆圈和蓝色圆圈。但是,当我尝试运行下面显示的代码时,两个标记都使用相同的图标。当我手动更改缩放时,此问题似乎已自行解决,但在使用GMapsFX缩放方法更改缩放时则无法解决此问题。
图片显示问题
控制器
package map;
import java.net.URL;
import java.util.ResourceBundle;
import com.lynden.gmapsfx.GoogleMapView;
import com.lynden.gmapsfx.MapComponentInitializedListener;
import com.lynden.gmapsfx.javascript.object.GoogleMap;
import com.lynden.gmapsfx.javascript.object.LatLong;
import com.lynden.gmapsfx.javascript.object.MapOptions;
import com.lynden.gmapsfx.javascript.object.MapTypeIdEnum;
import com.lynden.gmapsfx.javascript.object.Marker;
import com.lynden.gmapsfx.javascript.object.MarkerOptions;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
public class Controller implements Initializable,
MapComponentInitializedListener {
@FXML
protected GoogleMapView view;
private GoogleMap map;
@Override
public void initialize(URL url, ResourceBundle rb) {
view.addMapInializedListener(this);
}
@Override
public void mapInitialized() {
MapOptions options = new MapOptions();
options
.center(new LatLong(40.7127, -74.0059))
.mapType(MapTypeIdEnum.ROADMAP)
.zoom(12);
map = view.createMap(options);
view.setKey("");
showMarker(40.748433, -73.985656, "https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Disc_Plain_red.svg/32px-Disc_Plain_red.svg.png");
showMarker(40.713, -74.0135, "https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Disc_Plain_blue.svg/32px-Disc_Plain_blue.svg.png");
}
/**
* Adds a marker to the map.
*/
public void showMarker(double lat, double lng, String iconPath) {
MarkerOptions options = new MarkerOptions();
options
.icon(iconPath)
.position(new LatLong(lat, lng));
Marker marker = new Marker(options);
map.addMarker(marker);
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import com.lynden.gmapsfx.GoogleMapView?>
<GoogleMapView fx:id="view" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" fx:controller="map.Controller" />
主程序
package map;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MapTesting extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("map.fxml"));
primaryStage.setTitle("Window");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:0)
尝试一下:
String path = file.getAbsolutePath();
String image = MarkerImageFactory.createMarkerImage("file:"+path, "png"); //or jpg
image = image.replace("(", ""); //fix an error of the API
image = image.replace(")", "")
options.icon(image);