Comments (4)
Thanks a lot for the sample project! This makes things so much easier, and I learn from seeing your code. I like the image layer you use.
In Mapsui changing the viewport depends on the size of the canvas and the extent of the data and this is not known during startup. This is why the Map.Home method was added. This method is called ones those are known. I could fix your problem by writing it like this:
var layer = await CreateLayerAsync(default);
mapControl.Map?.Layers.Add(layer);
double x = -9188151.36056;
double y = 3235144.74039;
var point = new MPoint(x, y);
mapControl.Map.Home = (n) => n.CenterOnAndZoomTo(point, resolution: 1000, 500, Mapsui.Animations.Easing.CubicOut);
MyMapControl = mapControl;
Content = mapControl;
It now starts like this:
Notes:
- I tested on Windows, not on Mac or iOS, but I assume the fix also works there.
- Perhaps we should add this to the FAQ.
- I expect the Mapsui logger to log a warning when CenterOnAndZoom is called too early. I did not see that warning.
- You do not always need to the canvas size, and in this particular case (where resolution and center are set). I think you don't need it. Perhaps we can improve this.
from mapsui.
I looked into the last two bullets.
We do not log a warning when the navigator is called while width and height is zero. I think we should add this. It looks like the Navigator.SetViewport method is a good place for this.
Calling CenterOnAndZoom before width and height are set actually works, the viewport is correctly initialized. However, after that, the default Home method does a ZoomToPanBounds() and overrides the earlier CenterOnAndZoom. The initial CenterOnAndZoom actually works if mapControl.Map.Home = (n) => { };
is called before (did this just to test the logic). Anyway, this was just to understand what is happening. Lets leave this like it is. When we add the logger users will understand what is going on.
from mapsui.
Thank you so much for the quick response on this. This makes perfect sense. I updated the code per your example and is working as expected. Just a thought but perhaps the usage of the 'InvalidOperationException' in scenarios like this might be appropriate as well.
from mapsui.
Thanks for the suggestion, that might be the best option. I will close this as answered.
from mapsui.
Related Issues (20)
- Zoom and pan shows empty blank space around world map? HOT 2
- Long press is not triggered on Android HOT 2
- [Avalonia]: Hovered-event is not available yet HOT 5
- Mapsui.Wpf is incompatible with System.Drawing.Common 8.0.0 HOT 2
- Investigate support for native AOT HOT 1
- Add Map extensions to allow users to easily add functionality composed of several core components HOT 8
- Make all sample code copy-paste-able
- Fail in GeoTiffSample unit test HOT 3
- Polygon Drag Not Refreshing Until Map Is Panned HOT 2
- Convert all our scripts to PowerShell
- Add LayerListWidget HOT 5
- Custom IViewportLimiter's Limit function is not called HOT 1
- MAUI Flyout Locks Map (regression) HOT 9
- Make the MapControl disposable and not the Map
- GeometryFeature disappears while panning HOT 9
- BitmapRegistry.Unregister() doesn't remove bitmap from lookup array HOT 3
- Callout not always on top HOT 6
- Drawing order different to map info order HOT 4
- More shared touch/mouse handling over all platforms HOT 7
- When touching and holding a long press, mapControl becomes blank HOT 6
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 mapsui.