<script type="text/javascript">
// 定义地图变量
var map,layer,selectFeature,vectorLayer,vectorLayer2,queryParam, queryBySQLParams, queryBySQLService;
var url = "${mapUrl}/iserver/services/map-bhdt/rest/maps/bh";
style = {
strokeColor: "#FFDAB9",
strokeWidth: 2,
pointerEvents: "visiblePainted",
fillColor: "#FFDAB9",
fillOpacity: 0.9 // 填充透明度
};
//定义地图
// function init() {
// }
function addLayer() {
//将Layer图层加载到Map对象上
map.addLayers([layer,vectorLayer]);
//出图,map.setCenter函数显示地图
map.setCenter(new SuperMap.LonLat(12951739.74, 4863339.02), 0);
// vectorLayer2 = new SuperMap.Layer.Vector("高亮显示图层");
// vectorLayer2.displayInLayerSwitcher = false;
// map.minZoom = 0;
queryBySQL();
}
//sql查询
function queryBySQL(){
queryParam = new SuperMap.REST.FilterParameter({
name: "bh_sxt@北航",
attributeFilter: "SMID>0"
});
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams: [queryParam]
});
queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
eventListeners: {"processCompleted": processCompleted}});
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);
}
}
}
}
}
}
</script>
<script>
$(document).ready(function() {
// init();
map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Navigation({ // 此控件处理伴随鼠标事件(拖拽,双击、鼠标滚轮缩放)的地图浏览, 如果创建地图时没有设置任何控件,此控件会默认添加到地图。
dragPanOptions: {
enableKinetic: false // 拖拽动画
}
}),
], allOverlays: true,
});
layer = new SuperMap.Layer.TiledDynamicRESTLayer("bh", url,
null, {maxResolution: "auto"});
layer.events.on({"layerInitialized": addLayer});
// 定义图层
vectorLayer = new SuperMap.Layer.Vector("要素选择图层");
// // 是否需要在图层管理器中显示(默认为false)
// vectorLayer.displayInLayerSwitcher = false;
// //将初始化查询结果的透明度设置为0
// vectorLayer.setOpacity(0);
var callbacks = {
over: function(currentFeature){
// vectorLayer2.removeAllFeatures();
//
// var f = new SuperMap.Feature.Vector;
// f.geometry = currentFeature.geometry.clone();
// f.style= style;
// vectorLayer2.addFeatures(f);
},
out: function(currentFeature){
},
click: function(currentFeature){
alert("hello")
}
};
selectFeature = new SuperMap.Control.SelectFeature(vectorLayer,
{hover: false, callbacks: callbacks});
map.addControl(selectFeature);
selectFeature.activate();
});
</script>