Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
MacLuky
Posts: 7
Registered: ‎02-11-2013
My Device: Z10

Re: Is it possible draw overlays on a map?

Set up a map and a image in QML

Container {

                id: mapViewContainer

                layout: DockLayout {}

                background: Color.Green

                horizontalAlignment: HorizontalAlignment.Center

                verticalAlignment: VerticalAlignment.Center   

                

                MapView {

                    id: mapView     

                    objectName: "mapView"       

                    altitude: 1000 //settings.altitude

                    latitude: 52.2

                    longitude: 4.4

                    enabled: false

                    altitudeMode: AltitudeMode.ClampToGround

                    horizontalAlignment: HorizontalAlignment.Fill

                }

                ImageView {

                    id: anchorCircleImage

                    image: controller.circleImage

                    preferredHeight: 768/2

                    preferredWidth: 768/2

                    verticalAlignment: VerticalAlignment.Center

                    horizontalAlignment: HorizontalAlignment.Center

                }

 

Then fetch the image in C++ and adapt if needed

 

void AnchorWatch::updateImage()

{

QSize size(720, 1200);

QImage finalImage = Draw::drawCircle(size);

m_circleImage = Draw::fromQImage(finalImage);

 

emit circleImageChanged();

}

 

Hope it helps

 

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Is it possible draw overlays on a map?

Welcome back :-)

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Developer
gbreth
Posts: 8
Registered: ‎10-12-2013
My Device: Z10

Re: Is it possible draw overlays on a map?

Thx! This brings me to an good idea how to do it but may I ask you where the following methods come from?

 

QImage finalImage = Draw::drawCircle(size);

m_circleImage = Draw::fromQImage(finalImage);

 


I guess that's where the "magic" is happening :-)

Please use plain text.
New Developer
gbreth
Posts: 8
Registered: ‎10-12-2013
My Device: Z10

Re: Is it possible draw overlays on a map?

I guess from which example this code comes from ;-)

But I am still a bit struggeling :-D

Please use plain text.
BlackBerry Development Advisor
shaque
Posts: 235
Registered: ‎07-14-2008
My Device: Not Specified

Re: Is it possible draw overlays on a map?

Don't mean to distract from the conversation but drawing your own circles or images on top of the map will have a slight delay that some might find annoying although this may be your only option.

 

Alternatively, you could use

bb::smileytongue:latform::geo::Geographic
bb::smileytongue:latform::geo::GeoShape
bb::smileytongue:latform::geo::GeoPolygon
bb::smileytongue:latform::geo::GeoPolyline

 

They wont give you a perfect circle but you could get close to one with a polygon if that helps. This is available since 10.2.


To draw a circle by using a polygon:

    GeoPolygon* result = new GeoPolygon;

    double lat, lon, radius; // set somewhere else

    Polyline line;
    // convert radius meters to latitude width
    double r = radius / 111412.84; // this is the number of meters per degree
    const int numOfSeg = 18;
    for ( int i = 0; i < numOfSeg; i++ ) {
        double theta = 2.0f * 3.1415926f * float( i ) / float( numOfSeg );
        double x = r * cosf( theta );
        double y = r * sinf( theta );
        line.append( Coordinate( y + lat, x + lon ) );
    }

    result->setOuterBoundary( line );

 

Please use plain text.
New Developer
gbreth
Posts: 8
Registered: ‎10-12-2013
My Device: Z10

Re: Is it possible draw overlays on a map?

Thank you! This looks much better than what I had before.

I tried to play a bit with your code to optimize the "look & feel" but

my "circle" is always looking like an "egg".

 

Maybe you have an idea what I could do to let it look better.

My goal was/is to create a radar around the device position and

in this radar you can see the points of interest. The radius is always

updated when the slider in my app is set to a new search radius.

So replaced your radius with mine to make it moke flexible.

Please use plain text.
New Contributor
MacLuky
Posts: 7
Registered: ‎02-11-2013
My Device: Z10

Re: Is it possible draw overlays on a map?

Yes, you should use the Geo stuff, my code dates from 10.0 and falls back to the native Qt classes.

Please use plain text.