AsslamOAlikum。您好我在geoserver的帮助下创建了openlayer地图。我的地图应用程序基于javascript和openlayers(OSM,WMS)。在我的应用程序中,我使用多层,鼠标处理和定位和弹出功能。但我想在弹出功能中改变一些。在我的弹出功能中,当我单击鼠标按钮然后显示' E,W,Degree'的坐标。等等。我想更改为协调替换为关于该地方的获取特色信息。这是我的代码......
<!DOCTYPE html>
<html>
<head>
<title>Overlay</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.4.2/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v4.4.2/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
#marker {
width: 20px;
height: 20px;
border: 1px solid #088;
border-radius: 10px;
background-color: #0FF;
opacity: 0.5;
}
#vienna {
text-decoration: none;
color: white;
font-size: 11pt;
font-weight: bold;
text-shadow: black 0.1em 0.1em 0.2em;
}
.popover-content {
min-width: 180px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<div style="display: none;">
<!-- Popup -->
<div id="popup" title="Welcome to OpenLayers"></div>
</div>
<div id="nodelist">
<em>Click on the map to get feature info</em>
</div>
<div id="mouse-position"></div>
<form>
<label>Projection </label>
<select id="projection">
<option value="EPSG:4326">EPSG:4326</option>
</select>
<label>Precision </label>
<input id="precision" type="number" min="0" max="12" value="4"/>
</form>
<script>
//MOUSE HANDLING
var mousePositionControl = new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(4),
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var LonLat = [69.3451, 30.3753];
var pos = ol.proj.fromLonLat(LonLat);
var layer =[
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Tile({
//extent: [68.107725, 23.744288, 73.622861, 36.878836],
source: new ol.source.TileWMS({
url: 'http://gulraiz-pc:8080/geoserver/test/wms',
params: {LAYERS: 'test:pak_ad3_gaul_ply_15072010', 'TILED': true},
serverType: 'geoserver'
})
}),
new ol.layer.Tile({
//extent: [68.107725, 23.744288, 73.622861, 36.878836],
source: new ol.source.TileWMS({
url: 'http://gulraiz-pc:8080/geoserver/test/wms',
params: {'LAYERS': ' test:longlist', 'TILED': true},
serverType: 'geoserver'
})
})
];
var map = new ol.Map({
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
// collapsible: false
})
}).extend([mousePositionControl]),
layers: layer,
target: 'map',
view: new ol.View({
center: pos,
zoom: 5
})
});
// Popup showing the position the user clicked
var popup = new ol.Overlay({
element: document.getElementById('popup')
});
map.addOverlay(popup);
map.on('click', function(evt) {
var element = popup.getElement();
var coordinate = evt.coordinate;
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
coordinate, 'EPSG:4326', 'EPSG:4326'));
$(element).popover('destroy');
popup.setPosition(coordinate);
// the keys are quoted to prevent renaming in ADVANCED mode.
$(element).popover({
'placement': 'top',
'animation': false,
'html': true,
'content': '<p>The location you clicked was:</p><code>' + hdms + '</code>'
});
$(element).popover('show');
});
</script>
</body>
</html>
答案 0 :(得分:0)
不太明白你的要求。假设您想要特征的坐标而不是点击。
forEachFeatureAtPixel(pixel, (f) => {
coordinate = f.getGeometry().getCoordinates();
}