/// <summary> /// Add ArcIMS map service layer to map /// </summary> /// <param name="msi">Map service information</param> private void AddLayerArcIMS(esri.gpt.csw.MapServiceInfo msi) { if (msi == null) { throw new ArgumentNullException(); } try { IMxDocument mxDoc = (IMxDocument)m_application.Document; IMap map = (IMap)mxDoc.FocusMap; IActiveView activeView = (IActiveView)map; bool isAlreadyInMap = false; if (isAlreadyInMap) { ShowErrorMessageBox (StringResources.MapServiceLayerAlreadyExistInMap); return; } else { //IIMSConnection imsConnection; IIMSMapLayer imsMapLayer; // create service description based on provided map service info IIMSServiceDescription imsServiceDesc = new IMSServiceNameClass(); imsServiceDesc.URL = msi.Server; imsServiceDesc.Name = msi.Service; imsServiceDesc.ServiceType = acServiceType.acMapService; // note: add as image map service // todo: research on the relationship between MapServiceInfo.ServiceType and IIMSServiceDescription #region acServiceType info #endregion // connect to service try { imsMapLayer = new IMSMapLayerClass(); imsMapLayer.ConnectToService(imsServiceDesc); } catch (System.Runtime.InteropServices.COMException ex) { // note: when a site request usr/pwd to connect, user may choose "cancel". Then, imsMapLayer.ConnectToService() // would then throw an System.Runtime.InteropServices.COMException. Catch it but no need to display // any error message. System.Diagnostics.Trace.WriteLine(ex.Message, "NoConnectionToService"); return; } catch (Exception ex) { ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + ex.Message); return; } ILayer layer = (ILayer)imsMapLayer; ExpandLayer(layer, true); SetLayerVisibility(layer, true); // Add the layer mxDoc.AddLayer(imsMapLayer); } } catch (Exception ex) { ShowErrorMessageBox(StringResources.AddArcimsLayerFailed + "\r\n" + ex.Message); } }
/// <summary> /// Add ArcIMS map service layer to map /// </summary> /// <param name="msi">Map service information</param> private void AddLayerArcIMS(pdok4arcgis.MapServiceInfo msi) { if (msi == null) { throw new ArgumentNullException(); } try { IMxDocument mxDoc = (IMxDocument)m_application.Document; IMap map = (IMap)mxDoc.FocusMap; IActiveView activeView = (IActiveView)map; bool isAlreadyInMap = false; /* for (int i = 0; i < map.LayerCount; i++) { // note: minimum checking. to make sure only unique services are added. if (msi.Service.Equals(map.get_Layer(i).Name, StringComparison.OrdinalIgnoreCase)) { isAlreadyInMap = true; break; } }*/ if (isAlreadyInMap) { ShowErrorMessageBox (StringResources.MapServiceLayerAlreadyExistInMap); return; } else { //IIMSConnection imsConnection; IIMSMapLayer imsMapLayer; // create service description based on provided map service info IIMSServiceDescription imsServiceDesc = new IMSServiceNameClass(); imsServiceDesc.URL = msi.Server; imsServiceDesc.Name = msi.Service; imsServiceDesc.ServiceType = acServiceType.acMapService; // note: add as image map service // todo: research on the relationship between MapServiceInfo.ServiceType and IIMSServiceDescription #region acServiceType info /* acMapService 0 An image map service. acFeatureService 1 A feature stream service. acMetadataService 2 A metadata service. acGlobeService 3 A globe service. acWMSService 4 A WMS service. acUnknownService 5 An unknown service. */ #endregion // connect to service try { imsMapLayer = new IMSMapLayerClass(); imsMapLayer.ConnectToService(imsServiceDesc); } catch (System.Runtime.InteropServices.COMException ex) { // note: when a site request usr/pwd to connect, user may choose "cancel". Then, imsMapLayer.ConnectToService() // would then throw an System.Runtime.InteropServices.COMException. Catch it but no need to display // any error message. System.Diagnostics.Trace.WriteLine(ex.Message, "NoConnectionToService"); return; } catch (Exception ex) { ShowErrorMessageBox(StringResources.ConnectToMapServiceFailed + "\r\n" + ex.Message); return; } ILayer layer = (ILayer)imsMapLayer; ExpandLayer(layer, true); SetLayerVisibility(layer, true); // Add the layer mxDoc.AddLayer(imsMapLayer); } } catch (Exception ex) { ShowErrorMessageBox(StringResources.AddArcimsLayerFailed + "\r\n" + ex.Message); } }