[OpenLayers-Dev] Vector layer

Damiano Morosi damiano.morosi at gmail.com
Fri Oct 17 14:23:13 EDT 2008


Hi,

I'm a new user of OpenLayers. I'm trying to display a custom feature over a
map, reading a wkt string. This is the code I used:

<script type="text/javascript">
       var lon = 24;
       var lat = 42;
       var zoom = 5;
       var map, layer, path;

       var result_style = OpenLayers.Util.applyDefaults({
            strokeWidth: 20,
            strokeColor: "#ff0000",
            fillOpacity: 0
        }, OpenLayers.Feature.Vector.style['default']);

       function init(){
           map = new OpenLayers.Map( 'map', {
             projection: "EPSG :4806",
             maxExtent: new OpenLayers.Bounds(10.9083333334, 42.5686666667,
11.3083333334, 42.9686666667)} );
           layer = new OpenLayers.Layer.MapServer( "Navstreet Map",
                   "http://url",
                   {layers: 'GreenA Water Streets Autostrade1'},
                   {gutter: 15});
           path = new OpenLayers.Layer.Vector("Downtown data area",
                                                {style: result_style});

           map.addLayers([layer, path]);


           map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);

           parser = new OpenLayers.Format.WKT();
           //var wkt = "LINESTRING(11.095 42.761, 11.123 42.767)";
           var wkt = "POINT(11.095 42.761)";
           var geometry = parser.read(wkt);
           var feature = new OpenLayers.Feature.Vector(geometry);
           path.addFeatures([feature]);

           map.addControl( new OpenLayers.Control.LayerSwitcher() );
           map.addControl(new OpenLayers.Control.MousePosition());

           map.zoomToExtent(new OpenLayers.Bounds(10.9083333334,
42.5686666667, 11.3083333334, 42.9686666667), true);

       }

   </script>

If I add the "path" layer, the map displays in a strange way. Looking at
firefox debug window, I get the following message:

"feature.geometry.getBounds() is not a function"

What I'm missing?

Thank you,

Damiano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20081017/7b108407/attachment.html


More information about the Dev mailing list