使用 GWT Maps v3 更新地图时出现问题
Problems updating a map with GWT Maps v3
我刚刚下载了 https://github.com/branflake2267/GWT-Maps-V3-Api
我安装了它并从他们的演示中复制并粘贴了一些代码。地图已加载并正确显示。然而,除了这个小概述演示之外,没有关于如何使用 MapsWidget 的进一步说明......所以我(可能)有一个简单的问题(但由于缺少文档,我无法自学如何正确使用该库).
这是我的代码所做的。我有一个 lat/lon 坐标列表,我想在地图上显示这条路径的折线。所以,这些是我的程序必须执行的步骤:
- 初始化 MapWidget 并显示地图(有效)
- 如果选择了新路线则更新 MapWidget(不起作用)
所以,这是我的代码(仍然忽略 waypoints):
public class MapsDemoWidget extends SimplePanel {
private static MapWidget mapWidget;
ArrayList<WayPoint> waypoints;
public MapsDemoWidget(ArrayList<WayPoint> waypoints) {
this.waypoints = waypoints;
loadMapApi();
}
private void loadMapApi() {
boolean sensor = true;
// load all the libs for use in the maps
ArrayList<LoadLibrary> loadLibraries = new ArrayList<LoadApi.LoadLibrary>();
loadLibraries.add(LoadLibrary.DRAWING);
loadLibraries.add(LoadLibrary.GEOMETRY);
loadLibraries.add(LoadLibrary.VISUALIZATION);
Runnable onLoad = new Runnable() {
@Override
public void run() {
drawMap();
}
};
LoadApi.go(onLoad, loadLibraries, sensor);
}
private void drawMap() {
LatLng centerCoords = LatLng.newInstance(52.499095d,13.406220d);
MapOptions opts = MapOptions.newInstance();
opts.setZoom(14);
opts.setCenter(centerCoords);
opts.setMapTypeId(MapTypeId.ROADMAP);
mapWidget = new MapWidget(opts);
mapWidget.setSize("750px", "500px");
this.add(mapWidget);
}
}
如您所见:这几乎就是示例代码中的代码。现在在其他一些小部件中,我执行以下操作:
mapsWidget = new MapsDemoWidget(waypoints);
flex.setWidget(mapWidgetRow, 0, mapsWidget);
如果用户选择另一条路线,后面的代码将在另一次调用。
所以基本上,第一次执行代码并正确绘制地图。然后,在选择了另一条路线后,再次执行该代码。然而,第二次之后地图仍然是灰色的。
图中显示了结果。如您所见,在第二步中,显示了地图,但上面没有卡片。第二步,地图已经添加到网站,和第一次一样。
添加 MapDemoWidget
调用后 mapWidget.triggerResize();
它应该解决这个问题。
我刚刚下载了 https://github.com/branflake2267/GWT-Maps-V3-Api
我安装了它并从他们的演示中复制并粘贴了一些代码。地图已加载并正确显示。然而,除了这个小概述演示之外,没有关于如何使用 MapsWidget 的进一步说明......所以我(可能)有一个简单的问题(但由于缺少文档,我无法自学如何正确使用该库).
这是我的代码所做的。我有一个 lat/lon 坐标列表,我想在地图上显示这条路径的折线。所以,这些是我的程序必须执行的步骤:
- 初始化 MapWidget 并显示地图(有效)
- 如果选择了新路线则更新 MapWidget(不起作用)
所以,这是我的代码(仍然忽略 waypoints):
public class MapsDemoWidget extends SimplePanel {
private static MapWidget mapWidget;
ArrayList<WayPoint> waypoints;
public MapsDemoWidget(ArrayList<WayPoint> waypoints) {
this.waypoints = waypoints;
loadMapApi();
}
private void loadMapApi() {
boolean sensor = true;
// load all the libs for use in the maps
ArrayList<LoadLibrary> loadLibraries = new ArrayList<LoadApi.LoadLibrary>();
loadLibraries.add(LoadLibrary.DRAWING);
loadLibraries.add(LoadLibrary.GEOMETRY);
loadLibraries.add(LoadLibrary.VISUALIZATION);
Runnable onLoad = new Runnable() {
@Override
public void run() {
drawMap();
}
};
LoadApi.go(onLoad, loadLibraries, sensor);
}
private void drawMap() {
LatLng centerCoords = LatLng.newInstance(52.499095d,13.406220d);
MapOptions opts = MapOptions.newInstance();
opts.setZoom(14);
opts.setCenter(centerCoords);
opts.setMapTypeId(MapTypeId.ROADMAP);
mapWidget = new MapWidget(opts);
mapWidget.setSize("750px", "500px");
this.add(mapWidget);
}
}
如您所见:这几乎就是示例代码中的代码。现在在其他一些小部件中,我执行以下操作:
mapsWidget = new MapsDemoWidget(waypoints);
flex.setWidget(mapWidgetRow, 0, mapsWidget);
如果用户选择另一条路线,后面的代码将在另一次调用。 所以基本上,第一次执行代码并正确绘制地图。然后,在选择了另一条路线后,再次执行该代码。然而,第二次之后地图仍然是灰色的。
图中显示了结果。如您所见,在第二步中,显示了地图,但上面没有卡片。第二步,地图已经添加到网站,和第一次一样。
添加 MapDemoWidget
调用后 mapWidget.triggerResize();
它应该解决这个问题。