Comments (8)
if you don't use mess with the minimum scale, and leave scaleToFitTrue (which is default), the MapView will never show space, and will always fit it's layout dimensions - you can have it fill parent or fixed size, and it'll figure out the minimum scale to so that it's never smaller on the smallest axis. I feel like I'm not explaining that well - does that make sense?
from mapview.
In my usecase I always want to provide all possible zoom levels - regardless of the device size/view size - because every zoom level contains different kind information that should always be available.
So if the Map is very small in zoom level 0 and there will be a lot of space left I still want to be able to present that zoom level. Then it would be great when this small map is centered in the available space.
Maybe that is a new option or something.
BTW: When I set scaleToFit to false I am still not able to see the smallest map but instead the one that fits best.
I thought, that when scaleToFit is false, the MapView shows every zoom level as-is there is still scaling. How can I disable that?
from mapview.
scaleToFit effectively just sets the minimum allowed scale value to whatever it would be based on the size of the tileset and the dimensions of the device. if you've set the minimum scale elsewhere, that could also prevent some levels from showing. try setting minimum scale to 0 (or something ridiculously small).
i'll point out that i always intended the mapview to never be smaller than it's container, and both the minimum/maximum scale methods and setScaleToFit are undocumented deliberately - they're not well tested and could introduce other bugs. i think it's probably safe, but as I said I didn't spend much time on situations where it could be smaller than the screen. I'll look into this next update, mid-month.
I think the only way to center it would have to be external - within the widget itself, everything (positioning, geolocation, intersection detection, tile placement), is based on a 0,0 coordinate system. I'd probably do it like this:
- Put the MapView inside a FrameLayout, and set the FrameLayout's position to whatever you want.
- Add a MapEventListener and override onScaleChanged.
- During scale change events, check getScaledWidth and getScaledHeight, and compare that to the width and height of the containing FrameLayout. If it's smaller, than set the MapViews layout width and layout height to the scaled values, and do the math to position it manually, something like
int containingWidth = frameLayout.getWidth();
int containingHeight = frameLayout.getHeight();
int mapWidth = mapView.getScaledWidth();
int mapHeight = mapView.getScaledHeight();
// if mapWidth/Height are bigger than containingWidth/Height
// set layout params to match_parent and margins to 0
// otherwise...
LayoutParams lp = mapView.getLayoutParams();
lp.width = mapWidth;
lp.height = mapHeight;
lp.leftMargin = (int) ((containingWidth - mapWidth) * 0.5);
lp.topMargin = (int) ((containingHeight - mapHeight) * 0.5);
mapView.setLayoutParams(lp);
That's just off the top of my head - there could be errors in logic or syntax, but that's probably where I'd start.
HTH, LMK how it goes.
from mapview.
@mohlendo how did this work out? can I close this issue?
from mapview.
Ok, the Map is centered, but now I cannot scroll anymore...
from mapview.
Hm... No idea why that would happen. I'll try to recreate the concept tomorrow and see if I notice anything.
from mapview.
@mohlendo - I just did a quick POC of the basic concept and it works as expected. It centers to the container, and continues to scroll if there's still unshown area (e.g., if its shorter than the view it centers along the y axis, but if there's still content along the x axis, it'll still scroll). Obviously, if the whole thing is smaller than the container, there's nothing to scroll.
This is pretty much exactly as I'd expect. Here's a gist using a RelativeLayout. I can post the apk if you think it'd be helpful.
If that's now what you're looking for, maybe you can post more detailed "rules" about how you want it to behave and I'll do my best to point out the relevant code.
from mapview.
@moagrius using your gist with the RelativeLayout does the trick! Thanks!
from mapview.
Related Issues (20)
- Project Rename HOT 7
- Does MapView only draw PathViews that are visible? HOT 8
- Polygons as hotspots HOT 6
- Extra zoom feature HOT 8
- Increase the scrollable area in order to scroll the edges of the map into view HOT 4
- How to use HotSpot and HotSpotManager? HOT 3
- Render tiles outside of view HOT 2
- Loading downsample via TileDecoder HOT 2
- Markers moving when zooming HOT 2
- Callout drawn off screen HOT 3
- Image moving between zoom levels HOT 6
- Feature Requests HOT 15
- moveTo/slideTo rectangle HOT 4
- slideToAndCenter randomly not works HOT 3
- Adding ZoomLevels dynamically does not allow zooming. HOT 1
- How to listen onLongPress event? HOT 5
- map doesn't redraw after scrolling if scale is greater than 1 HOT 1
- Chaging zoomlevels dynamicaly doesn't show correct tiles HOT 1
- Gradle HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapview.