我想使用 OpenStreetMap 使用图书馆开放层向我的网站显示地图。当我想添加标记时,我想添加一个标记,但该标记没有显示在地图上。
我在谷歌上搜索过,我在我的代码下面找到了一个代码。有很多例子可以添加标记,但它主要用于谷歌地图,我想使用开源地图
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/ css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
///SHOW MAP
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([106.8478695, -6.1568562]),
zoom: 17
})
});
///ADD MARKER
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var size = new OpenLayers.Size(21,25);
var …Run Code Online (Sandbox Code Playgroud) openlayers ×1