简体   繁体   English

GWT 谷歌地图 V3 覆盖小部件

[英]GWT Google Maps V3 overlay widgets

I'm using the GWT google maps V3 API and I need to display custom shapes over the map. For simple elements I used Polygon, Circle and InfoWidnow classes, but I want to display some other widgets like button or custom panels.我正在使用 GWT 谷歌地图 V3 API,我需要在 map 上显示自定义形状。对于简单的元素,我使用了 Polygon、Circle 和 InfoWidnow 类,但我想显示一些其他小部件,如按钮或自定义面板。 Is there any way to do that using OverlayView class?有没有办法使用 OverlayView class 来做到这一点? I tried a simple solution: an AbsolutePanel that contains the MapWidget and my custom widgets, placed on top, but I would like to use the gwt google maps classes as much as I can.我尝试了一个简单的解决方案:一个包含 MapWidget 和我的自定义小部件的 AbsolutePanel,位于顶部,但我想尽可能多地使用 gwt 谷歌地图类。 I've read the documentation and also searched for an answer but I could't figure it out so a code example would be great.我已经阅读了文档并搜索了答案,但我无法弄清楚所以代码示例会很棒。 Thanx!谢谢!

Just make use of standard GWT API alongside with your maps V3 API. They will interconnect well enough.只需将标准 GWT API 与您的地图 V3 API 一起使用。它们将相互连接得很好。

I found what i needed here (the javascript v3 api): https://developers.google.com/maps/documentation/javascript/overlays#CustomOverlays我在这里找到了我需要的东西(javascript v3 api): https://developers.google.com/maps/documentation/javascript/overlays#CustomOverlays

the method names and classes are very similar so it isn't so difficult to figure out how the GWT classes should be used (like OverlayView).方法名称和类非常相似,因此不难弄清楚应该如何使用 GWT 类(如 OverlayView)。

Here is an example with custom widgets (containing SVG elements and animation) rendered on the map:这是一个在 map 上呈现的自定义小部件(包含 SVG 元素和动画)的示例:

private class TargettingOverlay extends OverlayView {

    protected Element div ;
    protected PanelWrapper panelWrapper;
    private TargettingEffect targetEffect;

    TargettingOverlay(){
        targetEffect = new TargettingEffect();
        targetEffect.setLinedDimension(10500);
        targetEffect.setLinesOffset(-5000);
    }

    void positionTarget(LatLng loc, boolean withoutLines){
        if (targetEffect == null )
            return;

        if (loc == null) {
            targetEffect.setElementsVisible(false);
            return;
        }
        targetEffect.setElementsVisible(true);


        Point p = null;
        Point sw = null;
        Point ne = null;
        LatLng locSW = (LatLng)this.getMap().getBounds().getSouthWest();
        LatLng locNE = (LatLng)this.getMap().getBounds().getNorthEast();

        //
        p = (Point)getProjection().fromLatLngToDivPixel(loc);
        sw = (Point)getProjection().fromLatLngToDivPixel(locSW);
        ne = (Point)getProjection().fromLatLngToDivPixel(locNE);



        targetEffect.setWithoutLinles(withoutLines);
        targetEffect.target((int)ne.getY(), (int)p.getY(), (int)sw.getX(), (int)p.getX());
    }

    @Override
    public void draw() {
        Point ne = (Point)getProjection().fromLatLngToDivPixel((LatLng)
                this.getMap().getBounds().getNorthEast());
        Point sw = (Point)getProjection().fromLatLngToDivPixel((LatLng)
                this.getMap().getBounds().getSouthWest());


        div.getStyle().setTop(ne.getY(), Unit.PX);
        div.getStyle().setLeft(sw.getX(), Unit.PX); 
    }

    @Override
    public void onAdd() {
        div = DOM.createDiv();

        getPanes().getOverlayLayer().appendChild(div);

        panelWrapper = new PanelWrapper(div);
        panelWrapper.attach();          

        targetEffect.setContainer(panelWrapper);
    }

    @Override
    public void onRemove() {
        div.removeFromParent();
        panelWrapper.removeFromParent();

        div = null;
        panelWrapper = null;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM