Re: OpenLayers WMSGetFeatureInfo пример
Добавлено: 29 сен 2011, 13:35
Хорошо. Вот:
Спойлер
Код: Выделить всё
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/geoserver/openlayers/theme/default/style.css"/>
<script
src="http://192.168.1.3:8080/geoserver/openlayers/lib/OpenLayers.js" type="text/javascript"></script>
<script defer="defer" type="text/javascript">
var info;
function load() {
var bounds = new OpenLayers.Bounds(...);
var options = {
controls:[],
maxExtent: bounds,
maxResolution: 147.527050781249955,
projection: "EPSG:32638",
units: 'm'
};
var map = new OpenLayers.Map('map', options);
var wms = new OpenLayers.Layer.WMS( "test",
"http://192.168.1.3:8080/geoserver/nurc/wms",
{layers: 'nurc:poligon_test',
STYLES: 'PH-test',format: 'image/gif'
}
);
map.addLayer(wms);
map.zoomToMaxExtent();
// build up all controls
map.addControl(new OpenLayers.Control.PanZoomBar({
position: new OpenLayers.Pixel(2, 15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
//map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
map.zoomToExtent(bounds);
wms_info = new OpenLayers.Control.WMSGetFeatureInfo({
title: 'wmsinfo',
layers: [wms],
url: 'http://192.168.1.3:8080/geoserver/nurc/wms',
infoFormat: 'application/vnd.ogc.gml',
queryVisible: true
});
wms_info.events.register('getfeatureinfo', this, showInfo);
map.addControl(wms_info);
wms_info.activate();
map.zoomToMaxExtent();
function showInfo(e) {
var reg = /^reg\./;
var text = '';
for(i in e.features) {
if (i != 0) text += '<br>';
if (reg.test(e.features[i].fid)) {
if (e.features.length != 1)
text += '<b>Цвет:</b><br>';
text += e.features[i].attributes.A+ ' "'
}
}
var popup = new OpenLayers.Popup.FramedCloud("popup",
map.getLonLatFromPixel(e.xy),
new OpenLayers.Size(640,480),
text,
null,
true
);
map.addPopup(popup);
}
}
</script>
</head>
<body onload="load()">
<div style="width: 640px; height: 480px; border: 2px solid black;" id="map"></div>
<div>test</div>
</body>
</html>