Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroundOverlay not working fine #273

Closed
edudavid83 opened this issue Dec 12, 2016 · 8 comments
Closed

GroundOverlay not working fine #273

edudavid83 opened this issue Dec 12, 2016 · 8 comments

Comments

@edudavid83
Copy link

Hi. I'm trying to load an image like GroundOverlay, but I can not get it to be located correctly. I tried to load both the 4326 and 3857 projections. Then create my own class that extends from GroundOverlay and reimplented the draw () method as follows:

Public class MyGroundOverlay extends GroundOverlay {

    Private Point southOestPoint;
    Private Point northEastPoint;
    Private GeoPoint southOest;
    Private GeoPoint northEast;
    

    Public MyGroundOverlay () {
        super();

        SouthOestPoint = new Point ();
        NorthEastPoint = new Point ();
    }

    Public void setSouthOest (GeoPoint southOest) {
        This.southOest = southOest;
    }

    Public void setNorthEast (GeoPoint northEast) {
        This.northEast = northEast;
    }

    @OverRide
    Protected void draw (Canvas canvas, MapView mapView, boolean shadow) {
        If (shadow)
            Return;
        If (mImage == null)
            Return;

        If (mHeight == NO_DIMENSION) {
            MHeight = mWidth * mImage.getIntrinsicHeight () / mImage.getIntrinsicWidth ();
        }

     / * GeoPoint NE = new GeoPoint (-29.9999999973059, -46.1880215332298);
        GeoPoint SO = new GeoPoint (-39.9999999994056, -65.2703644680108); * /

        Final Projection pj = mapView.getProjection ();
        Pj.toPixels (northEast, northEastPoint);
        Pj.toPixels (southOest, southOestPoint);

        Point Average = new Point ();
        Average.set ((southOestPoint.x + northEastPoint.x) / 2, (southOestPoint.y + northEastPoint.y) / 2);

        /*pj.toPixels(mPosition, mPositionPixels);
        GeoPoint pEast = mPosition.destinationPoint (mWidth / 2, 90f);
        GeoPoint pSouthEast = new GeoPoint (-39.9999999994056, -46.1880215332298); // pEast.destinationPoint (mHeight / 2, -180.0f);
        Pj.toPixels (pSouthEast, mSouthEastPixels);
        * /
        Int width = northEastPoint.x - Average.x;
        Int height = southOestPoint.y - Average.y;
        MImage.setBounds (-width, -height, width, height);

        MImage.setAlpha (255 - (int) (mTransparency * 255));

        DrawAt (canvas, mImage, Average.x, Average.y, false, -mBearing);
    }

But still does not look good. Both images are loaded correctly in other programs like QGis.
I attach the images I am using.

These are the data used:

Center: -55.729193 Lng, -35 Lat
Width: 2124236.699 mtrs
High: 1362392.436 mtrs

NW Point: -29.9999999973059 Lat, -65.2703644680108 Lng
NE Point: -29.9999999973059 Lat, -46.1880215332298 Lng
SW Point: -39.9999999994056 Lat, -65.2703644680108 Lng
SE Point: -39.9999999994056 Lat, -46.1880215332298 Lng

Thank you!

Best regards
mapserv3857
mapserv4326

@MKergall
Copy link
Owner

Please provide your code sample calling the standard GroundOverlay, so that we can try to see if there is an issue.
Note that GroundOverlay can be seen in action with the OSMBonusPack tutorial project.
Note that osmdroid only supports WGS84 projection (as far as I know).

@edudavid83
Copy link
Author

edudavid83 commented Dec 12, 2016 via email

@MKergall
Copy link
Owner

And what is the issue?

@edudavid83
Copy link
Author

Hi. I was testing the following code to load a GroundOverlay, and the result is the one shown in the attached image. What could be the problem?

**Location SO = new Location(LocationManager.GPS_PROVIDER);
SO.setLatitude(-39.9958333333333);
SO.setLongitude(-65.2703647891198);

    Location NO = new Location(LocationManager.GPS_PROVIDER);
    NO.setLatitude(-30.0041666666667);
    NO.setLongitude(-65.2703647891198);

    Location NE = new Location(LocationManager.GPS_PROVIDER);
    NE.setLatitude(-30.0041666666667);
    NE.setLongitude(-46.2015247519894);

    float hight = SO.distanceTo(NO);
    float width = NE.distanceTo(NO);

    GroundOverlay groundOverlay = new GroundOverlay(ctx);
    groundOverlay.setImage(ResourcesCompat.getDrawable(ctx.getResources(), R.drawable.mapserv4326, null));
    groundOverlay.setPosition(new GeoPoint(-35, -55.729193));

    groundOverlay.setDimensions(width, hight);

    mapView.getOverlays().add(1, groundOverlay);**

Thank you.
screenshot_20170207-132939

This is the image:
mapserv4326

@MKergall
Copy link
Owner

MKergall commented Feb 8, 2017

Interesting one. I found 1 issue on your side, and one issue on mine.

Your bug: your position longitude -55.729193 is not correct. The correct center between your east and west is: -55,7359447705546

My bug was inside GroundOverlay, about width/height computation, which was really weird. I just commited the fix.

Now, once both issues fixed, it's better, but still not good. I still don't understand why.

Putting some corrective coefficients on width and height can help:

groundOverlay.setDimensions(width*0.94f, height*1.06f);

@BorficchiaDavide
Copy link

I have the same problem my image is moved to the right. i tried with your corrective coefficients but it doesn't work. the center of the map is the same that the point i use in .setPosition.
How can i fix it?

@MKergall
Copy link
Owner

@be4r0 please provide relevant data/screen copy/code.

@edudavid83
Copy link
Author

edudavid83 commented May 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants