Coder Social home page Coder Social logo

Comments (4)

pauldendulk avatar pauldendulk commented on May 29, 2024

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:

image

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.

pauldendulk avatar pauldendulk commented on May 29, 2024

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.

nm4568 avatar nm4568 commented on May 29, 2024

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.

pauldendulk avatar pauldendulk commented on May 29, 2024

Thanks for the suggestion, that might be the best option. I will close this as answered.

from mapsui.

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.