【发布时间】:2018-04-19 22:12:17
【问题描述】:
大家好,我是新人,请原谅我可能的错误!谢谢你的时间..我想问一下我可以做些什么来在我的 html 页面中的所有内容前面添加一个按钮?我尝试在样式中使用“z-index”,但它不起作用。 :( 我用一个名为“btn”的类设置了按钮。这是一个紧急情况,因为它是为了我的毕业论文..谢谢!这是 html 文件:
function init() {
map = new OpenLayers.Map('basicMap');
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
navigator.geolocation.getCurrentPosition(function (position) {
document.getElementById('anzeige').innerHTML = 'Latitude: ' +
position.coords.latitude +
' Longitude: ' +
position.coords.longitude + '<p>';
var lonLat = new OpenLayers.LonLat(position.coords.longitude,
position.coords.latitude)
.transform(
new OpenLayers.Projection('EPSG:4326'), //transform from WGS 1984
map.getProjectionObject() //to Spherical Mercator Projection
);
markers.addMarker(new OpenLayers.Marker(lonLat));
map.setCenter(lonLat, 16 // Zoom level
);
});
//map = new OpenLayers.Map("basicMap");
//var mapnik = new OpenLayers.Layer.OSM();
//map.addLayer(mapnik);
map.setCenter(new
OpenLayers.LonLat(3, 3) // Center of the map
.transform(
new OpenLayers.Projection('EPSG:4326'), // transform from WGS 1984
new OpenLayers.Projection('EPSG:900913') // to Spherical Mercator Projection
), 15 // Zoom level
);
var markers = new OpenLayers.Layer.Markers('Markers');
map.addLayer(markers);
}
init();
.btn{
background-color: #000080;
border: none;
color: white;
padding: 3px 20px;
text-align: center;
white-space: nowrap;
font-size: 20px;
left:10px;
top:40px;
cursor: pointer;
position: absolute;
z-index: 110;
}
html, body, #basicMap {
padding: 0px;
margin: 0px;
height: 100%;
}
.p1 {
border: none;
color: white;
padding: 3px 32px;
font-family:courier;
text-decoration: none;
display: inline-block;
font-size: 30px;
margin: 5px 1025px;
position: absolute;
z-index: 100;
font-weight: bold;
white-space: nowrap;
}
.p2 {
border: none;
color: white;
line-height: 80%;
margin: 10px;
}
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<a class="btn" onclick="myFunction(this)" >Select Point</a>
<p class="p1">Sky Detect App</p>
<p class="p2">Your position estimated by browser geolocation API:</p>
<div id="anzeige" class="p2">(will be displayed here)</div>
<div id="basicMap"></div>
我是这样看的,但它不对.. error button's position
【问题讨论】:
-
看起来你的按钮是在其他一切之上
-
但不是! :(我不知道故障是否是osm干扰了按钮..
-
您在浏览器中看到该按钮的具体情况如何?
-
我在地图后面看到了.. :(
-
我在描述中添加了一张图片,如果您点击末尾:(“按钮位置错误”)
标签: javascript html css openlayers openstreetmap