<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type='text/javascript' src='lib/OpenLayers.js'></script>
<script type='text/javascript'>
var map;
function init(){
var bounds = new OpenLayers.Bounds(
87.60611724853516, 20.03179359436035,
126.64334106445312, 45.741493225097656
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.1524891555309296,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
var wms = new OpenLayers.Layer.WMS(
'OpenLayers WMS',
'http://localhost:8081/geoserver/wms',
{layers: 'china:shoudu'},
{}
);
var capital = new OpenLayers.Layer.WMS(
'capitals',
'http://localhost:8081/geoserver/wms',
{layers: 'china:bou2_4l',
transparent: true},
{opacity: 1}
);
map.addLayers([wms, capital]);
map.addControl(new OpenLayers.Control.LayerSwitcher({}));
if(!map.getCenter()){
map.zoomToMaxExtent();
}
}
/
function search(text){
var filter = new OpenLayers.Filter.Comparison({//比较操作符
type: OpenLayers.Filter.Comparison.LIKE,
property: "NAME",
value: text
})
var filter_1_0 = new OpenLayers.Format.Filter.v1_0_0();
var xml = new OpenLayers.Format.XML();
var xmlPara = xml.write(filter_1_0.write(filter));
document.getElementById("send").innerHTML = xmlPara;
XML = '<?xml version="1.1.0" encoding="UTF-8"?>' + "/n";
XML = '<wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2"';
XML += ' xmlns:topp="http://www.openplans.org/topp"';
XML += ' xmlns:wfs="http://www.opengis.net/wfs"';
XML += ' xmlns:ogc="http://www.opengis.net/ogc"';
XML += ' xmlns:gml="http://www.opengis.net/gml"';
XML += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
XML += ' xsi:schemaLocation="http://www.opengis.net/wfs';
XML += ' http://schemas.opengis.net/wfs/1.1.0/WFS-basic.xsd">';
XML += '<wfs:Query typeName="china:shoudu">' + "/n";
XML += '<wfs:PropertyName>china:NAME</wfs:PropertyName>' + '/n';
XML += '<wfs:PropertyName>china:the_geom</wfs:PropertyName>' + '/n';
XML += xmlPara;
XML += '</wfs:Query>' + "/n";
XML += '</wfs:GetFeature>';
var request = OpenLayers.Request.POST({
url : "http://localhost:8081/geoserver/wfs",
data : XML,
callback : handler
});
}
function handler(req){
document.getElementById('info').innerHTML = req.responseText;
var gml = new OpenLayers.Format.GML();
var feature = gml.read(req.responseText);
trans(feature[0]);
}
function trans(obj){
var geometry = obj.geometry;
var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
map.setCenter(foundPosition, 14);
}
</script>
</head>
<body οnlοad="init()">
<div id="map" style="width:80%;height:400px;border:1px solid;"> </div>
<div id='map_feature_log'>
<script type="text/javascript">
function clicked(){
//trans(feature_point2);
search(document.getElementById('st').value);
}
</script>
<input type="text" value="" id="st"/>
<input type="button" id="b" value="click me" οnclick="clicked()"/>
<textarea id="info">information</textarea>
<textarea id="send">send</textarea>
</div>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type='text/javascript' src='lib/OpenLayers.js'></script>
<script type='text/javascript'>
var map;
function init(){
var bounds = new OpenLayers.Bounds(
87.60611724853516, 20.03179359436035,
126.64334106445312, 45.741493225097656
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.1524891555309296,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
var wms = new OpenLayers.Layer.WMS(
'OpenLayers WMS',
'http://localhost:8081/geoserver/wms',
{layers: 'china:shoudu'},
{}
);
var capital = new OpenLayers.Layer.WMS(
'capitals',
'http://localhost:8081/geoserver/wms',
{layers: 'china:bou2_4l',
transparent: true},
{opacity: 1}
);
map.addLayers([wms, capital]);
map.addControl(new OpenLayers.Control.LayerSwitcher({}));
if(!map.getCenter()){
map.zoomToMaxExtent();
}
}
/
function search(text){
var filter = new OpenLayers.Filter.Comparison({//比较操作符
type: OpenLayers.Filter.Comparison.LIKE,
property: "NAME",
value: text
})
var filter_1_0 = new OpenLayers.Format.Filter.v1_0_0();
var xml = new OpenLayers.Format.XML();
var xmlPara = xml.write(filter_1_0.write(filter));
document.getElementById("send").innerHTML = xmlPara;
XML = '<?xml version="1.1.0" encoding="UTF-8"?>' + "/n";
XML = '<wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2"';
XML += ' xmlns:topp="http://www.openplans.org/topp"';
XML += ' xmlns:wfs="http://www.opengis.net/wfs"';
XML += ' xmlns:ogc="http://www.opengis.net/ogc"';
XML += ' xmlns:gml="http://www.opengis.net/gml"';
XML += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
XML += ' xsi:schemaLocation="http://www.opengis.net/wfs';
XML += ' http://schemas.opengis.net/wfs/1.1.0/WFS-basic.xsd">';
XML += '<wfs:Query typeName="china:shoudu">' + "/n";
XML += '<wfs:PropertyName>china:NAME</wfs:PropertyName>' + '/n';
XML += '<wfs:PropertyName>china:the_geom</wfs:PropertyName>' + '/n';
XML += xmlPara;
XML += '</wfs:Query>' + "/n";
XML += '</wfs:GetFeature>';
var request = OpenLayers.Request.POST({
url : "http://localhost:8081/geoserver/wfs",
data : XML,
callback : handler
});
}
function handler(req){
document.getElementById('info').innerHTML = req.responseText;
var gml = new OpenLayers.Format.GML();
var feature = gml.read(req.responseText);
trans(feature[0]);
}
function trans(obj){
var geometry = obj.geometry;
var foundPosition = new OpenLayers.LonLat(geometry.x, geometry.y).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
);
map.setCenter(foundPosition, 14);
}
</script>
</head>
<body οnlοad="init()">
<div id="map" style="width:80%;height:400px;border:1px solid;"> </div>
<div id='map_feature_log'>
<script type="text/javascript">
function clicked(){
//trans(feature_point2);
search(document.getElementById('st').value);
}
</script>
<input type="text" value="" id="st"/>
<input type="button" id="b" value="click me" οnclick="clicked()"/>
<textarea id="info">information</textarea>
<textarea id="send">send</textarea>
</div>
</body>
</html>