Coder Social home page Coder Social logo

Setting initial angle and center about mapview HOT 19 CLOSED

p-lr avatar p-lr commented on July 4, 2024
Setting initial angle and center

from mapview.

Comments (19)

p-lr avatar p-lr commented on July 4, 2024

After the MapView has been laid out, you can do like so:

with(mapView) {
    angle = 15f
    val centerX = scrollX + halfWidth
    val centerY = scrollY + halfHeight
    post {
        scrollToAndCenter(centerX, centerY)
    }
}

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I'm trying to apply ReferentialData:

with(mapView) {
    post {
        scale = data.scale
        setAngle(data.angle)
        scrollToAndCenter(data.centerX.toInt(), data.centerY.toInt())
    }
}

It rotates, scales, but not scrolls...

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

And it seems that it also moves to the top-left corner

from mapview.

p-lr avatar p-lr commented on July 4, 2024

I would check the values you have for data.centerX and data.centerY.
Typically, if those values are too small, it scrolls to the top left corner.

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I found out that in:

override fun scrollTo(x: Int, y: Int) {
    val (constrainedX, constrainedY) = gestureController.setConstrainedScroll(x, y)
    super.scrollTo(constrainedX, constrainedY)
}

I got zeros in constrainedX, constrainedY.

from mapview.

p-lr avatar p-lr commented on July 4, 2024

Can you also explain when you're trying to restore the state of MapView? Is it on device rotation (and activity re-create?)

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

Ah, yes, the are small. Less than 1. It seems that they are between 0 an 1

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I'm trying to restore ReferentialData just after configure.

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I'm just trying to save it and restore to open map on a previous location.

from mapview.

p-lr avatar p-lr commented on July 4, 2024

Do you know that the MapView has an automatic feature of state restore (angle, scale and scroll) on device rotation?

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I'm trying to share the ReferentialData between three MapView's to save the cache. To able fast switching between maps without reloading.

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

Screenshot 2020-06-01 at 17 09 35

from mapview.

p-lr avatar p-lr commented on July 4, 2024

If you look at the doc of ReferentialData:

ref-data

You can see that those values you have are in percent of the full width/height of your map.

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

Oh... ^_^ That's my fault...

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I can't understand how to calculate real center with that percentage. Could you help me please?

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

Screenshot 2020-06-01 at 18 12 54

That works incorrect...

from mapview.

p-lr avatar p-lr commented on July 4, 2024

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

Oh... this is so unobvious. I tried fullWidth/fullHeight and got the opposite situation, when viewport sticks to the right-bottom.

from mapview.

c0dd3vi11 avatar c0dd3vi11 commented on July 4, 2024

I did the combo! ^_^

fun MapView.applyReferentialData(config: MapViewConfiguration, data: ReferentialData) {
    post {
        scale = data.scale
        setAngle(data.angle)
        val centerX = config.fullWidth * data.scale * data.centerX
        val centerY = config.fullHeight * data.scale * data.centerY
        scrollToAndCenter(centerX.toInt(), centerY.toInt())
    }
}

from mapview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.