openlayers实现查询功能

<!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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值