[OpenLayers-Dev] [openlayers/mapserver]display shapefile content having TYPE as LINE

Alexandre Dube adube at mapgears.com
Mon Jul 20 10:10:33 EDT 2009


Hi,

  First, that question is more suitable for the 'users' mailing list.  
See below for more.

abir rezgui wrote:
> Hi there!
>
> I want to display the content of a shapefile using mapserver with 
> openlayers. I did it successfully in cases where the layer's type is 
> POLYGON but I still don't know where is the problem to do it when the 
> layer's type is LINE.
>
> Here are informations about my shapefile displayed with ogr info:
>
> INFO: Open of 
> `C:\ms4w\Apache\htdocs\my_shape_files\shape_ams\EXP_SEGMENT_FONCTIONNEL.shp' 
>
> using driver `ESRI Shapefile' successful.
> Layer name: EXP_SEGMENT_FONCTIONNEL
> Geometry: Line String
> Feature Count: 6
> Extent: (633527.743437, 2517184.387950) - (669562.958005, 2556945.272294)
> Layer SRS WKT:
> (unknown)
> ID_SEGMENT: Real (24.5)
> ID_RESEAU: Real (24.5)
> TYPE_ETB_O: String (5.0)
> ID_ETB_ORI: Real (24.5)
> TYPE_ETB_E: String (5.0)
> ID_ETB_EXT: Real (24.5)
> CODE_OUVRA: String (30.0)
> ID_RAMONAB: Real (24.5)
> CLASSIFICA: String (80.0)
> LONGUEUR_S: Real (24.5)
> PME: Real (24.5)
> EXPL_DEGS_: String (80.0)
> COMMENTAIR: String (255.0)
> PK_INIT: Real (24.5)
> ID_ENTITE_: String (30.0)
> STATUT_CON: String (1.0)
> AUTEUR: String (80.0)
> DATE_DERNI: Date (10.0)
>
> Here is the content of my mapfile:
>
> MAP
>   IMAGETYPE      PNG
>   EXTENT         633527.743437 2517184.387950 669562.958005 
> 2556945.272294
>   SIZE           400 300
>   SHAPEPATH      "/ms4w/Apache/htdocs/my_shape_files/shape_ams"
>   IMAGECOLOR     255 255 255
>   LAYER
>     NAME         EXP_SEGMENT_FONCTIONNEL
>     DATA         EXP_SEGMENT_FONCTIONNEL
>         STATUS       OFF
>         TYPE         LINE
>     STATUS       DEFAULT
>     CLASS
>       NAME       "AMS Example"
>       STYLE
>         COLOR        0 0 0
>         OUTLINECOLOR 32 32 32
>       END
>     END
>   END
> END
>
> finally here is the content of the html file with the javascript code:
>
> <html xmlns="http://www.w3.org/1999/xhtml">
>   <head>
>     <title>MapServer Layer: AMS Example</title>
>     <script src="../../lib/OpenLayers.js"></script>
>     <script type="text/javascript">
>         var map, layer, mybounds;
>         function init(){
>             map = new OpenLayers.Map("map");
>             layer = new OpenLayers.Layer.MapServer( "Exemple AMS", 
> "http://localhost:8081/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/my_examples_MS/ams_exp.map", 
> {layers: "EXP_SEGMENT_FONCTIONNEL", format: 'image/png', isBaseLayer: 
> false, opacity: 1});
>             map.addLayer(layer);
>             mybounds = new 
> OpenLayers.Bounds(633527.743437,2517184.387950,669562.958005,2556945.272294); 
>
>             map.zoomToExtent(mybounds);
>             map.addControl( new OpenLayers.Control.LayerSwitcher() );
>         }
>     </script>
>   </head>
>   <body onload="init()">
>     <div id="title">MapServer Layer: AMS Example</div>
>     <div id="map"></div>
>   </body>
> </html>
>

Your map object is missing an 'options' object (2nd argument) with the 
required 'projection', 'units', 'maxResolution', etc. properties.  Plus, 
your data seems to be in meters.  OpenLayers is in degrees by default.  
Here's an example of what I mean :

=============================================
        var oMapOptions = {
            controls: [], units: 'm', maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds( -1192709.604, -204908.6926,
                                              1172293.7082, 2338511.3665),
            projection: new OpenLayers.Projection("EPSG:32198"),
            numZoomLevels: 11,
            scales: [13000000, 8000000, 4000000, 2000000, 1000000,
                      500000, 250000, 100000, 50000, 25000, 10000]
        };

        oMap = new OpenLayers.Map( 'map', oMapOptions );
=============================================

Also, the 3rd argument of your OpenLayers.Layer.MapServer object is an 
object of 'params'.  isBaseLayer is a 'options' parameter of the 4th 
argument.  See the code source of Layer/MapServer.js.  This should look 
more like :


layer = new OpenLayers.Layer.MapServer(
  "Exemple AMS", // layer name
  
"http://localhost:8081/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/my_examples_MS/ams_exp.map", 
// url
  {layers: "EXP_SEGMENT_FONCTIONNEL", format: 'image/png'}, // params 
(server-side options)
  {isBaseLayer: false, opacity: 1} // options (openlayers options)
);

By the way, 'format' is a Layer.WMS parameter only.  You should switch 
to WMS since it's better than MapServer.

Regards,

> I tried to display this shapefile without using openlayers and it 
> worked so I guess the problem is in the javascript code probabily when 
> calling the method /*OpenLayers.Layer.MapServer()*/ but when I tried 
> to debug the code I found no errors! Note that I did the same way to 
> display other shapefiles content having TYPE POLYGON with openlayers 
> using mapserver and that worked well so I don't know what else to do now!
>
> Please HELP!
>
> -- 
> Abir Rezgui
> -----------------------
> Elève Ingénieur à l'Ecole Nationale des Sciences Informatiques ( ENSI )
> ------------------------------------------------------------------------
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Dev mailing list