【问题标题】:CodenameOne MapContainer Zoom LevelCodenameOne MapContainer 缩放级别
【发布时间】:2016-07-23 12:53:51
【问题描述】:

我正在使用 MapContainer(cn1lib)。所以在 android 设备低分辨率中缩放工作正常。但在 android 设备高分辨率中,缩放不能正常工作。放大的距离很远。我附加了一个最大放大的屏幕,这是一个错误还是我错了?

SCREENSHOT

GUI-DESIGN

公共类 StateMachine 扩展 StateMachineBase {

MapContainer mapContainer;

public StateMachine(String resFile) {
    super(resFile);
    // do not modify, write code in initVars and initialize class members there,
    // the constructor might be invoked too late due to race conditions that might occur
}

/**
 * this method should be used to initialize variables instead of the
 * constructor/class scope to avoid race conditions
 */
protected void initVars(Resources res) {
}

@Override
protected void beforeShow(Form f) {
    try {

        this.mapContainer.setShowMyLocation(true);
        this.mapContainer.zoom(new Coord(20.640086, -103.432207), 17);
        this.mapContainer.setCameraPosition(new Coord(20.640086, -103.432207));
        this.mapContainer.addMarker(
                EncodedImage.createFromImage(fetchResourceFile().getImage("pin.png"), false),
                new Coord(20.640086, -103.432207),
                "Hi marker", "Optional long description",
                new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        Dialog.show("Marker Clicked!", "You clicked the marker", "OK", null);
                    }
                }
        );


        this.mapContainer.addPointerDraggedListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                mapContainer.clearMapLayers();
                mapContainer.addMarker(EncodedImage.createFromImage(fetchResourceFile().getImage("pin.png"), false), mapContainer.getCameraPosition(), "Hi marker", "Optional long description", new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        Dialog.show("Marker Clicked!", "You clicked the marker", "OK", null);
                    }
                });

            }
        });

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    super.beforeShow(f); //To change body of generated methods, choose Tools | Templates.
}

@Override
protected Component createComponentInstance(String componentType, Class cls) {
    if (cls == MapComponent.class) {    
        this.mapContainer = new MapContainer();
        return this.mapContainer;
    }
    return super.createComponentInstance(componentType, cls); //To change body of generated methods, choose Tools | Templates.
}

}

【问题讨论】:

  • 请发布一些代码,以便我们更好地帮助您。
  • 我已经更新了帖子,谢谢

标签: codenameone


【解决方案1】:

那是MapComponent 不是原生地图,所以它使用旧的开放街道地图支持和相对简单的地图渲染,即使在设备上也是如此。我们支持native google maps,它未在 GUI 构建器中公开,但您可以通过代码添加它。

这会将实际的本机 GUI 嵌入到位,尽管在模拟器上看起来和感觉相同,但它在设备上的外观和感觉都会更好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 2019-06-04
    • 2015-09-18
    • 2012-08-15
    相关资源
    最近更新 更多