我使用 GWT 的 branflake2267 谷歌地图 API ( https://github.com/branflake2267/GWT-Maps-V3-Api )。我想在标记下方显示一个标题。
我的位置:
final LatLng latlng = LatLng.newInstance(47.4125, -0.861944);
图标标记(它是地图上的正确位置)
MarkerImage icon = MarkerImage.newInstance("/images/maps/pin_workshop.png", Size.newInstance(21, 34), Point.newInstance(0, 0), Point.newInstance(10, 34));
MarkerImage shadow = MarkerImage.newInstance("/images/maps/shadow.png", Size.newInstance(40, 37), Point.newInstance(0, 0), Point.newInstance(12, 35));
MarkerOptions options = MarkerOptions.newInstance();
options.setPosition(latlng);
options.setMap(map);
options.setTitle("Factory");
options.setIcon(icon);
options.setShadow(shadow);
Marker marker = Marker.newInstance(options);
带有标题的叠加层(地图中的位置不正确...):
final DivElement div = Document.get().createDivElement();
OverlayView.newInstance(map, new OverlayViewOnDrawHandler() {
@Override
public void onDraw(OverlayViewMethods methods) {
Point position = methods.getProjection().fromLatLngToDivPixel(latlng);
div.getStyle().setPosition(Position.ABSOLUTE);
div.getStyle().setLeft(position.getX(), Unit.PX);
div.getStyle().setRight(position.getY(), Unit.PX);
div.setInnerText("Factory");
}
},
new OverlayViewOnAddHandler() {
@Override
public void onAdd(OverlayViewMethods methods) {
methods.getPanes().getOverlayLayer().appendChild(div);
}
},
new OverlayViewOnRemoveHandler() {
@Override
public void onRemove(OverlayViewMethods methods) {
div.removeFromParent();
}
});
我尝试了不同版本的库(3.09 build 17、3.10.0-alpha-6),以及不同的窗格(getMapPane(),getFloatPane())但没有成功......