[OpenLayers-Users] Using Vector Layer with OSM
Christian Hackl
hacki at sbox.tugraz.at
Sun Nov 23 17:20:56 EST 2008
Hi,
This is probably a newbie question, but since I cannot figure out the
answer even after days of reading docs, searching the archives and
studying examples, I thought I'd just ask, so here we go:
How does one use a Vector layer upon an OSM base layer?
All the working Vector examples I've seen use base layers other than
OSM. Copying the entire example code with just replacing the base layer
yields wrong results. No points or lines are visible anymore, or they
all appear centered at the equator no matter which values are chosen as
coordinates.
I'm pretty sure that the problem has to do with projections, but as far
as that topic is concerned, I'm completely lost, both on theory and on
the practical part. I've tried to set the correct projection for OSM,
but none of my trial & error attempts worked. Any hints or reading
material on projections in OpenLayers would be very appreciated.
Here's a simplified example of my problem:
function init()
{
var map = new OpenLayers.Map("map");
map.addControl(new OpenLayers.Control.LayerSwitcher);
// the following uses WMS and *does* work:
// map.addLayer(new OpenLayers.Layer.WMS("OpenLayers WMS",
// "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ));
// the following uses OSM and does *not* work:
map.addLayer(new OpenLayers.Layer.OSM.Osmarender("Osmarender"));
var vectorLayer = new OpenLayers.Layer.Vector("Just a point...");
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(point);
map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
vectorLayer.addFeatures([pointFeature]);
}
I've also uploaded complete versions of both the working and the
non-working example:
http://www.student.tugraz.at/christian.hackl/openlayers/openlayers.html
Thank you,
Christian
--
Christian Hackl
hacki at sbox.tugraz.at
More information about the Users
mailing list