[OpenLayers-Users] need help displaying a vector
LazyGun
lazygun at gmx.de
Thu Jun 5 09:24:10 EDT 2008
Got it to work now. I had to use a LineString instead of a Curve and added
tranformation for the Geography.Point(s).
LazyGun wrote:
>
> Hi everyone,
>
> i'm new to openlayers. on my webpage i want to display a number of markers
> which represent gps positions which are stored in a database. These
> markers then should be connected by a line. (in order)
>
> To achieve this i dynamically create a script which uses the gps
> coordinates i need. So far i have successfully created the markers but
> haven't been able to create a line between them.
>
> To draw a line between the markers, i want to use a
> OpenLayers.Feature.Vector object.
>
> here is an example of a generated script for two points/markers that i use
> so far:
>
> <script language = 'javascript'>
> var x; var y; var userid; var speed; var date;
> var map = new OpenLayers.Map('map',
> { maxExtent: new
> OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
> numZoomLevels: 19,
> maxResolution: 156543.0399,
> units: 'm',
> projection: new OpenLayers.Projection("EPSG:900913"),
> displayProjection: new OpenLayers.Projection("EPSG:4326")
> });
> var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik (updated
> weekly)");
> var layerTah = new OpenLayers.Layer.OSM.Osmarender("Tiles at Home");
> map.addLayers([layerMapnik,layerTah]);
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> var markers = new OpenLayers.Layer.Markers("Markers");
> var centerPoint = new OpenLayers.LonLat(0,0).transform(new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> map.setCenter(centerPoint, 12);
> var size = new OpenLayers.Size(30,30);
> var offset = new OpenLayers.Pixel(-(size.w/2), -(size.h/2));
> var icon = new OpenLayers.Icon('pin2.gif', size, offset);
> var geoPoints = new OpenLayers.Geometry.MultiPoint();
> var vectorlayer = new OpenLayers.Layer.Vector("Route");
>
> x = 52.498334;y = 13.391626;
> var geoPoint0 = new OpenLayers.Geometry.Point(13.391626, 52.498334);
> geoPoints.addPoint(geoPoint0);
> var point = new OpenLayers.LonLat(13.391626,52.498334).transform(new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> var marker0 = new OpenLayers.Marker(point, icon.clone());
> var html = "05.03.2008";
> marker0.events.register('mousedown', marker0, function() { alert("Datum:
> 05.03.2008\nZeit: 09:24:00\nBenutzername: Zimmermann\nUserID:
> 250e1336");});
> markers.addMarker(marker0);
> x = 52.497447;y = 13.391813;
> var geoPoint1 = new OpenLayers.Geometry.Point(13.391813, 52.497447);
> geoPoints.addPoint(geoPoint1);
> var point = new OpenLayers.LonLat(13.391813,52.497447).transform(new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> var marker1 = new OpenLayers.Marker(point, icon.clone());
> var html = "05.03.2008"; marker1.events.register('mousedown', marker1,
> function() { alert("Datum: 05.03.2008\nZeit: 09:25:01\nBenutzername:
> Zimmermann\nUserID: 250e1336");});
> markers.addMarker(marker1);
> var centerPoint = new OpenLayers.LonLat(13.391813,52.497447).transform(new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> map.setCenter(centerPoint, 12);
>
> var line = new OpenLayers.Geometry.Curve(geoPoints.components);
> var vector = new OpenLayers.Feature.Vector(line);
> vectorlayer.addFeatures([vector]);
> map.addLayer(vectorlayer);
> map.addLayer(markers);
> </script>
>
>
> As i said, it shows the markers but not the vecctor.
>
> Any advice would be welcome.
>
> ps: sorry for bad english.
>
--
View this message in context: http://www.nabble.com/need-help-displaying-a-vector-tp17668316p17669708.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list