【问题标题】:Marker and Overlay not displayed at the same place标记和覆盖不在同一位置显示
【发布时间】:2013-07-25 08:43:37
【问题描述】:

我为 GWT (https://github.com/branflake2267/GWT-Maps-V3-Api) 使用了 branflake2267 谷歌地图 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()),但均未成功...

【问题讨论】:

    标签: gwt google-maps-api-3


    【解决方案1】:

    好的,只需使用 setLeft 和 setRight 代替 setLeft 和 setTop...

    【讨论】:

      猜你喜欢
      • 2019-03-04
      • 1970-01-01
      • 2012-02-10
      • 2015-02-11
      • 2019-04-17
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 2018-04-06
      相关资源
      最近更新 更多