codenameone / codenameone-google-maps

Allows native google maps to run within Codename One applications
https://www.codenameone.com/
13 stars 24 forks source link

getScreenCoordinate returns wrong points #33

Open kutoman opened 5 years ago

kutoman commented 5 years ago

When a marker is placed at the left border of a map which is the left border of the screen at the same time I would expect that getScreenCoordinate(myMarker) returns a point with x == 0 (or near 0) but I for example get 160 at the state demonstrated at the snapshot below (the marker image is just 50 pixel wide). The issue is similar for the y axis. This wasn't the case a while ago.

bildschirmfoto 2018-12-12 um 12 14 07

sample code:

    final String API_KEY = "key";

    final MapContainer mapContainer = new MapContainer(API_KEY);

    Form f = new Form("Maps", new LayeredLayout());
    f.setScrollable(false);
    f.add(mapContainer);

    Coord originalC = new Coord(50.96280565137735, 7.047107219696045);

    EncodedImage ei = EncodedImage.createFromImage(
            FontImage.createMaterial(FontImage.MATERIAL_GPS_FIXED, f.getUnselectedStyle())
            , false);

    MapContainer.MarkerOptions mo = new MapContainer.MarkerOptions(originalC, ei)
    .anchor(0.5f, 0.5f)
    .onClick((evt) -> {
        log.p("clicked on marker" + originalC);
    });

    MapContainer.MapObject obj = mapContainer.addMarker(mo);

    f.getToolbar().addCommandToRightBar("", FontImage.createMaterial(FontImage.MATERIAL_ADD_CIRCLE, f.getUnselectedStyle()), (ev) -> {
        System.out.println("PRINTOUT:");
        System.out.println("Point of Marker: " + mapContainer.getScreenCoordinate(originalC));
        System.out.println("Screen: " + CN.getDisplayWidth() + "x" + CN.getDisplayHeight());
        System.out.println("MapC: " + mapContainer.getWidth() + "x" + mapContainer.getHeight());

    });

    f.getToolbar().addCommandToRightBar("", FontImage.createMaterial(FontImage.MATERIAL_ZOOM_IN, f.getUnselectedStyle()), (ev) -> {
        System.out.println("focus");
        mapContainer.zoom(originalC, (int) mapContainer.getZoom());
    });

    mapContainer.zoom(originalC, 10);
    f.revalidate();

    f.show();