[英]Put a simple point at OpenStreetMap-tile using OpenLayers
I've read in many threads trying to put a simple point (vector layer) at my OpenStreetMap. 我读过很多线程,试图在我的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>
ol.Map.addLayer only takes one parameter. ol.Map.addLayer仅采用一个参数。 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. 您也没有在任何地方包含ol.css文件。 Make sure you add that in. Here's a working JSFiddle . 确保将其添加进来。这是一个可用的JSFiddle 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.