Код: Выделить всё
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers WMS Feature Info Example (GeoServer)</title>
<script src="http://localhost:8080/geoserver/www/OpenLayers.js"></script>
<link rel="stylesheet" href="http://localhost:8080/geoserver/www/style1.css" type="text/css">
<link rel="stylesheet" href="http://localhost:8080/geoserver/www/style.css" type="text/css">
<script type="text/javascript">
function load() {
var map = new OpenLayers.Map('map');
var political = new OpenLayers.Layer.WMS("State Boundaries",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
{isBaseLayer: true}
);
var roads = new OpenLayers.Layer.WMS("Roads",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
var water = new OpenLayers.Layer.WMS("Bodies of Water",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
var layer4 = new OpenLayers.Layer.Vector('ДЦ1', {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.WFS({
version: '1.1.0',
url: 'http://localhost:8080/geoserver/IGDG_data/wfs',
featureType: 'churchu',
featureNS: 'file:data/',
extractAttributes: true
}),
});
map.addLayers([political, roads, water,layer4]);
var info1=new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
//title: 'Identify features by clicking',
layers: [layer4,political]
//queryVisible: true
});
var infoControls = {
click:info1
};
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
infoControls.click.activate();
map.zoomToMaxExtent();
}
function showInfo(evt) {
document.getElementById('responseText').innerHTML = evt.text;
}
</script>
</head>
<body onload="load()">
<div id="responseText"> </div>
<div id="map" class="smallmap"></div>
</body>
</html>
1.Этот пример работает для WMS слоев. А мне нужно чтобы так же работало для WFS (в коде это layer4). Пересмотрел кучу литературы и ничего не нашел такого чтобы я понял (я только начинаю программировать в JavaScript). Подскажите что изменить чтобы код заработал для layer4?
2.Не полностью понимаю, что делается в следующих строках. Если бы кто-то мог напишите несколько комментов.
Код: Выделить всё
var info1=new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
//title: 'Identify features by clicking',
layers: [layer4,political]
//queryVisible: true
});
var infoControls = {
click:info1
};
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
infoControls.click.activate();
map.zoomToMaxExtent();
}
function showInfo(evt) {
document.getElementById('responseText').innerHTML = evt.text;
}
Код: Выделить всё
<div id="responseText"> </div>
<div id="map" class="smallmap"></div>
Заранее спасибо!