[mapserver-users] Help To Add Layer on MAP Dynamically.....

Hulbert, Brian brian.hulbert at linquest.com
Tue Jun 24 04:39:13 PDT 2008


Using MapServer 5.0.2 & C# with VS2005, I use some simple factory methods I
built.

 

        /// <summary>Factory method to create a MapServer layer object of
the specified type and Id

        /// <para>NOTE: the layer is visible/on by default with an 100%
opacity and a default lat/long "projection"</para></summary>

        /// <param name="baseMap">the MaperServer mapObj for which this new
layer is to be created</param>

        /// <param name="layerType">the MapServer layer type enumeration
specifying the type of MapServer layerObj to create</param>

        /// <param name="uniqueLayerId">the MapServer unique layer Id string
to use for the layer's name</param>

        /// <param name="proj4projectionString">the Proj.4 projection
string</param>

        /// <returns>a MapServer layerObj</returns>

        public static layerObj CreateDefaultLayer(mapObj baseMap,
MS_LAYER_TYPE layerType, string uniqueLayerId, string proj4projectionString)

        {

            System.Diagnostics.Debug.Assert(baseMap != null,
MAPNOTINSTANTIATED);

 

            layerObj layer = new layerObj(baseMap);

 

            // set the layer type

            layer.type = layerType;

            // set a unique id for this layer

            layer.name = uniqueLayerId;

            // set the default map projection for this layer

            layer.setProjection(proj4projectionString);

            // set initial layer visibility

            layer.status = mapscript.MS_ON; // visible by default

            // set layer non-transparent

            layer.opacity = 100;

 

            return layer;

        }

 

        /// <summary>Factory method to create a MapServer class object of
the specified parent layer

        /// <para>NOTE: the class name is of the form: "Class of [parent
layer name]"</para></summary>

        /// <param name="parentLayer">the MapServer layerObj into which this
class is to be inserted</param>

        /// <returns>a MapServer classObj</returns>

        public static classObj CreateDefaultClass(layerObj parentLayer)

        {

            System.Diagnostics.Debug.Assert(parentLayer != null, "The parent
layer for this class has not been instantiated!");

 

            // create a class of this layer to specify how this layer is to
be drawn

            classObj layerClass = new classObj(parentLayer);

            // set a unique name for this class

            layerClass.name = "Class of " + parentLayer.name;

 

            return layerClass;

        }

 

 

        /// <summary>Factory method to create a MapServer style
object</summary>

        /// <param name="parentClass">the MapServer classObj into which this
style is to be inserted</param>

        /// <returns>a MapServer styleObj</returns>

        public static styleObj CreateDefaultStyle(classObj parentClass)

        {

            System.Diagnostics.Debug.Assert(parentClass != null, "The parent
class cannot be null.");

 

            styleObj style = new styleObj(parentClass);

 

            style.color.setRGB(0, 0, 0);    // set the color to use when
drawing this style (black)

            style.opacity = 100;            // set the style to non
transparent

            style.symbol = 0;               // use the default symbol when
drawing this layer

            style.antialias = (int)mapscript.MS_FALSE;  // do not antialias
cartoline symbols

            return style;

        }

 

 

                Then in my InsertShapeFileLayer() method, I do the
following:

 

            layerObj layer = MapServerFactory.CreateDefaultLayer(m_baseMap,
MS_LAYER_TYPE.MS_LAYER_POLYGON, uniqueLayerId, LATLONPROJECTIONSTRINGBASE);

 

            // set the filename for the new layer's shape file

            layer.data = fqShapeFilename;   // a fully qualified shape path
and filename

 

            // set all layers initially on

            layer.status = (int)mapscript.MS_ON; 

 

            // create a class of this layer to specify how this layer is to
be drawn

            classObj layerClass =
MapServerFactory.CreateDefaultClass(layer);

 

            // create a style for this class to use when drawing this layer

            styleObj classStyle =
MapServerFactory.CreateDefaultStyle(layerClass);

 

            // set the default pixel width of the style's pen

            classStyle.size = 1;

 

      where:

        /// <summary>constant fundamental Proj.4 projection string for a
latlong "projection"</summary>

        private const string LATLONPROJECTIONSTRINGBASE = "+proj=latlong
+ellps=WGS84 +datum=WGS84 +over";

 

 

IHTH,

 

Brian

 

From: mapserver-users-bounces at lists.osgeo.org
[mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Prasad B
Sent: Tuesday, June 24, 2008 12:09 AM
To: mapserver-users at lists.osgeo.org
Subject: [mapserver-users] Help To Add Layer on MAP Dynamically.....

 

 

Respt Sir/Madam ,

 

 i m performing one MAP SERVER Application in which i want to Add Points on
my MAP Place Where user Click, i m doing application in C# , want to add
layer Dynamically , so how i can add layer .

 

 

          Please Help 

 


Thanks & Regards, 

Prasad A. Bhale
iWork Technologies Pvt. Ltd.
Mobile:+91-9960051912
Visit us: www.iworktech.com <http://www.iworktech.com/> 

This email message and any attachments is confidential and intended only for
the use of an individual or entity named above and may contain information
that is privileged, confidential or exempt from disclosure under applicable
law. If you are not the intended recipient, you are notified that any
dissemination, distribution or copying of this email is strictly prohibited.
iWork does not accept liability for any errors, omissions, corruption or
virus in the contents of this message or any attachments that arise as a
result of e-mail transmission. If you have received this communication in
error, please notify the sender and delete the original message and its
attachments immediately. 



-- 
Thanks & Regards, 

Prasad A. Bhale
iWork Technologies Pvt. Ltd.
Mobile:+91-9960051912
Visit us: www.iworktech.com

This email message and any attachments is confidential and intended only for
the use of an individual or entity named above and may contain information
that is privileged, confidential or exempt from disclosure under applicable
law. If you are not the intended recipient, you are notified that any
dissemination, distribution or copying of this email is strictly prohibited.
iWork does not accept liability for any errors, omissions, corruption or
virus in the contents of this message or any attachments that arise as a
result of e-mail transmission. If you have received this communication in
error, please notify the sender and delete the original message and its
attachments immediately. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20080624/d07be09b/attachment.htm>


More information about the MapServer-users mailing list