项目需要一个小型的gis。openlayers,geoserver,postgres组合是比较好的选择。
openlayers的marker层好像不支持拖动操作。通过研究api发现,可以利用vector层
达到这个目的,作出标注的效果。可以定位,搜索,拖动等效果,选中的时候可以
通过修改style达到动画效果。
基本做法如下:
1:定义marker显示的样式
2:扩展vector层,利用在扩展层上添加point与style,图片显示point就出现标注的
   效果
基本代码如下:
定义样式:

  1. $package("com.bct.map");
  2. com.bct.map.EncoderMarkerStyle = {
  3. 'bigEncoder':{
  4. graphicWidth:,
  5. graphicHeight : ,
  6. graphicXOffset : -,
  7. graphicYOffset : -,
  8. externalGraphic : "scripts/map/img/channel2.png"
  9. },
  10. 'smallEncoder':{
  11. graphicWidth:,
  12. graphicHeight : ,
  13. graphicXOffset : -,
  14. graphicYOffset : -,
  15. externalGraphic : "scripts/map/img/channel.gif"
  16. },
  17. 'selectStyle':{
  18. pointerEvents: "visiblePainted",
  19. border:"border:25 outset #ff88ff",
  20. cursor: "pointer",
  21. graphicWidth:,
  22. graphicHeight : ,
  23. graphicXOffset : -,
  24. graphicYOffset : -,
  25. externalGraphic : "scripts/map/img/channel2.png"
  26. },
  27. styleMap: new OpenLayers.StyleMap({
  28. "select": new OpenLayers.Style({pointRadius: })
  29. })
  30. }
  1. $package("com.bct.map");
  2. com.bct.map.EncoderMarkerStyle = {
  3. 'bigEncoder':{
  4. graphicWidth:24,
  5. graphicHeight : 24,
  6. graphicXOffset : -12,
  7. graphicYOffset : -24,
  8. externalGraphic : "scripts/map/img/channel2.png"
  9. },
  10. 'smallEncoder':{
  11. graphicWidth:16,
  12. graphicHeight : 16,
  13. graphicXOffset : -8,
  14. graphicYOffset : -16,
  15. externalGraphic : "scripts/map/img/channel.gif"
  16. },
  17. 'selectStyle':{
  18. pointerEvents: "visiblePainted",
  19. border:"border:25 outset #ff88ff",
  20. cursor: "pointer",
  21. graphicWidth:24,
  22. graphicHeight : 24,
  23. graphicXOffset : -12,
  24. graphicYOffset : -24,
  25. externalGraphic : "scripts/map/img/channel2.png"
  26. },
  27. styleMap: new OpenLayers.StyleMap({
  28. "select": new OpenLayers.Style({pointRadius: 24})
  29. })
  30. }

2:扩展向量层

  1. $package("com.bct.map");
  2. $import("com.bct.map.EncoderMarkerStyle");
  3. com.bct.map.MarkerVectorLayer = OpenLayers.Class(OpenLayers.Layer.Vector,{
  4. /**
  5. * parameters
  6. * attribute filer对象
  7. */
  8. getFeatureByAttribute :function(attributes){
  9. var feature = null;
  10. for(var i=;i<this.features.length; ++i){
  11. var attri = this.features[i].attributes;
  12. var find = false;
  13. for(var j in attributes){
  14. if(attributes[j] == attri[j]){
  15. find = true;
  16. }
  17. }
  18. if(find){
  19. return this.features[i];
  20. }
  21. }
  22. },
  23. //添加Feature,是point显示为图片
  24. addEncorderFeature:function(encNode,location){
  25. if(encNode&&this.repetitiveCheck(encNode.id)){
  26. return;
  27. }
  28. var attributes = OpenLayers.Util.extend({}, encNode.attributes);
  29. var enc_point = new OpenLayers.Geometry.Point(location.lon,location.lat);
  30. var enc_Feature = new OpenLayers.Feature.Vector(enc_point,attributes,com.bct.map.EncoderMarkerStyle['smallEncoder']);
  31. this.addFeatures([enc_Feature]);
  32. if(encNode.attributes['lon']&&encNode.attributes['lat']&&encNode.attributes['lon'].length>){
  33. return;
  34. }
  35. this.updateChannel(encNode.id,location.lon,location.lat);
  36. },
  37. repetitiveCheck:function(entity_id){
  38. if(this.getFeatureByAttribute({id:entity_id})){
  39. return true;
  40. }
  41. return false;
  42. },
  43. updateChannel:function(channel_id,lon,lat){
  44. Ext.Ajax.request({
  45. url: 'deviceVideoEncoder.do?method=updateLonlat&id='+channel_id+"&lon="+lon+"&lat="+lat
  46. });
  47. },
  48. channelMarkerClick:function() {
  49. var features = this.selectedFeatures;
  50. if(features.length >=&&features[]) {
  51. feature = features[];
  52. var treeNodeAttribute = feature.attributes;
  53. //显示信息
  54. }
  55. },
  56. cartoonFeature :function(feature){
  57. this.drawFeature(feature,com.bct.map.EncoderMarkerStyle['bigEncoder']);
  58. var runner = new Ext.util.TaskRunner();
  59. var task = {
  60. run:this.drawFeature,
  61. scope:this,
  62. args:[feature,com.bct.map.EncoderMarkerStyle['smallEncoder']],
  63. interval:
  64. }
  65. runner.start(task);
  66. },
  67. removeSelectFeature:function(){
  68. var features = this.selectedFeatures;
  69. for(var i=features.length-; i>=; i--) {
  70. feature = features[i];
  71. this.updateChannel(feature.attributes['id'],"","");
  72. }
  73. this.destroyFeatures(this.selectedFeatures);
  74. },
  75. monitorSelectFeature:function(){
  76. var features = this.selectedFeatures;
  77. if(features.length >=&&features[]) {
  78. feature = features[];
  79. var treeNodeAttribute = feature.attributes;
  80. var objId="mapAVShow"+treeNodeAttribute['id'];
  81. //弹出窗口
  82. }
  83. }
  84. });
  1. $package("com.bct.map");
  2. $import("com.bct.map.EncoderMarkerStyle");
  3. com.bct.map.MarkerVectorLayer = OpenLayers.Class(OpenLayers.Layer.Vector,{
  4. /**
  5. * parameters
  6. * attribute filer对象
  7. */
  8. getFeatureByAttribute :function(attributes){
  9. var feature = null;
  10. for(var i=0;i<this.features.length; ++i){
  11. var attri = this.features[i].attributes;
  12. var find = false;
  13. for(var j in attributes){
  14. if(attributes[j] == attri[j]){
  15. find = true;
  16. }
  17. }
  18. if(find){
  19. return this.features[i];
  20. }
  21. }
  22. },
  23. //添加Feature,是point显示为图片
  24. addEncorderFeature:function(encNode,location){
  25. if(encNode&&this.repetitiveCheck(encNode.id)){
  26. return;
  27. }
  28. var attributes = OpenLayers.Util.extend({}, encNode.attributes);
  29. var enc_point = new OpenLayers.Geometry.Point(location.lon,location.lat);
  30. var enc_Feature = new OpenLayers.Feature.Vector(enc_point,attributes,com.bct.map.EncoderMarkerStyle['smallEncoder']);
  31. this.addFeatures([enc_Feature]);
  32. if(encNode.attributes['lon']&&encNode.attributes['lat']&&encNode.attributes['lon'].length>0){
  33. return;
  34. }
  35. this.updateChannel(encNode.id,location.lon,location.lat);
  36. },
  37. repetitiveCheck:function(entity_id){
  38. if(this.getFeatureByAttribute({id:entity_id})){
  39. return true;
  40. }
  41. return false;
  42. },
  43. updateChannel:function(channel_id,lon,lat){
  44. Ext.Ajax.request({
  45. url: 'deviceVideoEncoder.do?method=updateLonlat&id='+channel_id+"&lon="+lon+"&lat="+lat
  46. });
  47. },
  48. channelMarkerClick:function() {
  49. var features = this.selectedFeatures;
  50. if(features.length >=0&&features[0]) {
  51. feature = features[0];
  52. var treeNodeAttribute = feature.attributes;
  53. //显示信息
  54. }
  55. },
  56. cartoonFeature :function(feature){
  57. this.drawFeature(feature,com.bct.map.EncoderMarkerStyle['bigEncoder']);
  58. var runner = new Ext.util.TaskRunner(1000);
  59. var task = {
  60. run:this.drawFeature,
  61. scope:this,
  62. args:[feature,com.bct.map.EncoderMarkerStyle['smallEncoder']],
  63. interval: 1000
  64. }
  65. runner.start(task);
  66. },
  67. removeSelectFeature:function(){
  68. var features = this.selectedFeatures;
  69. for(var i=features.length-1; i>=0; i--) {
  70. feature = features[i];
  71. this.updateChannel(feature.attributes['id'],"","");
  72. }
  73. this.destroyFeatures(this.selectedFeatures);
  74. },
  75. monitorSelectFeature:function(){
  76. var features = this.selectedFeatures;
  77. if(features.length >=0&&features[0]) {
  78. feature = features[0];
  79. var treeNodeAttribute = feature.attributes;
  80. var objId="mapAVShow"+treeNodeAttribute['id'];
  81. //弹出窗口
  82. }
  83. }
  84. });

addEncorderFeature是添加一个标注的地方。
利用这种方式,比原有的marker层拥有更多的功能

openlayers中利用vector实现marker的方式的更多相关文章

  1. 在JAVA中利用public static final的组合方式对常量进行标识

    在JAVA中利用public static final的组合方式对常量进行标识(固定格式). 对于在构造方法中利用final进行赋值的时候,此时在构造之前系统设置的默认值相对于构造方法失效. 常量(这 ...

  2. python中利用matplotlib绘图可视化知识归纳

    python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...

  3. 从0开始:Windows内核利用的另一种方式

    https://www.anquanke.com/post/id/91063 从0开始:Windows内核利用的另一种方式 阅读量    9168 |   稿费 200   分享到: 发布时间:201 ...

  4. Hadoop 中利用 mapreduce 读写 mysql 数据

    Hadoop 中利用 mapreduce 读写 mysql 数据   有时候我们在项目中会遇到输入结果集很大,但是输出结果很小,比如一些 pv.uv 数据,然后为了实时查询的需求,或者一些 OLAP ...

  5. Oracle中“行转列”的实现方式

    在报表的开发当中,难免会遇到行转列的问题. 以Oracle中scott的emp为例,统计各职位的人员在各部门的人数分布情况,就可以用“行转列”: scott的emp的原始数据为: EMPNO ENAM ...

  6. iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】

                   在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...

  7. ArcGIS中利用ArcMap将地理坐标系转换成投影坐标系(从WKID=4326到WKID=102100)

    原文:ArcGIS中利用ArcMap将地理坐标系转换成投影坐标系(从WKID=4326到WKID=102100) 对于非地理专业的开发人员,对与这些生涩的概念,我们不一定都要了解,但是我们要理解,凡是 ...

  8. .NET中的三种接口实现方式

    摘自:http://www.cnblogs.com/zhangronghua/archive/2009/11/25/1610713.html 一般来说.NET提供了三种不同的接口实现方式,分别为隐式接 ...

  9. JAVA中集合输出的四种方式

    在JAVA中Collection输出有四种方式,分别如下: 一) Iterator输出. 该方式适用于Collection的所有子类. public class Hello { public stat ...

随机推荐

  1. SciTE配置信息

    超强文本编辑器SciTE配置方法详细实例 转载 2006年12月28日 17:07:00 标签: 文本编辑 / 文档 / 语言 / html / python / api 32800 关于scite文 ...

  2. Python——eventlet.wsgi

    eventlet 的 wsgi 模块提供了一种启动事件驱动的WSGI服务器的简洁手段,可以将其作为某个应用的嵌入web服务器,或作为成熟的web服务器,一个这样的web服务器的例子就是 Spawnin ...

  3. 回想sql语句中的各种连接

    1. 内连接(Inner Join) 内连接是最常见的一种连接,它页被称为普通连接,而E.FCodd最早称之为自然连接. 以下是ANSI SQL-92标准 select * from    t_ins ...

  4. Obj格式模型 读取

    OBJ文件的结构 在一个OBJ文件中,首先有一些以v.vt或vn前缀开头的行指定了所有的顶点.纹理坐标.法线的坐标.然后再由一些以f开头的行指定每一个三角形所对应的顶点.纹理坐标和法线的索引.在顶点. ...

  5. unity3d 获取游戏对象详解

    原文地址:http://www.xuanyusong.com/archives/2768 我觉得Unity里面的Transform 和 GameObject就像两个双胞胎兄弟一样,这俩哥们很要好,我能 ...

  6. c fopen fread 错误

    真的被,读取一个txt文本,结果一个早上都没搞好 程序如下: 能看出哪里有问题么,输出字符串,得到的结果后面有“屯”或则 “烫”,单个字符输出来也有,为何,搜啊搜,改txt的内容,依旧不行 最后 改f ...

  7. SOAP消息头的处理

    SOAP消息头的处理 WebService学习总结(四)——调用第三方提供的webService服务 SOAP中 RPC/ENC 为啥被抛弃

  8. UNIX环境编程学习笔记(23)——信号处理初步学习

    lienhua342014-10-29 1 信号的概念 维基百科中关于信号的描述是这样的: 在计算机科学中,信号(英语:Signals)是 Unix.类 Unix 以及其他 POSIX 兼容的操作系统 ...

  9. asp.net mvc maproute定义可变数量的自定义片断变量

    有时候我们定义了如{controller}/{action}/{id}之类的路由规则,但是后面还可能跟上一堆可能会有可能不会有,但是路由规则是一样的,如{controller}/{action}/{i ...

  10. 页面加载中jquery逐渐消失效果实现

    为了获得更好的用户体验,现在大多数网页都会在页面中加一个加载中效果,这里实现一个加载中逐渐消失的效果,以至于看上去不那么生硬. html: <div id="loading" ...