openlayers中利用vector实现marker的方式
项目需要一个小型的gis。openlayers,geoserver,postgres组合是比较好的选择。
openlayers的marker层好像不支持拖动操作。通过研究api发现,可以利用vector层
达到这个目的,作出标注的效果。可以定位,搜索,拖动等效果,选中的时候可以
通过修改style达到动画效果。
基本做法如下:
1:定义marker显示的样式
2:扩展vector层,利用在扩展层上添加point与style,图片显示point就出现标注的
效果
基本代码如下:
定义样式:
- $package("com.bct.map");
- com.bct.map.EncoderMarkerStyle = {
- 'bigEncoder':{
- graphicWidth:,
- graphicHeight : ,
- graphicXOffset : -,
- graphicYOffset : -,
- externalGraphic : "scripts/map/img/channel2.png"
- },
- 'smallEncoder':{
- graphicWidth:,
- graphicHeight : ,
- graphicXOffset : -,
- graphicYOffset : -,
- externalGraphic : "scripts/map/img/channel.gif"
- },
- 'selectStyle':{
- pointerEvents: "visiblePainted",
- border:"border:25 outset #ff88ff",
- cursor: "pointer",
- graphicWidth:,
- graphicHeight : ,
- graphicXOffset : -,
- graphicYOffset : -,
- externalGraphic : "scripts/map/img/channel2.png"
- },
- styleMap: new OpenLayers.StyleMap({
- "select": new OpenLayers.Style({pointRadius: })
- })
- }
- $package("com.bct.map");
- com.bct.map.EncoderMarkerStyle = {
- 'bigEncoder':{
- graphicWidth:24,
- graphicHeight : 24,
- graphicXOffset : -12,
- graphicYOffset : -24,
- externalGraphic : "scripts/map/img/channel2.png"
- },
- 'smallEncoder':{
- graphicWidth:16,
- graphicHeight : 16,
- graphicXOffset : -8,
- graphicYOffset : -16,
- externalGraphic : "scripts/map/img/channel.gif"
- },
- 'selectStyle':{
- pointerEvents: "visiblePainted",
- border:"border:25 outset #ff88ff",
- cursor: "pointer",
- graphicWidth:24,
- graphicHeight : 24,
- graphicXOffset : -12,
- graphicYOffset : -24,
- externalGraphic : "scripts/map/img/channel2.png"
- },
- styleMap: new OpenLayers.StyleMap({
- "select": new OpenLayers.Style({pointRadius: 24})
- })
- }
2:扩展向量层
- $package("com.bct.map");
- $import("com.bct.map.EncoderMarkerStyle");
- com.bct.map.MarkerVectorLayer = OpenLayers.Class(OpenLayers.Layer.Vector,{
- /**
- * parameters
- * attribute filer对象
- */
- getFeatureByAttribute :function(attributes){
- var feature = null;
- for(var i=;i<this.features.length; ++i){
- var attri = this.features[i].attributes;
- var find = false;
- for(var j in attributes){
- if(attributes[j] == attri[j]){
- find = true;
- }
- }
- if(find){
- return this.features[i];
- }
- }
- },
- //添加Feature,是point显示为图片
- addEncorderFeature:function(encNode,location){
- if(encNode&&this.repetitiveCheck(encNode.id)){
- return;
- }
- var attributes = OpenLayers.Util.extend({}, encNode.attributes);
- var enc_point = new OpenLayers.Geometry.Point(location.lon,location.lat);
- var enc_Feature = new OpenLayers.Feature.Vector(enc_point,attributes,com.bct.map.EncoderMarkerStyle['smallEncoder']);
- this.addFeatures([enc_Feature]);
- if(encNode.attributes['lon']&&encNode.attributes['lat']&&encNode.attributes['lon'].length>){
- return;
- }
- this.updateChannel(encNode.id,location.lon,location.lat);
- },
- repetitiveCheck:function(entity_id){
- if(this.getFeatureByAttribute({id:entity_id})){
- return true;
- }
- return false;
- },
- updateChannel:function(channel_id,lon,lat){
- Ext.Ajax.request({
- url: 'deviceVideoEncoder.do?method=updateLonlat&id='+channel_id+"&lon="+lon+"&lat="+lat
- });
- },
- channelMarkerClick:function() {
- var features = this.selectedFeatures;
- if(features.length >=&&features[]) {
- feature = features[];
- var treeNodeAttribute = feature.attributes;
- //显示信息
- }
- },
- cartoonFeature :function(feature){
- this.drawFeature(feature,com.bct.map.EncoderMarkerStyle['bigEncoder']);
- var runner = new Ext.util.TaskRunner();
- var task = {
- run:this.drawFeature,
- scope:this,
- args:[feature,com.bct.map.EncoderMarkerStyle['smallEncoder']],
- interval:
- }
- runner.start(task);
- },
- removeSelectFeature:function(){
- var features = this.selectedFeatures;
- for(var i=features.length-; i>=; i--) {
- feature = features[i];
- this.updateChannel(feature.attributes['id'],"","");
- }
- this.destroyFeatures(this.selectedFeatures);
- },
- monitorSelectFeature:function(){
- var features = this.selectedFeatures;
- if(features.length >=&&features[]) {
- feature = features[];
- var treeNodeAttribute = feature.attributes;
- var objId="mapAVShow"+treeNodeAttribute['id'];
- //弹出窗口
- }
- }
- });
- $package("com.bct.map");
- $import("com.bct.map.EncoderMarkerStyle");
- com.bct.map.MarkerVectorLayer = OpenLayers.Class(OpenLayers.Layer.Vector,{
- /**
- * parameters
- * attribute filer对象
- */
- getFeatureByAttribute :function(attributes){
- var feature = null;
- for(var i=0;i<this.features.length; ++i){
- var attri = this.features[i].attributes;
- var find = false;
- for(var j in attributes){
- if(attributes[j] == attri[j]){
- find = true;
- }
- }
- if(find){
- return this.features[i];
- }
- }
- },
- //添加Feature,是point显示为图片
- addEncorderFeature:function(encNode,location){
- if(encNode&&this.repetitiveCheck(encNode.id)){
- return;
- }
- var attributes = OpenLayers.Util.extend({}, encNode.attributes);
- var enc_point = new OpenLayers.Geometry.Point(location.lon,location.lat);
- var enc_Feature = new OpenLayers.Feature.Vector(enc_point,attributes,com.bct.map.EncoderMarkerStyle['smallEncoder']);
- this.addFeatures([enc_Feature]);
- if(encNode.attributes['lon']&&encNode.attributes['lat']&&encNode.attributes['lon'].length>0){
- return;
- }
- this.updateChannel(encNode.id,location.lon,location.lat);
- },
- repetitiveCheck:function(entity_id){
- if(this.getFeatureByAttribute({id:entity_id})){
- return true;
- }
- return false;
- },
- updateChannel:function(channel_id,lon,lat){
- Ext.Ajax.request({
- url: 'deviceVideoEncoder.do?method=updateLonlat&id='+channel_id+"&lon="+lon+"&lat="+lat
- });
- },
- channelMarkerClick:function() {
- var features = this.selectedFeatures;
- if(features.length >=0&&features[0]) {
- feature = features[0];
- var treeNodeAttribute = feature.attributes;
- //显示信息
- }
- },
- cartoonFeature :function(feature){
- this.drawFeature(feature,com.bct.map.EncoderMarkerStyle['bigEncoder']);
- var runner = new Ext.util.TaskRunner(1000);
- var task = {
- run:this.drawFeature,
- scope:this,
- args:[feature,com.bct.map.EncoderMarkerStyle['smallEncoder']],
- interval: 1000
- }
- runner.start(task);
- },
- removeSelectFeature:function(){
- var features = this.selectedFeatures;
- for(var i=features.length-1; i>=0; i--) {
- feature = features[i];
- this.updateChannel(feature.attributes['id'],"","");
- }
- this.destroyFeatures(this.selectedFeatures);
- },
- monitorSelectFeature:function(){
- var features = this.selectedFeatures;
- if(features.length >=0&&features[0]) {
- feature = features[0];
- var treeNodeAttribute = feature.attributes;
- var objId="mapAVShow"+treeNodeAttribute['id'];
- //弹出窗口
- }
- }
- });
addEncorderFeature是添加一个标注的地方。
利用这种方式,比原有的marker层拥有更多的功能
openlayers中利用vector实现marker的方式的更多相关文章
- 在JAVA中利用public static final的组合方式对常量进行标识
在JAVA中利用public static final的组合方式对常量进行标识(固定格式). 对于在构造方法中利用final进行赋值的时候,此时在构造之前系统设置的默认值相对于构造方法失效. 常量(这 ...
- python中利用matplotlib绘图可视化知识归纳
python中利用matplotlib绘图可视化知识归纳: (1)matplotlib图标正常显示中文 import matplotlib.pyplot as plt plt.rcParams['fo ...
- 从0开始:Windows内核利用的另一种方式
https://www.anquanke.com/post/id/91063 从0开始:Windows内核利用的另一种方式 阅读量 9168 | 稿费 200 分享到: 发布时间:201 ...
- Hadoop 中利用 mapreduce 读写 mysql 数据
Hadoop 中利用 mapreduce 读写 mysql 数据 有时候我们在项目中会遇到输入结果集很大,但是输出结果很小,比如一些 pv.uv 数据,然后为了实时查询的需求,或者一些 OLAP ...
- Oracle中“行转列”的实现方式
在报表的开发当中,难免会遇到行转列的问题. 以Oracle中scott的emp为例,统计各职位的人员在各部门的人数分布情况,就可以用“行转列”: scott的emp的原始数据为: EMPNO ENAM ...
- iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】
在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...
- ArcGIS中利用ArcMap将地理坐标系转换成投影坐标系(从WKID=4326到WKID=102100)
原文:ArcGIS中利用ArcMap将地理坐标系转换成投影坐标系(从WKID=4326到WKID=102100) 对于非地理专业的开发人员,对与这些生涩的概念,我们不一定都要了解,但是我们要理解,凡是 ...
- .NET中的三种接口实现方式
摘自:http://www.cnblogs.com/zhangronghua/archive/2009/11/25/1610713.html 一般来说.NET提供了三种不同的接口实现方式,分别为隐式接 ...
- JAVA中集合输出的四种方式
在JAVA中Collection输出有四种方式,分别如下: 一) Iterator输出. 该方式适用于Collection的所有子类. public class Hello { public stat ...
随机推荐
- 嵌入式开发值zynq驱动—— zynq SPI Flash 驱动过程
http://blog.csdn.net/pengwangguo/article/details/52292664 http://blog.csdn.net/pengwangguo/article/d ...
- Maven最佳实践-distributionManagement
分发构件至远程仓库 mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库.本地Maven仓库的构件只能供当前用户使用, ...
- .NET条形码
建议不要用CODE-39码,改用CODE-128码: CODE-39码密度比较低,条码数字内容太多,导致条码太长,缩短长度就只能减小X尺寸,造成识读困难: CODE-128码密度高,相同的数字生成条码 ...
- Deep Voice
https://arxiv.org/abs/1702.07825 听起来和真人声非常接近了.
- Maven 与 IntelliJ IDEA 的完美结合
你是否正在学习Maven?是否因为Maven难用而又不得不用而苦恼?是否对Eclipse于Maven的冲突而困惑? 那么我告诉你一个更直接更简单的解决方案: IntelliJ IDEA! 1. 什么是 ...
- Java高级面试题及答案
List和Set比较,各自的子类比较 对比一:Arraylist与LinkedList的比较 1.ArrayList是实现了基于动态数组的数据结构,因为地址连续,一旦数据存储好了,查询操作效率会比较高 ...
- linux系统负载
系统负载System Load:系统CPU繁忙程度的度量,即有多少进程在等待被CPU调度 平均负载(Load Average):一段时间内系统的平均负载,这个一段时间一般取1分钟.5分钟.15分钟 查 ...
- flashfxp v3.7 注册码
-------- FlashFXP Registration Data START --------FLASHFXPvwBW1S4QvwAAAAC5W5MNJwXnsl73i3CxcVAAvAyagF ...
- Centos修改时间显示的时区,将UTC修改为CST
问题说明: 今天一同事反应,系统的时间不对和正常的时间差8个小时.就登录主机看了下时间 系统时间显示为: # date Fri Dec :: UTC # 备注:查看了下,正好和当前的时间差了8个小时. ...
- Python 常用类库
python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的. 常用的libraries(modules)如下: 1 ...