Well, turns out the code works, the problem was that I was drawing a
line, and the layer and feature source seemed to only accept polygons.

Regardless, I got what I needed from the example.  Thanks for the
response. J

 

As far as your question... Yes, I am able to programmatically create a
layer and save it permanently.  The code is as follows:

////////////////////////////////////////////////////////////////////////
/////////////////////////////

 

<%@ Page Language="VB" %>

 

<!-- #Include File="../UtilityFunctions.aspx" -->

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

 

<script runat="server">

    Private sessionId As String

    Private MapName As String

</script>

 

<html xmlns="http://www.w3.org/1999/xhtml"; >

<head id="Head1" runat="server">

    <title>Untitled Page</title>

</head>

<body>

 

<%

 

    Try

        ' ------------------------------------------------- '

        ' Basic initialization needs to be done every time. '

        

        sessionId = Session.Item("SESSION")

        MapName = Session.Item("MAPNAME")

        

        InitializeWebTier()

        

        ' Get the user information using the session id,

        ' and set up a connection to the site server.     

        

        Dim UserInfo As New MgUserInformation(sessionId)

        Dim siteconnection As New MgSiteConnection

        siteconnection.Open(UserInfo)

 

        ' Get an instance of the required service(s).

        Dim ResourceService As MgResourceService =
siteconnection.CreateService(MgServiceType.ResourceService)

        Dim featureService As MgFeatureService =
siteconnection.CreateService(MgServiceType.FeatureService)

        

        '---------------------------------------------------'

        ' Open the map

        Dim Map As New MgMap(siteconnection)

        Map.Open(ResourceService, MapName)

        

        Dim tmpLayer As MgLayer

        Dim resourceIdentifier As New
MgResourceIdentifier("Library://Kroll/Data/allparcels.FeatureSource")

        Dim layerResId As New
MgResourceIdentifier("Library://Kroll/Layer/TempX.LayerDefinition")

        

        Dim layerDefinition As String =
File.ReadAllText(Request.MapPath("../testing/layer
template/layerdefinition.xml"))

        layerDefinition = layerDefinition.Replace("%rid",
resourceIdentifier.ToString)

        layerDefinition = layerDefinition.Replace("%fn",
"Default:allparcels")

            

        Dim reader As New MgByteReader(layerDefinition, "text/xml")

        ResourceService.SetResource(layerResId, reader, Nothing)

 

        tmpLayer = New MgLayer(layerResId, ResourceService)

 

        tmpLayer.SetName("TempX")

        tmpLayer.SetLegendLabel("TempX")

        tmpLayer.SetDisplayInLegend(True)

        tmpLayer.SetSelectable(True)

 

        Dim layers As MgLayerCollection = Map.GetLayers

        layers.Insert(0, tmpLayer)

 

        tmpLayer.SetVisible(True)

        tmpLayer.ForceRefresh()

        Map.Save(ResourceService)

        

        Dim permanent As String = "Library://Kroll/Map/" + MapName +
".Map"

        Dim ResId As New MgResourceIdentifier(permanent)

        ResId.Validate()

        Map.Save(ResourceService, ResId)

        

    Catch ex As MgException

        Response.Write(ex.Message)

    End Try

        

%>

 

</body>

</html>

 

 

////////////////////////////////////////////////////////////////////////
///////////////////

 

Notice the use of the layerDefinition... it calls a function which
points to a xml file containing the basics of a layer definition.

The xml file looks like this:

 

--------------------------------------------------------------------

 

<?xml version="1.0" encoding="UTF-8"?>

 

<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">

  <VectorLayerDefinition>

    <ResourceId>%rid</ResourceId>

    <FeatureName>%fn</FeatureName>

    <FeatureNameType>FeatureClass</FeatureNameType>

    <Geometry>Geometry</Geometry>

    <VectorScaleRange>

      <AreaTypeStyle>

        <AreaRule>

          <LegendLabel></LegendLabel>

          <AreaSymbolization2D>

            <Fill>

              <FillPattern>Solid</FillPattern>

              <ForegroundColor>40FF0000</ForegroundColor>

              <BackgroundColor>FF000000</BackgroundColor>

            </Fill>

            <Stroke>

              <LineStyle>Solid</LineStyle>

              <Thickness>0</Thickness>

              <Color>FFFF0000</Color>

              <Unit>Inches</Unit>

            </Stroke>

          </AreaSymbolization2D>

        </AreaRule>

      </AreaTypeStyle>

    </VectorScaleRange>

  </VectorLayerDefinition>

</LayerDefinition>

 

 

--------------------------------------------------------------------

 

I hope this helps.

 

-Mark Pendergraft

 

 

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tsai
Chih-Cheng
Sent: Wednesday, July 11, 2007 3:45 AM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] Create Temporary Feature Source

 

Hi Mark:

First, I'm confused about your question.
My experience is that I translated the same code ( the developer's guide
example  : task_pane_redlining.php & draw_line.php ) to C#.
And it works fine, but I just could draw a line or a polygon temporarily
stored in the session repository.
So, according to your question, I am not sure that your code can create
a permanent layer with feature source stored in the "Library://" or they
are just stored in the session step. 

I am hurry-skurry to know how to create a permanent layer stored in the
"Library://".
I think the steps should be :
1. Login by "Administrator","Admin".
2. Open/Create Map with MgResourceIdentifier(with "Library://...") 
3. Save the map to the "Library://".

But I have tried many different parameters in Open/Create/Save MgMap,
but I still can't make it works successfully.
If you have correct steps or code could demonstrate how to create a
layer with a feature source permanently, please provide me, I would
deeply appreciate it. 

Thanks.

Patrick.



On 7/7/07, Mark Pendergraft <[EMAIL PROTECTED]> wrote:

I'm having a really hard time creating a temporary feature source, on
which to store redlines.  I'm using the developer's guide example
(task_pane_redlining.php & draw_line.php) which I have translated into
VB.  I can create a layer programmatically, and set it's feature source
to an existing layer, and things work fine.   But I cannot create the
temporary feature source, draw a line, and create a layer and then have
that show up on the map.  The layer shows up, and no errors occur in the
code, and I am even able to query the feature source, and it all seems
to work...... except that nothing shows up on the map.

 

If someone could provide an example of creating a feature source in .Net
and/or creating a feature source, and a layer programmatically, I would
greatly appreciate it.

 

Thanks.

 

 

Ph: (425) 486-1252  Fx: (425) 486-6108  www.meadgilman.com
<http://www.meadgilman.com/>  

 


_______________________________________________
mapguide-users mailing list
[email protected] 
http://lists.osgeo.org/mailman/listinfo/mapguide-users

 

<<image001.jpg>>

_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to