supermap学习系列(五)——上一篇的续集(鼠标单击或者移动,高亮显示并弹出对话框)
来源:互联网 发布:2017严厉打击网络博客 编辑:程序博客网 时间:2024/05/17 06:11
学习笔记,方便以后查阅。参考超图技术资源中心--代码库:http://support.supermap.com.cn/ProductCenter/ResourceCenter/CodeLibrary.aspx
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="libs/SuperMap.Include.js"></script> <script type="text/javascript"> var style = { strokeColor: "#304DBE", strokeOpacity: 0, fillColor: "#00ff00", fillOpacity: 0, }; var selectStyle = { fillColor: "#FFFFFF", //填充颜色 strokeColor: "#ff0000", //边框颜色 strokeWidth: 3, graphZIndex: 1 }; var map, layer, vectorLayer, selectFeature, popup; // 设置访问的GIS服务地址 var url = "http://localhost:8090/iserver/services/map-ChinaTestWorkPlace/rest/maps/ChinaTest"; function GetMap() { // 创建地图对象 map = new SuperMap.Map("map"); //control = new SuperMap.Control.MousePosition(); //该控件显示鼠标移动时,所在点的地理坐标。 //map.addControl(control); //添加控件 // 创建图层对象 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");
//这里添加两种事件方式点击事件和mouseover事件,都可以实现,这里屏蔽掉mouseover事件。(这里我还存一个问题,在这两种情况下双击地图不能放大,只能用滚轮) // (双击除了要高亮显示的其他区域,还是可以的) //给vectorLayer添加单击事件 selectFeature = new SuperMap.Control.SelectFeature(vectorLayer, { onSelect: onFeatureSelect, onUnselect: onUnFeatureSelect }); selectFeature.repeat = true; selectFeature.toggle = true;
////给vectorLayer添加鼠标mouseover事件 //selectFeature = new SuperMap.Control.SelectFeature(vectorLayer, { // onSelect: onFeatureSelect, // onUnselect: onUnFeatureSelect, // hover: true //}); map.addControl(selectFeature); selectFeature.activate(); } // 加载图层 function addLayer() { // 向Map添加图层 map.addLayers([layer, vectorLayer]); map.setCenter(new SuperMap.LonLat(116.409749, 39.912344), 1); QueryBySQL(); } function QueryBySQL() { var filterParameter, queryBySQLService, queryBySQLParameters; //SuperMap.REST.FilterParameter 查询过滤条件参数类。 该类用于设置查询数据集的查询过滤参数。 filterParameter = new SuperMap.REST.FilterParameter({ name: "Provinces_R@China400" }); //SuperMap.REST.QueryBySQLParameters SQL 查询参数类。 该类用于设置 SQL 查询的相关参数。 queryBySQLParameters = new SuperMap.REST.QueryBySQLParameters({ queryParams: [filterParameter] }); //SuperMap.REST.QueryBySQLService SQL 查询服务类。 在一个或多个指定的图层上查询符合 SQL 条件的空间地物信息。 queryBySQLService = new SuperMap.REST.QueryBySQLService(url, { eventListeners: { "processCompleted": queryCompleted, "processFailed": queryError } }); queryBySQLService.processAsync(queryBySQLParameters); } //查询成功 function queryCompleted(queryEventArgs) { var result = queryEventArgs.result; if (result && result.recordsets[0].features) { features = result.recordsets[0].features; for (var i = 0; i < features.length; i++) { features[i].style = style; } vectorLayer.addFeatures(features); } } function queryError(e) { alert(e.error.errorMsg); } function onUnFeatureSelect(feature) { map.removePopup(feature.popup); feature.popup.destroy(); feature.popup = null;
feature.style = style; vectorLayer.redraw();
} function onFeatureSelect(feature) { feature.style = selectStyle; vectorLayer.redraw(); vectorLayer.setOpacity(0.6);
// 获取点击点的经纬度 var x = feature.geometry.getBounds().getCenterLonLat().lon; var y = feature.geometry.getBounds().getCenterLonLat().lat; var contentHTML = "<div style='font-size:.8em; opacity: 0.8; width:150px; height:50px;'>" + "<span style='font-weight: bold; font-size: 18px;'>详细信息</span><br>"; contentHTML += "<div>所属:" + feature.attributes.NAME + "</div>"; contentHTML += "<div>1994年GDP:" + parseInt(feature.attributes.GDP_1994) + "</div>"; contentHTML += "<div>1997年GDP:" + parseInt(feature.attributes.GDP_1997) + "</div>"; contentHTML += "<div>1998年GDP:" + parseInt(feature.attributes.GDP_1998) + "</div>"; contentHTML += "<div>1999年GDP:" + parseInt(feature.attributes.GDP_1999) + "</div>"; contentHTML += "<div>2000年GDP:" + parseInt(feature.attributes.GDP_2000) + "</div>"; contentHTML += "</div>" popup = new SuperMap.Popup.FramedCloud("chicken", new SuperMap.LonLat(x, y), null, contentHTML, null, true); feature.popup = popup; popup.panMapIfOutOfView = true; map.addPopup(popup);
} </script></head><body onload="GetMap()"> <div id="map" style="height: 640px; width: 720px; border: 1px solid red; margin-left: auto; margin-right: auto;"></div></body></html>
初始效果图:
鼠标单击其中的一个省份:
鼠标移动也是可以的,上面的代码中有说明。
- supermap学习系列(五)——上一篇的续集(鼠标单击或者移动,高亮显示并弹出对话框)
- supermap学习系列(六)——上一篇的另一种版本(鼠标单击或者移动,高亮显示并弹出对话框)
- supermap 学习系列(四)——鼠标到哪里亮哪里(高亮显示)
- supermap 学习系列(二)——添加标注(鼠标点击弹出窗口)
- supermap学习系列(八)——上一篇的另一种实现方式(给要素图层SuperMap.Layer.Vector注册事件)
- supermap 学习系列(三)——在地图上绘制线段(鼠标放在上面时改变其颜色)
- supermap学习系列之silverlight--添加可拖拽的定位图钉(方法二之超图自带类(Pushpin、InfoWindow)) 续 解决上一篇的问题
- C#-—单击按钮可以弹出对话框
- MFC 显示对话框内鼠标单击点的坐标值
- 单击BindingNavigator上的删除按钮时弹出确认对话框
- supermap学习系列(七)——用户自己在地图上添加点、线、面标注
- MFC对话框添加菜单栏并添加鼠标单击响应(实例,包你一学就会)
- c#—devexpress chartcontrol 鼠标点击chart上的点事件,鼠标移动显示值
- js table鼠标移动高亮显示
- 鼠标移动到热点上,显示详细信息(显示数据库的信息)
- 基于对话框显示,动态显示jpg.bmp等图片,并获取鼠标移动的坐标值及rgb值
- 为对话框窗口添加菜单栏并单击弹出对话框
- MFC(对话框鼠标右键弹出菜单)
- struct2 的拦截器
- 海盗分金币的问题
- 越狱检测的攻与防
- win7环境变量
- 二叉堆
- supermap学习系列(五)——上一篇的续集(鼠标单击或者移动,高亮显示并弹出对话框)
- 某文学网站的优化具体方案
- VSFTP 配置
- Scala学习笔记5 (集合 Collections)
- Intel万兆网卡,intel万兆双口网卡X540T2 性能解剖
- 文字熵的简述
- 如何使用HTML5开发实现拍照上传应用
- 标准C++的类型转换符:static cast、dynamic cast、reinterpret cast和const cast
- u盘格式化后如何恢重要的数据