The problem with the Anonymous user is that you must create the session with that user. If you attempt to access data from another session, it will work with Administrator, but fail with any other user.

Regards, Kenneth Skovhede, GEOGRAF A/S



Jamo skrev:
I'm trying to create some images straight from mapguide without

This is the code


MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "../webconfig.ini");
        MgUserInformation userInfo = new MgUserInformation("Administrator",
"admin");
        MgSite site = new MgSite();
        //connect to site
        site.Open(userInfo);
        String sessionId = site.CreateSession();
        MgSiteConnection siteConnection = new MgSiteConnection();
        //open site connection
        siteConnection.Open(userInfo);
        MgResourceService ResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
        MgFeatureService FeatureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
        MgRenderingService RenderService =
siteConnection.CreateService(MgServiceType.RenderingService) as
MgRenderingService;
        MgResourceIdentifier mgResourceID = new
MgResourceIdentifier("Library://portbris/maps/PortBris.MapDefinition");
        MgMap baseMap = new MgMap(siteConnection);
        baseMap.Create(ResourceService, mgResourceID, "PortBris");
        MgMap map = new MgMap(siteConnection);

        String mapSRS = baseMap.MapSRS;
        MgEnvelope mapExts = baseMap.GetDataExtent();
map.Create(mapSRS, mapExts, "CadastreModel");
        MgSelection thisSel = new MgSelection(map);

        String layerDef = "Session:" + sessionId +
"//cadSecondary.LayerDefinition";
        MgResourceIdentifier layerDefId = new
MgResourceIdentifier(layerDef);

        String dataSource =
"Library://portbris/data/SQLvmsql01Portbris.FeatureSource";
        MgByteReader layerDefContent =
BuildLayerDefinitionContent(dataSource, "cadSecondary_Full", "", "fd0011",
50, 50, "", "", "1", "fd0011");
        ResourceService.SetResource(layerDefId, layerDefContent, null);

        MgLayer myLayer = new MgLayer(layerDefId, ResourceService);
        myLayer.SetName("cadSecondary");
        myLayer.SetLegendLabel("Other Cadastre");
        myLayer.SetDisplayInLegend(true);
        myLayer.SetSelectable(true);
map.GetLayers().Insert(0, myLayer);


        myLayer = map.GetLayers().GetItem("cadSecondary") as MgLayer;
        MgFeatureQueryOptions fQryOpts = new MgFeatureQueryOptions();
        fQryOpts.SetFilter("BU_NAME LIKE '%FA%'");
        MgFeatureReader cFeatReader = myLayer.SelectFeatures(fQryOpts);
//MgFeatureReader cFeatReader = myLayer.SelectFeatures(null);
        thisSel.AddFeatures(myLayer as MgLayerBase, cFeatReader, 0);
        //thisSel.Save(ResourceService,"CadastreModel");
        Response.Write(thisSel.GetExtents(FeatureService).Height.ToString()
+ " - Feats : " + thisSel.GetSelectedFeaturesCount(myLayer as
MgLayerBase,myLayer.FeatureClassName).ToString());
        cFeatReader.Close();




        //double zoomScale = 1;
        //MgEnvelope ext = thisSel.GetExtents(FeatureService);
        //double xMin = ext.LowerLeftCoordinate.X - (ext.Width * zoomScale);
        //double xMax = ext.UpperRightCoordinate.X + (ext.Width *
zoomScale);

        //double yMin = ext.LowerLeftCoordinate.Y - (ext.Height *
zoomScale);
        //double yMax = ext.UpperRightCoordinate.Y + (ext.Height *
zoomScale);

        //MgEnvelope ext1 = new MgEnvelope(xMin, yMin, xMax, yMax);
        //int W = 0; int H = 0; double M = 0;
        //M = 600 / ext1.Width;

        //W = Convert.ToInt32(ext1.Width * M);
        //H = Convert.ToInt32(ext1.Height * M);


        MgColor bColor = new MgColor(map.GetBackgroundColor());
        MgByteReader byteReader = RenderService.RenderMap(map, thisSel,
thisSel.GetExtents(FeatureService), 500, 500, bColor, "PNG", true);

        MemoryStream memBuf = new MemoryStream();
        byte[] byteBuffer = new byte[1024];
        int numBytes = byteReader.Read(byteBuffer, 1024);
        while (numBytes > 0)
        {
            memBuf.Write(byteBuffer, 0, numBytes);
            numBytes = byteReader.Read(byteBuffer, 1024);
        }
        //Response.ContentType = byteReader.GetMimeType();
        byte[] content = memBuf.ToArray();
        //Response.OutputStream.Write(content, 0, content.Length);


basically no mater what the mgSelection is 1 feature / 17 features, it seems
to return the extents of the map....?

Any Ideas...?

I'm trying to generate everything at runtime for this.

Another query is how to use the Anonymouse user, I've tried but it insists
that they don't have rights to the session repositry?
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to