Closed c0dd3vi11 closed 4 years ago
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)
}
}
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...
And it seems that it also moves to the top-left corner
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.
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.
Can you also explain when you're trying to restore the state of MapView? Is it on device rotation (and activity re-create?)
Ah, yes, the are small. Less than 1. It seems that they are between 0 an 1
I'm trying to restore ReferentialData just after configure
.
I'm just trying to save it and restore to open map on a previous location.
Do you know that the MapView has an automatic feature of state restore (angle, scale and scroll) on device rotation?
I'm trying to share the ReferentialData between three MapView's to save the cache. To able fast switching between maps without reloading.
If you look at the doc of ReferentialData
:
You can see that those values you have are in percent of the full width/height of your map.
Oh... ^_^ That's my fault...
I can't understand how to calculate real center with that percentage. Could you help me please?
That works incorrect...
You shouldn't use width and height, which might be 0 at the time you call your function. Instead, use the fullWidth and fullHeight you set at the configuration of the MapView.
Le lun. 1 juin 2020 à 17:13, c0dd3vi11 notifications@github.com a écrit :
[image: Screenshot 2020-06-01 at 18 12 54] https://user-images.githubusercontent.com/60510579/83423365-87643480-a433-11ea-9458-ff8d6ed6d117.png That works incorrect...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/peterLaurence/MapView/issues/18#issuecomment-636915279, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXKCCXPAKI74BA5OKIKNYTRUPARXANCNFSM4NPYMH2Q .
Oh... this is so unobvious. I tried fullWidth/fullHeight and got the opposite situation, when viewport sticks to the right-bottom.
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())
}
}
@peterLaurence, could you help me again, please?
I got that I can use
MapViewConfiguration.setStartScale
to initiate the scale. But how to initiate angle and center for map properly?p.s. I'm storing angle, scale & center between launching and also want a feature to open map positioned properly on the certain map's zone.