[mapguide-users] MSSql and mapguide, data not displayed

Jackie Ng jackie.ng at aecsystems.com.au
Mon Mar 3 13:03:22 EST 2008


If you are invoking SelectFeatures() from MgLayer you need to instantiate
MgMap with an MgSiteConnection object otherwise you'll get an Exception

- Jackie


deakaron wrote:
> 
> Thanks for your answer.
> 
> Now I have another problem, I have the following code that throws an
> exception whenever I try to read features from any layer of the Sheboygan
> map.
> 
> import org.osgeo.mapguide.MapGuideJavaApi;
> import org.osgeo.mapguide.MgException;
> import org.osgeo.mapguide.MgFeatureQueryOptions;
> import org.osgeo.mapguide.MgFeatureService;
> import org.osgeo.mapguide.MgLayerBase;
> import org.osgeo.mapguide.MgMap;
> import org.osgeo.mapguide.MgRenderingService;
> import org.osgeo.mapguide.MgResourceIdentifier;
> import org.osgeo.mapguide.MgResourceService;
> import org.osgeo.mapguide.MgServiceType;
> import org.osgeo.mapguide.MgSite;
> import org.osgeo.mapguide.MgSiteConnection;
> import org.osgeo.mapguide.MgUserInformation;
> 
> public class Program {
> 
> 	/**
> 	 * @param args
> 	 */
> 	public static void main(String[] args) {
> 		try {
> 			MgResourceIdentifier mapDefid = new MgResourceIdentifier(
> 					"Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
> 			try {
> 				MapGuideJavaApi.MgInitializeWebTier("C:\\webconfig.ini");
> 			} catch (Exception ex) {
> 				ex.printStackTrace();
> 			}
> 			MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
> 			MgSite site = new MgSite();
> 			site.Open(userInfo);
> 			String sessionId = site.CreateSession();
> 			site.Close();
> 
> 			MgSiteConnection siteConnection = new MgSiteConnection();
> 			siteConnection.Open(new MgUserInformation(sessionId));
> 			MgResourceService service = (MgResourceService) siteConnection
> 					.CreateService(MgServiceType.ResourceService);
> 			MgResourceService resourceService =
> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
> 	        MgMap map = new MgMap();
> 	        map.Open(resourceService, "Sheboygan");
> 			MgRenderingService renderingService = (MgRenderingService)
> siteConnection
> 					.CreateService(MgServiceType.RenderingService);
> 			MgFeatureService featureService = (MgFeatureService) siteConnection
> 					.CreateService(MgServiceType.FeatureService);
> 			/**
> 			 * Make all layers visible
> 			 */
> 			for (int i = 0; i < map.GetLayers().GetCount(); i++) {
> 				MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
> 				queryOptions.SetFilter("Autogenerated_SDF_ID = 1");
> 				MgLayerBase layer = map.GetLayers().GetItem(i);
> 				layer.SetVisible(true);
> 				try {
> 					layer.SelectFeatures(queryOptions);
> 				} catch (Exception ex) {
> 					ex.printStackTrace();
> 				}
> 				System.out.println("Layer name: " + layer.GetName());
> 			}
> 		} catch (MgException ex) {
> 			ex.printStackTrace();
> 		}
> 	}
> 
> }
> 

-- 
View this message in context: http://www.nabble.com/MSSql-and-mapguide%2C-data-not-displayed-tp15760131s16610p15809764.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list