openlayers實(shí)現(xiàn)地圖彈窗
本文實(shí)例為大家分享了openlayers實(shí)現(xiàn)地圖彈窗的具體代碼,供大家參考,具體內(nèi)容如下
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" />
<script type="text/javascript" src="https://openlayers.org/en/v5.3.0/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<title>Ol3 popup</title>
<style type="text/css">
body, #map {
border: 0px;
margin: 0px;
padding: 0px;
padding: 0px;
padding: 0px;
width: 100%;
height: 100%;
font-size: 13px;
}
.ol-popup {
display: none;
position: absolute;
background-color: white;
-moz-box-shadow: 0 1px 4px rgba(0,0,0,0.2);
-webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
border: 1px solid #cccccc;
bottom: 12px;
left: -50px;
width: 200px;
}
.ol-popup:after, .ol-popup:before {
top: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.ol-popup:after {
border-top-color: white;
border-width: 10px;
left: 48px;
margin-left: -10px;
}
.ol-popup:before {
border-top-color: #cccccc;
border-width: 11px;
left: 48px;
margin-left: -11px;
}
.popup-title{
font-weight: bold;
border-bottom:1px solid #cccccc;
padding: 5px 8px;
}
.popup-content{
padding: 5px 8px;
}
.ol-popup-closer {
text-decoration: none;
position: absolute;
top: 6px;
right: 6px;
}
.ol-popup-closer:after {
content: "✖";
}
</style>
<script type="text/javascript">
function init(){
var format = 'image/png';
var bounds = [73.4510046356223, 18.1632471876417,
134.976797646506, 53.5319431522236];
var vectorSource = new ol.source.TileWMS({
url: 'http://localhost:8080/geoserver/map/wms?service=WMS&version=1.1.0&request=GetMap&layers=map:capital&styles=&bbox=87.57607938302118,19.97015007757606,126.56705607814561,45.69385655384421&width=768&height=506&srs=EPSG:4326&format=application/openlayers',
params:{
'LAYERS':'capital',
'TILED':false
},
serverType:'geoserver'
});
var untiled = new ol.layer.Tile({
source: vectorSource
});
var container = document.getElementById('popup');
var content = document.getElementById('popup-content');
var title = document.getElementById('popup-title');
var closer = document.getElementById('popup-closer');
closer.onclick = function(){
container.style.display = 'none';
closer.blur();
return false;
};
var overlay = new ol.Overlay({
element: container
});
var osmsource = new ol.source.OSM()
//console.log(osmsource.getProjection().getCode());
var map = new ol.Map({
controls: ol.control.defaults({
attribution: false
}),
target: 'map',
layers: [new ol.layer.Tile({
source: osmsource, //將數(shù)據(jù)源坐標(biāo)系統(tǒng)進(jìn)行轉(zhuǎn)換
projection:ol.proj.getTransform("EPSG:3857", "EPSG:4326")
}),
untiled],
overlays: [overlay],
view: new ol.View({
center:[117,42],
projection:'EPSG:4326',
zoom:1
})
});
map.addOverlay(overlay);
map.getView().fit(bounds, map.getSize());
map.on('click', function(evt) {
var coordinate = evt.coordinate;
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
coordinate, 'EPSG:4326', 'EPSG:4326'));
overlay.setPosition(coordinate);
content.innerHTML = '<p>You clicked here:</p><code>' + hdms +
'</code>';
container.style.display = 'block';
title.innerHTML = "提示信息";
title.style.display = 'block';
map.getView().setCenter(coordinate);
});
}
</script>
</head>
<body onLoad="init()">
<div id="map">
<div id="popup" class="ol-popup">
<a href="#" rel="external nofollow" id="popup-closer" class="ol-popup-closer"></a>
<div id="popup-title" class="popup-title"></div>
<div id="popup-content" class="popup-content"></div>
</div>
</div>
</body>
</html>
效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Openlayers實(shí)現(xiàn)地圖全屏顯示
- Openlayers學(xué)習(xí)之地圖比例尺控件
- Openlayers實(shí)現(xiàn)地圖的基本操作
- OpenLayers3實(shí)現(xiàn)地圖鷹眼以及地圖比例尺的添加
- OpenLayers3實(shí)現(xiàn)對(duì)地圖的基本操作
- OpenLayers3實(shí)現(xiàn)地圖顯示功能
- openlayers實(shí)現(xiàn)地圖測(cè)距測(cè)面
- vue-openlayers實(shí)現(xiàn)地圖坐標(biāo)彈框效果
- 使用OpenLayers3 添加地圖鼠標(biāo)右鍵菜單
- Openlayers繪制地圖標(biāo)注
相關(guān)文章
JavaScript函數(shù)防抖動(dòng)debounce
這篇文章主要介紹了JavaScript函數(shù)防抖動(dòng)debounce,防抖動(dòng)作用防止在短時(shí)間內(nèi)過(guò)于頻繁的執(zhí)行相同的任務(wù),更多相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-06-06
前端Webpack配置之eval-source-map使用方法
eval-source-map 是 Webpack 中 devtool 選項(xiàng)的一種模式,它提供了一種內(nèi)聯(lián) Source Map 的方式,用于開發(fā)環(huán)境中的源代碼映射,這篇文章主要介紹了前端Webpack配置之eval-source-map使用方法,需要的朋友可以參考下2024-12-12
JavaScript實(shí)現(xiàn)批量重命名文件
這篇文章主要為大家詳細(xì)介紹了如何利用JavaScript實(shí)現(xiàn)批量重命名文件,文中的示例代碼講解詳細(xì),有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-12-12
JavaScript圣杯布局與雙飛翼布局實(shí)現(xiàn)案例詳解
這篇文章主要介紹了JavaScript圣杯布局與雙飛翼布局實(shí)現(xiàn)案例,這是前端面試中需要掌握的知識(shí)點(diǎn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
JavaScript鏈?zhǔn)秸{(diào)用實(shí)例淺析
這篇文章主要介紹了JavaScript鏈?zhǔn)秸{(diào)用,結(jié)合實(shí)例形式分析了javascript鏈?zhǔn)秸{(diào)用的相關(guān)原理、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下2018-12-12
js實(shí)現(xiàn)簡(jiǎn)單的驗(yàn)證碼
這篇文章主要介紹了js實(shí)現(xiàn)簡(jiǎn)單驗(yàn)證碼的方法,驗(yàn)證碼主要是為了網(wǎng)站的安全性,防止惡意注冊(cè)和登陸,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-12-12
JavaScript的for循環(huán)中嵌套一個(gè)點(diǎn)擊事件的問(wèn)題解決
本文主要介紹了JavaScript的for循環(huán)中嵌套一個(gè)點(diǎn)擊事件點(diǎn)擊一次彈出多個(gè)相同的值的解決方法,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03

