[OpenLayers-Users] Problem with Vector
Ilya Braude
ilya at drakontas.com
Fri Feb 13 10:25:44 EST 2009
That, and you never add your features to the vector layer.
http://dev.openlayers.org/releases/OpenLayers-2.7/doc/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.addFeatures
So you need to do something like this:
paden.addFeatures([pointFeature])
Ilya
Arnd Wippermann wrote:
>
> I'm not sure , but map = new OpenLayers.Map("map") creates by default a map
> in EPSG:4326 and not in EPSG:900913. Try without the transformation.
>
> Arnd Wippermann
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Stormcrow
> Gesendet: Freitag, 13. Februar 2009 14:58
> An: users at openlayers.org
> Betreff: [OpenLayers-Users] Problem with Vector
>
>
> I'm trying to draw a point on a map, and to draw a line between two points.
> but Somehow, none of both seem to work.
> I have the lon en lat of every point, which I transform so that I can use
> them as x and y for the Point Objects.
> I have been tinkering with it for a few hours and I'm growing tired of
> wasting time on such a seemingly silly matter :D Does anybody have a clue on
> what I'm doing wrong?
>
> and here is the javascript code:
>
> var map;
> var drawControls;
> var center = new OpenLayers.LonLat(4.68887,50.87589);
> //var center2 = new
> OpenLayers.LonLat(523649.42436625174,6599806.262664414);
> function init(){
> map = new OpenLayers.Map("map");
>
> var kaart = new OpenLayers.Layer.OSM.Mapnik("Kaart");
> var paden = new OpenLayers.Layer.Vector("Paden");
>
> map.addLayers([kaart, paden]);
>
> //var pois = new OpenLayers.Layer.Text( "My Points", {
> location:"./textfile.txt", projection: new
> OpenLayers.Projection("EPSG:4326")} );
> //map.addLayer(pois);
>
> //map.addControl(new OpenLayers.Control.LayerSwitcher());
>
> map.setCenter(center.transform(new
> OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913")), 14);
> //map.setCenter(center2, 14);
>
> /*
> * Put point on map
> */
>
> var style_mark = OpenLayers.Util.extend({},
> OpenLayers.Feature.Vector.style['default']);
> style_mark.graphicWidth = 24;
> style_mark.graphicXOffset = -(style_mark.graphicWidth/2); //
> this is the default value
> style_mark.graphicYOffset = -style_mark.graphicHeight;
> style_mark.externalGraphic = "Ol_icon_blue_example.png";
>
>
> var lonlat = new OpenLayers.LonLat(4.70452,
> 50.87906).transform(new OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> //alert(lonlat.lon + ', ' + lonlat.lat);
> var point = new OpenLayers.Geometry.Point(lonlat.lon,
> lonlat.lat);
> var pointFeature = new
> OpenLayers.Feature.Vector(point,null,style_mark);
>
> /*
> * Put path on map
> */
>
> drawLine(4.70452,50.87906,4.716585,50.864909);
> }
>
> function drawLine(start_x, start_y, finish_x, finish_y) {
> var pointList = [];
> var lonlat_start = new OpenLayers.LonLat(start_x,
> start_y).transform(new OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> var newPoint = new OpenLayers.Geometry.Point(lonlat_start.lon,
> lonlat_start.lat);
> //alert(newPoint.x + ', ' + newPoint.y);
> pointList.push(newPoint);
> var lonlat_finish = new OpenLayers.LonLat(finish_x,
> finish_y).transform(new OpenLayers.Projection("EPSG:4326"), new
> OpenLayers.Projection("EPSG:900913"));
> var newPoint = new OpenLayers.Geometry.Point(lonlat_finish.lon,
> lonlat_finish.lat);
> pointList.push(newPoint);
> var lineFeature = new OpenLayers.Feature.Vector(new
> OpenLayers.Geometry.LineString(pointList));
> --
> View this message in context:
> http://n2.nabble.com/Problem-with-Vector-tp2321331p2321331.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list