This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

got exception when creating a map based on OSM

-1

I would like to run a C# code to create a map based on OSM. The code is from http://www.codeproject.com/Articles/87944/WPF-Map-Control-using-openstreetmap-org-Data

I can build and run the code at Visual Studio 2013. I need to make the map focus on a given lat/lon. So I added

 myMap.Focus(); // enable manual zoom-in/out 
 myMap.Center(37.806029, -122.407007, 16);

in MainWindow.xaml.cx. I also added

  <map:MapCanvas Latitude="37.806029" Longitude ="-122.407007" Zoom="16" x:Name="myMap"
           />

in MainWindow.xaml But, when I ran the code, I got exception:

  An exception of type 'System.ArgumentOutOfRangeException' occurred in PresentationCore.dll but was not handled in user code

  Additional information: The parameter value must be greater than zero.

The exception occured at:

 public ImageSource CreateImage()
    {
        RenderTargetBitmap bitmap = new RenderTargetBitmap((int)this.**ActualWidth**, (int)this.**ActualHeight**, 96, 96, PixelFormats.Default);
        bitmap.Render(_tilePanel);
        bitmap.Freeze();
        return bitmap;
    }

The "ActualWidth" and "ActualHeight" are all 0s.

How can I set values for them ?

Any help would be appreciated.

asked 04 Oct '15, 23:29

usact's gravatar image

usact
19335
accept rate: 0%

edited 04 Oct '15, 23:36

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554

1

debugging of your code and/or some other libraries/examples is not really the scope of this help site for OpenStreetMap, in my opinion

(04 Oct '15, 23:35) aseerel4c26 ♦

Source code available on GitHub .