[OpenLayers-Users] Trying to get a minimal Vector example to
work....
Nick Whitelegg
nick at hogweed.org
Sun Dec 17 06:04:29 EST 2006
I'm playing around with the Vector code (checked out Dec 13 21:17GMT) and
trying to get a minimal example to work, where the user draws a blue polyline
by clicking points on the map.
This was derived from the vector.html in the examples. I want to add my own
custom code for communicating with a server - hence the need to write my own
code rather than use the "draw line" tool in vector.html.
However, I can't seem to get it to work. The code is as follows:
var map, vector;
var line, feature;
function init() {
map = new OpenLayers.Map('map',
{
maxExtent:new OpenLayers.Bounds(0,0,599999,999999),
maxResolution: 8, units:'meters'});
var ol_wms = new OpenLayers.Layer.WMS( "NPE",
"http://nick.dev.openstreetmap.org/openpaths/freemap.php",
{'layers':'npe'} );
vector = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([vector, ol_wms]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(489600,128500));
map.events.register('click',map,mapClick);
line = new OpenLayers.Geometry.LineString();
feature = new OpenLayers.Feature();
feature.setStyle
( { 'strokeStyle': 'blue', 'lineWidth': 2 } );
feature.setGeometry(line);
vector.addFeatures(feature);
}
function mapClick(e)
{
var pos = map.getLonLatFromViewPortPx
(map.events.getMousePosition(e));
line.addPoint(pos);
}
Any ideas what the problem might be? It's accessible on the web at
http://www.free-map.org.uk/vector/examples/npe.html.
Tested on Firefox 1.5. The vector examples (e.g. vector.html) are working.
I don't get any errors on the javascript console.
Thanks,
Nick
More information about the Users
mailing list