[OpenLayers-Users] geometry collection
Marc Jansen
jansen at terrestris.de
Thu Aug 6 05:20:58 EDT 2009
Hi Max,
It is possible to add Geometry Collections to Vectorlayers:
var gc_geometry = new OpenLayers.Geometry.Collection(
[
new OpenLayers.Geometry.Point( ... ),
new OpenLayers.Geometry.LineString( ... ),
new OpenLayers.Geometry.Polygon( ... )
// etc.
]
);
var gc_feature = new OpenLayers.Feature.Vector( gc_geometry );
var vectorLayer = new OpenLayers.Layer.Vector( ... )
vectorLayer.addFeatures( [ gc_feature ] );
Regards,
Marc
Max Weidemann schrieb:
> Dear openlayers users and developers,
>
> I want to know if it is possible to show an geometry collection in an vector
> layer?
> If it is possible could anyone help me please with my code or tell me what
> is the right way for using the geometrycollection??
>
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>OpenLayers Boxes Example</title>
> <link rel="stylesheet" href="../theme/default/style.css"
> type="text/css" />
> <link rel="stylesheet" href="style.css" type="text/css" />
> <script src="../lib/OpenLayers.js"></script>
> <script type="text/javascript">
> var box_extents = [
> [-10, 50, 5, 60],
> [-75, 41, -71, 44],
> [-122.6, 37.6, -122.3, 37.9],
> [10, 10, 20, 20]
> ];
> var map;
> function init(){
> map = new OpenLayers.Map('map');
>
> var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
> "http://labs.metacarta.com/wms/vmap0?", {layers:
> 'basic'} );
>
> var boxes = new OpenLayers.Layer.Vector( "Boxes" );
> var geomcoll = new OpenLayers.Geometry.Collection;
>
> var ext = box_extents[0];
> var bounds1 = new OpenLayers.Bounds(ext[0], ext[1],
> ext[2], ext[3]);
> var geo1=new
> OpenLayers.Feature.Vector(bounds1.toGeometry());
> geomcoll.addComponents(geo1);
>
> ext = box_extents[1];
> var bounds2 = new OpenLayers.Bounds(ext[0], ext[1],
> ext[2], ext[3]);
> var geo2=new
> OpenLayers.Feature.Vector(bounds2.toGeometry());
> geomcoll.addComponents(geo2);
>
> ext = box_extents[2];
> var bounds3 = new OpenLayers.Bounds(ext[0], ext[1],
> ext[2], ext[3]);
> var geo3=new
> OpenLayers.Feature.Vector(bounds3.toGeometry());
> geomcoll.addComponents(geo3);
>
> boxes.addFeatures(geomcoll);
>
> map.addLayers([ol_wms, boxes]);
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> var sf = new OpenLayers.Control.SelectFeature(boxes);
> map.addControl(sf);
> sf.activate();
> map.zoomToMaxExtent();
> }
> </script>
> </head>
>
> <body onload="init()">
> <h1 id="title">Boxes Example</h1>
>
> <div id="tags">
> </div>
>
> <p id="shortdesc">
> Demonstrate marker and box type annotations on a map.
> </p>
>
> <div id="map" class="smallmap"></div>
>
> <div id="docs"></div>
> </body>
> </html>
>
>
>
> The map is shown and the layer boxes is added, but there are no geometries
> shown.
>
--
Diplom-Geograph Marc Jansen
- Anwendungsentwickler -
terrestris GmbH & Co. KG
Irmintrudisstraße 17
53111 Bonn
Tel: ++49 (0)228 / 96 28 99 -53
Fax: ++49 (0)228 / 96 28 99 -57
Email: jansen at terrestris.de
Web: http://terrestris.de
Amtsgericht Bonn, HRA 6835
Komplementärin: terrestris Verwaltungsgesellschaft mbH
vertreten durch: Hinrich Paulsen, Till Adams
More information about the Users
mailing list