openlayers 渲染wkt数据,标记中心值并弹窗
2015-07-20 15:44
274 查看
function drawFatureSelectRow(vwkt,vl,name,phone,address){ var feature = new OpenLayers.Format.WKT().read(vwkt); var gml = new OpenLayers.Format.GML(); var style = { strokeColor: "blue", strokeWidth: 1, pointerEvents: "visiblePainted", fillColor: "red", fillOpacity: 0.5 }; feature.style=style; var geo = feature.geometry; /* <span style="color:#ff0000;">var bo = geo.getBounds(); var latlon=bo.getCenterLonLat()</span>; 可以获得中心点,但如果是不规则线面状数据,中心点会偏移到不在图象上*/ var vlistv=geo.getVertices(); var latlon; if(vlistv.length>1){ var vmid; if(vlistv.length%2==0){ vmid=vlistv.length/2 }else{ vmid=(vlistv.length+1)/2; } alert(vmid); latlon=vlistv[vmid]; }else{ latlon= geo.getVertices()[0]; } var lat = latlon.y; var lon = latlon.x; vectorLayer.addFeatures([feature]); locatebylonlatSelectRow(lon,lat,name,phone,address); map.moveTo([lon, lat], vl, new Object()); } function locatebylonlatSelectRow(lon,lat,name,phone,address){ var AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { 'autoSize': true, 'maxSize': new OpenLayers.Size(280, 270) }); var feature = new OpenLayers.Format.WKT().read("POINT(" + lon + " " + lat + ")"); var point = feature.geometry.getCentroid(); var lonlat = new OpenLayers.LonLat(point.x, point.y); var popupClass = AutoSizeFramedCloud; var popupContentHTML = "<label>名称: </label>" + name + "<br/>" + "<label>电话: </label>" + phone+ "<label>地址: </label>" + address; if(address==="rode"){ popupContentHTML= "<label>名称: </label>" + name ; } addMarkerForLocate(lonlat, popupClass, popupContentHTML, true, true); } //弹窗 function addMarkerForLocate(ll, popupClass, popupContentHTML, closeBox, overflow) { var feature = new OpenLayers.Feature(markerLayer, ll); feature.closeBox = closeBox; feature.popupClass = popupClass; feature.data.popupContentHTML = popupContentHTML; feature.data.overflow = (overflow) ? "auto" : "hidden"; var marker = feature.createMarker(); var markerClick = function(evt) { if (this.popup == null) { this.popup = this.createPopup(this.closeBox); map.addPopup(this.popup); this.popup.show(); } else { this.popup.toggle(); } currentPopup = this.popup; OpenLayers.Event.stop(evt); }; marker.events.register("mousedown", feature, markerClick); markerLayer.addMarker(marker); }
相关文章推荐
- # 2.1 linux文件系统dup/dup2重定向应用实例
- openssl 自签发证书及ssl 原理简介(一)
- POJ 3258 River Hopscotch
- linux下给php安装curl、gd(ubuntu)
- Linux下利用backtrace追踪函数调用堆栈以及定位段错误
- linux Composer 安装
- Apache 安装过程中 Cannot use an external APR with the bundled APR-util 错误
- Fly-By Topology
- 每天一个linux命令(37):date命令
- SQL Server中的高可用性---概念
- CentOS6.5下编译安装LAMP环境
- Linux下源码包安装Apache+Mysql+Php
- 如何把xshell的session配置文件拷贝到别的机器上
- JFinal使用笔记1-部署demo项目到本地tomcat
- linux vim 常用操作
- CentOS(四)--Weblogic建域
- linux 常用命令学习
- Linux下Socket编程
- linux .sh脚本中的一些常用命令
- backtrace&&backtrace_symbols 查找段错误 打印堆栈信息