我比较新,所以对这个问题可能有一个非常简单的答案,但是如何在Java中为KmlLayer添加'setPreserveViewport'选项?我找到了一个解决方案,但这并不能很好地显示多个KML图层。
所以我现在拥有的是:
final KmlLayer KMLmap1 = KmlLayer.create("https://earthbuilder.googleusercontent.com/04956359305736194955-05414812628978701557-4/2/kml/link.kml");
final KmlLayer KMLmap2 = KmlLayer.create("https://dl.dropboxusercontent.com/u/20845226/alledanmarks5regioner.kml");
class KMLButtonPanel extends FlowPanel {
public KMLButtonPanel() {
Button KML1Btn = new Button("KML 1", new ClickHandler() {
public void onClick(ClickEvent event) {
kmlUnload(KMLmap2);
kmlLoad(KMLmap1);
}
});
Button KML2Btn = new Button("KML 2", new ClickHandler() {
public void onClick(ClickEvent event) {
kmlUnload(KMLmap1);
kmlLoad(KMLmap2);
}
});
}
public void onModuleLoad() {
private void kmlLoad(KmlLayer layer) {
layers = layer;
layers.setMap(map);
}
private void kmlUnload(KmlLayer layer) {
layers = layer;
layers.setMap(null);
}
}
我还有很多其他代码,所以我刚刚复制了相关的行。现在我想做的事情是以某种方式添加setPreserveViewport(true)选项 - 这就是我所处的位置!我该怎么做?
答案 0 :(得分:0)
对于任何有兴趣的人来说,解决方案非常简单:
private KmlLayer layers;
private String KMLmap1 = "https://earthbuilder.googleusercontent.com/04956359305736194955-05414812628978701557-4/2/kml/link.kml";
private String KMLmap2 = "https://dl.dropboxusercontent.com/u/20845226/alledanmarks5regioner.kml";
然后当我运行kmlLoad(KMLmap1);或kmlLoad(KMLmap2);我明白了:
private void kmlLoad(String string) {
if (layers != null) {
kmlUnload();
}
KmlLayerOptions layerOpts = KmlLayerOptions.create();
layerOpts.setPreserveViewport(true);
KmlLayer newlayers = KmlLayer.create(
string,
layerOpts
);
layers = newlayers;
newlayers.setMap(map);
}
private void kmlUnload() {
layers.setMap(null);
}