Hello there,
I am kind of new to ThinkGeo and just got to work recently on a project using ThinkGeo v5.
I followed the different guides and wiki and manages to upgrade to the latest nuGet packages 13.2.1 (and 13.2.2 for ThinkGeo.UI.Winforms).
What I wanted to do in my application was to change the map provider and instead of using shape file I’d use a WMS service. So basically I got rid of the shape file loading and looked at the sample provided here.
Here are some code samples from my project:
MapComponent.cs
public MapComponent()
{
InitializeComponent();
localizeComponent();
mapView.CurrentExtentChanged +=
new EventHandler(MapView_CurrentExtentChanged);
JMSManager.getInstance().OnUnitStatusUpdate += new JMSManager.UnitEventHandler(MapComponent_OnUnitStatusUpdate);
initMap();
zoomToFullExtent();
mapView.TrackOverlay.TrackEnded += new EventHandler<TrackEndedTrackInteractiveOverlayEventArgs>(trackOverlay_TrackEnded);
mapView.TrackOverlay.TrackEnding += new EventHandler<TrackEndingTrackInteractiveOverlayEventArgs>(trackOverlay_TrackEnding);
mapView.TrackOverlay.TrackStarting += new EventHandler<TrackStartingTrackInteractiveOverlayEventArgs>(trackOverlay_TrackStarting);
//createSignalAreaShapefile();
initAppVersion();
}
**[...]**
public async void initMap()
{
mapView.MapUnit = GeographyUnit.DecimalDegree;
// Clear out the overlays so we start fresh
mapView.Overlays.Clear();
// Create an overlay that we will add the layer to.
LayerOverlay staticOverlay = new LayerOverlay();
mapView.Overlays.Add(staticOverlay);
// Create the WMS layer using the parameters below.
// This is a public service and is very slow most of the time.
ThinkGeo.Core.Async.WmsRasterLayer wmsImageLayer = new ThinkGeo.Core.Async.WmsRasterLayer(new Uri("http://ows.mundialis.de/services/service"));
wmsImageLayer.ActiveLayerNames.Add("OSM-WMS");
wmsImageLayer.ActiveStyleNames.Add("default");
wmsImageLayer.Exceptions = "application/vnd.ogc.se_xml";
// Add the layer to the overlay.
staticOverlay.Layers.Add("wmsImageLayer", wmsImageLayer);
mapView.CurrentExtent = new RectangleShape(-96.8538765269409, 33.1618647290098, -96.7987487018851, 33.1054126590461);
await mapView.RefreshAsync();
startGPS();
}
MapComponen.designer.cs
private System.Windows.Forms.Panel mainPanel;
private System.Windows.Forms.Panel mapPanel;
private ThinkGeo.UI.WinForms.MapView mapView;
**[...]**
private void InitializeComponent()
{
this.mapView = new ThinkGeo.UI.WinForms.MapView();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MapComponent));
this.mainPanel = new System.Windows.Forms.Panel();
this.mapPanel = new System.Windows.Forms.Panel();
this.infoTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.speedLabelControl = new DevExpress.XtraEditors.LabelControl();
this.countLabelControl = new DevExpress.XtraEditors.LabelControl();
this.stopSimpleButton = new DevExpress.XtraEditors.SimpleButton();
this.zoomLevelLabelControl = new DevExpress.XtraEditors.LabelControl();
this.longitudeLabelControl = new DevExpress.XtraEditors.LabelControl();
this.latitudeLabelControl = new DevExpress.XtraEditors.LabelControl();
this.scaleLabelControl = new DevExpress.XtraEditors.LabelControl();
this.scaleValueLabelControl = new DevExpress.XtraEditors.LabelControl();
this.eastingValueLabelControl = new DevExpress.XtraEditors.LabelControl();
this.northingValueLabelControl = new DevExpress.XtraEditors.LabelControl();
this.routeTrackBarControl = new DevExpress.XtraEditors.TrackBarControl();
this.playSimpleButton = new DevExpress.XtraEditors.SimpleButton();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
this.labelControl2 = new DevExpress.XtraEditors.LabelControl();
this.mainPanel.SuspendLayout();
this.mapPanel.SuspendLayout();
this.infoTableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.routeTrackBarControl)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.routeTrackBarControl.Properties)).BeginInit();
this.tableLayoutPanel2.SuspendLayout();
this.SuspendLayout();
//
// mainPanel
//
this.mainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.mainPanel.Location = new System.Drawing.Point(0, 0);
this.mainPanel.Name = "mainPanel";
this.mainPanel.Size = new System.Drawing.Size(800, 600);
this.mainPanel.TabIndex = 0;
//
// mapPanel
//
this.mapPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.mapPanel.Location = new System.Drawing.Point(0, 0);
this.mapPanel.Name = "mapPanel";
this.mapPanel.Size = new System.Drawing.Size(800, 600);
this.mapPanel.TabIndex = 0;
//
// MapView
//
this.mapView.BackColor = System.Drawing.Color.White;
this.mapView.CurrentScale = 0D;
this.mapView.Dock = System.Windows.Forms.DockStyle.Fill;
this.mapView.Location = new System.Drawing.Point(0, 0);
this.mapView.MapFocusMode = ThinkGeo.Core.MapFocusMode.Default;
this.mapView.MapResizeMode = ThinkGeo.Core.MapResizeMode.PreserveExtent;
this.mapView.MaximumScale = 80000000000000;
this.mapView.MinimumScale = 200;
this.mapView.RestrictExtent = null;
this.mapView.Name = "mapView";
this.mapView.Size = new System.Drawing.Size(800, 572);
this.mapView.TabIndex = 0;
this.mapView.Text = "mapView";
//this.mapView.SizeChanged += new System.EventHandler(this.MapView_SizeChanged);
//this.mapView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MapView_MouseMove);
//this.mapView.MapClick += new System.EventHandler<ThinkGeo.Core.MapClickMapViewEventArgs>(this.MapView_MapClick);
**[...]**
//
// MapComponent
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.mapPanel.Controls.Add(this.mapView);
this.mapPanel.Controls.Add(this.infoTableLayoutPanel);
this.Controls.Add(this.mainPanel);
this.Name = "MapComponent";
this.Size = new System.Drawing.Size(800, 600);
this.mainPanel.ResumeLayout(false);
this.mapPanel.ResumeLayout(false);
this.infoTableLayoutPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.routeTrackBarControl.Properties)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.routeTrackBarControl)).EndInit();
this.tableLayoutPanel2.ResumeLayout(false);
this.ResumeLayout(false);
}
I tried taking only the relevant parts of the code, please do tell me if something is missing.
My issue is that the project crashes when initMap() is called especially when adding the overlay here:
mapView.Overlays.Add(staticOverlay);
Here’s the error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=ThinkGeo.UI.WinForms
StackTrace:
at ThinkGeo.Core.MapViewBase.3kc=(Object sender, AddedGeoCollectionEventArgs e)
I have looked at many topics on this forum about the same subject but most of them were about WPF. I tried multiple solutions with no success. I tried adding a currentExtent before adding the overlay but it was always out of bounds no matter what. I tried checking my mapView and overlay before adding it but none of them are null.
Would you happen to have any guidance on how to debug this ? I am available if any other information is needed. I have been looking for solutions for two days now so this is my last resort.
Regards.