SuperMap 如何高亮省份或某一区域

高亮区域的步骤

1.选择操作的区域图层

2.给图层添加样式

可以根据示范程序中的SQL查询进行区域的选定,先把区域查询出来然后给区域加上style就能达到高亮的效果。

var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name: "China_Province_R@China400",
attributeFilter: "id=662 or name='河南省'"
});

name 指定查询的图层 

attributeFilter 指定查询的条件,类似于写SQL语句,属性可以根据图层信息查询如下图:

完整实例代码如下:

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SQL 查询</title>
<style type="text/css">
body{
margin: 0;
overflow: hidden;
background: #fff;
}
#map{
position: relative;
height: 520px;
border:1px solid #3473b7;
}
#toolbar{
position: relative;
height: 33px;
padding-top:5;
}
</style>
<script src='../libs/SuperMap.Include.js'></script>
<script type="text/javascript">
var map, local, layer, vectorLayer,
style = {
strokeColor: "#304DBE",
strokeWidth: 1,
fillColor: "#304DBE",
fillOpacity: "0.8"
},
host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host,
url=host+"/iserver/services/map-world/rest/maps/World";
function init(){
map = new SuperMap.Map("map",{controls: [
new SuperMap.Control.LayerSwitcher(),
new SuperMap.Control.ScaleLine(),
new SuperMap.Control.Zoom(),
new SuperMap.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
})]
});
layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
layer.events.on({"layerInitialized":addLayer});
vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
}

function addLayer() {
map.addLayers([layer, vectorLayer]);
map.setCenter(new SuperMap.LonLat(0, 0), 0);
}
function queryBySQL() {
vectorLayer.removeAllFeatures();

var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name: "Countries@World.1",
attributeFilter: "Pop_1994>1000000000 and SmArea>900"
});
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams: [queryParam]
});
queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}});
queryBySQLService.processAsync(queryBySQLParams);
}
function processCompleted(queryEventArgs) {
var i, j, feature,
result = queryEventArgs.result;
if (result && result.recordsets) {
for (i=0; i<result.recordsets.length; i++) {
if (result.recordsets[i].features) {
for (j=0; j<result.recordsets[i].features.length; j++) {
feature = result.recordsets[i].features[j];
feature.style = style;
vectorLayer.addFeatures(feature);
}
}
}
}
}
function processFailed(e) {
alert(e.error.errorMsg);
}
function clearFeatures() {
//先清除上次的显示结果
vectorLayer.removeAllFeatures();
vectorLayer.refresh();
}
</script>
</head>
<body onload="init()">
<div id="toolbar">
<input type="button" value="查询" onclick="queryBySQL()" />
<input type="button" value="清除" onclick="clearFeatures()" />
</div>
<div id="map"></div>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值