[fdo-users] How to add WMS Transparent layer???

Patrick Tsang pt at pat.ca
Sat Jun 30 18:03:25 EDT 2007


Thank you guys, got it working with WMS server...

I should explain what i try to do here, i want to add WMS layer on the fly
not through MapStudio.
I am able to add WMS layer on the fly but the layer come back is not
transparent but i cannot figure out how to request the layer as
transparent... here is my code (C#):

        private string formatWMSProviderXml =
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
System.Environment.NewLine +
            "  <FeatureSource
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xsi:noNamespaceSchemaLocation=\"FeatureSource-1.0.0.xsd\">" +
System.Environment.NewLine +
            "    <Provider>OSGeo.WMS</Provider>" +
System.Environment.NewLine +
            "    <Parameter>" + System.Environment.NewLine +
            "      <Name>FeatureServer</Name>" + System.Environment.NewLine
+
            "      <Value>{0}</Value>" + System.Environment.NewLine +
            "    </Parameter>" + System.Environment.NewLine +
            "  </FeatureSource>";

        private string formatWMSLayerXml =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
System.Environment.NewLine +
            "  <LayerDefinition
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xsi:noNamespaceSchemaLocation=\"LayerDefinition-1.0.0.xsd\"
version=\"1.0.0\"> " + System.Environment.NewLine +
            "    <GridLayerDefinition> " + System.Environment.NewLine +
            "      <ResourceId>{0}</ResourceId> " +
System.Environment.NewLine +
            "      <FeatureName>WMS_Schema:{1}</FeatureName> " +
System.Environment.NewLine +
            "      <Geometry>Raster</Geometry> " +
System.Environment.NewLine +
            "      <GridScaleRange> " + System.Environment.NewLine +
            "        <ColorStyle> " + System.Environment.NewLine +
            "          <ColorRule> " + System.Environment.NewLine +
            "            <LegendLabel></LegendLabel> " +
System.Environment.NewLine +
            "            <Color> " + System.Environment.NewLine +
            "              <ExplicitColor>000000</ExplicitColor> " +
System.Environment.NewLine +
            "            </Color> " + System.Environment.NewLine +
            "          </ColorRule> " + System.Environment.NewLine +
            "          <ColorRule> " + System.Environment.NewLine +
            "            <LegendLabel></LegendLabel> " +
System.Environment.NewLine +
            "            <Color> " + System.Environment.NewLine +
            "              <ExplicitColor>FFFFFF</ExplicitColor> " +
System.Environment.NewLine +
            "            </Color> " + System.Environment.NewLine +
            "          </ColorRule> " + System.Environment.NewLine +
            "        </ColorStyle> " + System.Environment.NewLine +
            "        <RebuildFactor>1</RebuildFactor> " +
System.Environment.NewLine +
            "      </GridScaleRange> " + System.Environment.NewLine +
            "    </GridLayerDefinition> " + System.Environment.NewLine +
            "  </LayerDefinition>";

        public void AddLayer(string SessionId, string ClassName, Server
Server, string MapName)
        {
            // Create MgSiteConnection
            MgSiteConnection siteConnection = new MgSiteConnection();
            siteConnection.Open(new MgUserInformation(SessionId));

            //create the services we will use
            MgResourceService resourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;

            //create the wms feature source
            // NOTES: Server.URL is something like
"http://www.geographynetwork.ca/wmsconnector/com.esri.wms.Esrimap/OBM_Full_I?request=getcapabilities&service=WMS&version=1.1.1"
            string formatedWmsProviderXml =
string.Format(formatWMSProviderXml, XmlEscape(Server.URL));

            MgByteSource wmsFeatureSourceByteSource = new
MgByteSource(System.Text.Encoding.ASCII.GetBytes(formatedWmsProviderXml),
formatedWmsProviderXml.Length);
            wmsFeatureSourceByteSource.SetMimeType(MgMimeType.Xml);
            string featureSourceName =
string.Format("Session:{0}//{1}.FeatureSource", SessionId, Guid.NewGuid());
            MgResourceIdentifier WmsFeatureSourceResourceIdentifier = new
MgResourceIdentifier(featureSourceName);
            resourceService.SetResource(WmsFeatureSourceResourceIdentifier,
wmsFeatureSourceByteSource.GetReader(), null);

            //create the wms layer
            // NOTES: ClassName is the layer name user pick from a list of
layers from the Server.URL
            string layerWmsName = ClassName;
            string formatedWmsLayerXml = string.Format(formatWMSLayerXml,
XmlEscape(featureSourceName), XmlEscape(layerWmsName));
            MgByteSource wmsLayerByteSource = new
MgByteSource(System.Text.Encoding.ASCII.GetBytes(formatedWmsLayerXml),
formatedWmsLayerXml.Length);
            wmsLayerByteSource.SetMimeType(MgMimeType.Xml);

            MgResourceIdentifier wmsLayerResourceIdentifier = new
MgResourceIdentifier(string.Format("Session:{0}//{1}.LayerDefinition",
SessionId, layerWmsName));
            resourceService.SetResource(wmsLayerResourceIdentifier,
wmsLayerByteSource.GetReader(), null);

            //get a reference to the map
            MgResourceService l_oResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
            MgMap map = new MgMap();
            map.Open(l_oResourceService, MapName);

            // Add the new layer to the map's layer collection
            MgLayer newLayer = new MgLayer(wmsLayerResourceIdentifier,
resourceService);

            newLayer.SetName(layerWmsName);
            newLayer.SetVisible(true);
            newLayer.SetLegendLabel(layerWmsName);
            newLayer.SetDisplayInLegend(true);


            MgLayerCollection layerCollection = map.GetLayers();
            if (!layerCollection.Contains(layerWmsName))
            {
                // Insert the new layer at position 0 so it is at
                // the top of the drawing order
                layerCollection.Insert(0, newLayer);

                Server.Layers.Find(delegate(Layer l) { return l.ClassName ==
ClassName; }).IsVisible = true;
            }

            //  Save the map back to the session repository
            string mapResourceName = string.Format("Session:{0}//{1}.Map",
SessionId, MapName);
            MgResourceIdentifier mapResourceID = new
MgResourceIdentifier(mapResourceName);
            mapResourceID.Validate();
            map.Save(resourceService, mapResourceID);

            // return
            //return Server;
        }

There has objects not defined, try to keep it short. Sorry about it...
Thanks in advance!!!

Cheers,
Patrick


gregboone wrote:
> 
> Also, use the depends.exe application (or other appropriate NS tool) to
> determine modules are missing.
> 
> Greg
> 
> -----Original Message-----
> From: fdo-users-bounces at lists.osgeo.org
> [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Hidekazu Shimaji
> Sent: Friday, June 22, 2007 8:46 PM
> To: fdo-users at lists.osgeo.org
> Subject: Re: [fdo-users] The specified module could not be found.
> (Exceptionfrom HRESULT: 0x8007007E)
> 
> 
> Hello Patrick,
> 
> You need add the following path to your "Path" system environment
> variable.
> 
> C:\Program Files\MapGuideOpenSource\Server\Bin\FDO
> C:\Program Files\MapGuideOpenSource\Server\Bin\FDO\com
> 
> They are where fdo files are locationed.
> This is because the OSGeo.*.dlls refer other files in those folders.
> 
> Try it.
> 
> Regards,
> Hidekazu
> 
> --- original message ---
> Hi Guys,
> 
> I ran into this error when I try to use FDO in my C# web application.
> Here
> is what I did.
> 
> 1.) I downloaded 3.2.1 binaries from http://fdo.osgeo.org/download.html
> 2.) Create a new web application using VS 2005
> 3.) Add all the OSGeo.*.dll reference 
> 4.) Run the web application then I got that error...
> 
> Any idea will be great!!! Thanks in advance.
> 
> Cheers,
> Patrick
> 
> -- 
> View this message in context:
> http://www.nabble.com/The-specified-module-could-not-be-found.-%28Except
> ion-from-HRESULT%3A-0x8007007E%29-tf3967241s18162.html#a11262204
> Sent from the fdo-users mailing list archive at Nabble.com.
> 
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> 

-- 
View this message in context: http://www.nabble.com/The-specified-module-could-not-be-found.-%28Exception-from-HRESULT%3A-0x8007007E%29-tf3967241s18162.html#a11377462
Sent from the fdo-users mailing list archive at Nabble.com.



More information about the fdo-users mailing list