0

I've read in many threads trying to put a simple point (vector layer) at my OpenStreetMap. I'm guessing it is som kind of problem with different projections but i can´t figure it out by myself.

What am i doing wrong in the code below?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://openlayers.org/en/v3.13.1/build/ol.js" type="text/javascript"></script>
    <title>Openstret</title>
</head>
<body>
    <div id="map">
        <script type="text/javascript">

           var vectorSource = new ol.source.Vector();

            var iconFeature = new ol.Feature({
                geometry: new ol.geom.Point([0, 0])
            });

            vectorSource.addFeature(iconFeature);       

            var vectorLayer = new ol.layer.Vector({
                source: vectorSource
            });

            var olmap = new ol.Map({
                view: new ol.View({
                    center: [0, 0],
                    zoom: 2
                }),
                target: 'map'
            });

            var bakgrund = new ol.layer.Tile({source: new ol.source.OSM()});

            olmap.addLayer(bakgrund,vectorLayer);

        </script>

    </div>
</body>
</html>
ahocevar
  • 5,448
  • 15
  • 29

1 Answers1

0

ol.Map.addLayer only takes one parameter. You'll have to add the two layers separately.

Change

olmap.addLayer(bakgrund,vectorLayer);

to

olmap.addLayer(bakgrund);
olmap.addLayer(vectorLayer);

You're also not including the ol.css file anywhere. Make sure you add that in. Here's a working JSFiddle.

rgvassar
  • 5,635
  • 1
  • 24
  • 31