private bool LoadGisData() { try { isLoading = true; SplashScreen.UpdateInfo(resources.GetString("CreatingMap")); winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); winformsMap1.MapUnit = GeographyUnit.DecimalDegree; SplashScreen.UpdateInfo(resources.GetString("AddingLayers")); TiledWmsLayer tiledWmsLayer = AddTileLayer(); LayerOverlay staticOverlay = GetStaticLayer(); staticOverlay.Layers.Add("SimpleWmsLayerPlugin", tiledWmsLayer); winformsMap1.Overlays.Add(staticOverlay); SplashScreen.UpdateInfo(resources.GetString("AddingAdornments")); AddScaleBar(); AddGraticule(); SplashScreen.UpdateInfo(resources.GetString("DrawingMap")); DrawMap(); SplashScreen.UpdateInfo(resources.GetString("SetupIcons")); SetupInitialIconDisplay(); MapIsDrawn = true; SplashScreen.UpdateInfo(resources.GetString("Complete")); return true; } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; MapIsDrawn = false; return false; } finally { isLoading = false; } } private TiledWmsLayer AddTileLayer() { //version 4.5 //TiledWmsLayer tiledWmsLayer = new TiledWmsLayer(new Uri(WmsServer)); //version 6.0 Collection onsiteServers = new Collection(); onsiteServers.Add(new Uri(WmsServer)); TiledWmsLayer tiledWmsLayer = new TiledWmsLayer(onsiteServers); //TODO Finish after info collected CreateProxy(tiledWmsLayer); tiledWmsLayer.ClientId = GetXmlValue("Id"); tiledWmsLayer.PrivateKey = GetXmlValue("Key"); tiledWmsLayer.ActiveLayerNames.Add("WorldMapKitLayer"); tiledWmsLayer.ActiveStyleNames.Add("WorldMapKitDefaultStyle"); return tiledWmsLayer; } private static LayerOverlay GetStaticLayer() { LayerOverlay staticOverlay = new LayerOverlay() { IsBase = true, TileCache = AddTileCache() }; return staticOverlay; } private void DrawMap() { try { //Draw points for extent LayerOverlay dynamicOverlay = AddDynamicOverlay(); InMemoryFeatureLayer shapeLayer = AddShapeLayer(); winformsMap1.Overlays.Add(dynamicOverlay); dynamicOverlay.Layers.Add("DynamicShapeLayer", shapeLayer); //Create the points at lat/lon for BoundingBox DrawPointsLayer(shapeLayer); //configure extent shapeLayer.Open(); winformsMap1.CurrentExtent = shapeLayer.GetBoundingBox(); shapeLayer.Close(); tLog.WriteInfo(resources.GetString("DrawMapExit")); } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private static LayerOverlay AddDynamicOverlay() { //Contracts.ValidateObjectResult(); LayerOverlay dynamicOverlay = new LayerOverlay() { Name = "DynamicOverlay", IsBase = false }; return dynamicOverlay; } private void DrawPointsLayer(InMemoryFeatureLayer layer) { try { //Create the points at lat/lon for BoundingBox DataView dv = dt.DefaultView; IEnumerator iterator = dv.GetEnumerator(); DataRowView drv; Int32 i = 0; string lon = string.Empty; string lat = string.Empty; while (iterator.MoveNext()) { drv = (DataRowView)iterator.Current; string lSiteId = drv.Row["lSiteID"].ToString(); lon = drv.Row["lLongitude"].ToString(); lat = drv.Row["lLatitude"].ToString(); if (MapFunctions.VerifyLatLon(lat, lon)) { #if (DEBUG) tLog.WriteInfo(String.Format("CreateAPointAt: Lat: {0} Lon: {1} lSiteId: {2}", lat, lon, lSiteId)); #endif CreatePoint(layer, lon, lat); } else { tLog.WriteInfo(String.Format("{0}{1} {2}", resources.GetString("FailedToCreateAPointAt"), lat, lon)); } i++; } } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private void CreatePoint(InMemoryFeatureLayer layer, string lon, string lat) { try { //could use the id param to identify Feature pointFeature = new Feature(new PointShape(double.Parse(lon, CultureInfo.InvariantCulture), double.Parse(lat, CultureInfo.InvariantCulture))); layer.InternalFeatures.Add(pointFeature.Id, pointFeature); } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private void SetupInitialIconDisplay() { try { SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay() { IsBase = false, MapControl = winformsMap1 }; winformsMap1.Overlays.Add("IconMarkerOverlay", markerOverlay); DrawMarkers(markerOverlay); tLog.WriteInfo(resources.GetString("SetupInitialIconDisplayExit")); } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private void DrawMarkers(SimpleMarkerOverlay markeroverlay) { string lSiteId = string.Empty; string rrId = string.Empty; Double lLatitude = 0; Double lLongitude = 0; string szSiteDesc = string.Empty; int DisplayState = 2; string DisplayText = string.Empty; try { foreach (DataRow row in dt.Rows) { lSiteId = row["lSiteID"].ToString(); rrId = row["szSiteID"].ToString(); lLatitude = Double.Parse(row["lLatitude"].ToString()); lLongitude = Double.Parse(row["lLongitude"].ToString()); szSiteDesc = TrimSiteDesc(row["szSiteDesc"].ToString()); DisplayState = int.Parse(row["DisplayState"].ToString()); DisplayText = row["DisplayText"].ToString(); Marker marker = new Marker(lLongitude, lLatitude) { Name = lSiteId }; #if (DEBUG) tLog.WriteInfo("lSiteId: " + lSiteId); tLog.WriteInfo("latitude: " + lLatitude); tLog.WriteInfo("longitude: " + lLongitude); #endif marker.Image = GetImage(DisplayState); marker.Tag = DisplayState; marker.ToolTipText = GetMarkerToolTipText(lSiteId, rrId, lLatitude.ToString(), lLongitude.ToString(), szSiteDesc); SetMarkerProperties(marker); markeroverlay.Markers.Add(lSiteId, marker); } SetAllMarkerZOrder(); winformsMap1.Refresh(); tLog.WriteInfo(resources.GetString("DrawMarkersExit")); } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private static void SetMarkerProperties(Marker marker) { marker.Width = INT_markerWidth; marker.Height = INT_markerHeight; marker.XOffset = INT_markerXOffset; marker.YOffset = INT_markerYOffset; } private void SetAllMarkerZOrder() { try { MarkerOverlaySortByDisplayState(); } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; throw; } } private SimpleMarkerOverlay MarkerOverlaySortByDisplayState() { //this function brings occupied markers to the top //of the display //according to ThinkGeo, state 1 markers //must be in the 'front' of the collection GeoCollection tmpSortedMarkers = new GeoCollection(); try { SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["IconMarkerOverlay"]; //sort by Tag (contains state) var query = markerOverlay.Markers.OrderByDescending(s => int.Parse(s.Tag.ToString())); //add to collection in sorted order //item.Name holds lSiteId foreach (Marker item in query) { tmpSortedMarkers.Add(item.Name, item); } //clear the display collection markerOverlay.Markers.Clear(); //add ordered markers back to display collection foreach (Marker item in tmpSortedMarkers) { markerOverlay.Markers.Add(item.Name, item); #if (DEBUG) tLog.WriteInfo("Adding name: " + item.Name); #endif } return markerOverlay; } catch (Exception ex) { StackFrame stackFrame = new StackFrame(); tLog.WriteError(String.Format("{0}:{1}", stackFrame.GetMethod().Name, ex.Message)); stackFrame = null; return null; } finally { tmpSortedMarkers.Clear(); tmpSortedMarkers = null; } }