关于openlayers显示点的问题

aubreycanfly 2017-03-23 11:59:52
我从数据库获取到一个json数组,想要把里面点显示在图层上。数组获取没问题,alert过 geolongitude和 geolatitude也都存在
lbpoint定义过了是“保护站点”,就是显示不了,显示了一个坐标不知道哪来的点


$.ajax({
type : "GET",//请求方式
async : false,
url : "../services/"+options.datatype+"/"+options.method+"=" + options.lb,
data : "json",//数据类型text xml json script jsonp
success : function(msg) {//返回的参数就是 action里面所有的有get和set方法的参数

$(msg).each(function (i, val) {
val.img=options.img;
});
that.loaddata2dpoint(msg);
//that.loaddata3d(msg);
}
});


MapBztc.prototype.loaddata2dpoint = function (result) {
var that = this;
that.id=pointlb;
var customStyleFunction = function (feature, resolution) {
// 根据空气级别,设定不同颜色
var img="";
var mc="";
if(feature.data) {
img='images/menu/u1271small.png';/*+feature.data.img*/
//alert(img)
}else{
img='images/menu/u1271small.png';
}
if(feature.data) {
mc=feature.data.descript;
}else{
mc="";
}
//
//console.info(feature.data);
var fontSize = '14';
var styleimg = new ol.style.Style({
fill: new ol.style.Fill({ //矢量图层填充颜色,以及透明度
color: 'rgba(231, 216, 0, 0.5)'
}),
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
}),image: new ol.style.Icon({
src: img
}),

});
var styletext = new ol.style.Style({
text: new ol.style.Text({
textAlign: "center",
textBaseline: "middle",
font: '14px Normal Arial',
text: mc, //that.mapoptions.key + feature.get('features')[0].data[that.mapoptions.value] + that.mapoptions.unit,//,// //feature.data.station,
fill: new ol.style.Fill({
color: "#00E400",////
}),
stroke: new ol.style.Stroke({
color: '#000000',
width: 1
}),

offsetX: 0,
offsetY: 20,
rotation: 0
})
});
style = [styleimg, styletext];
// console.info(style);
return style;
};
//console.info(result);
$(result).each(function (i, val) {
//判断类型,开始添加元素
var geolatitude= val.latitude;
var geolongitude= val.longitude;
var geom;

//alert("1")
geom = new ol.geom.Point([parseFloat(geolatitude),parseFloat(geolongitude)]);
feature = new ol.Feature(geom);
feature.data = val;
feature.layerid = that.id;
// feature.setStyle(iconStyle);
that.ol2dlist[that.id] = feature;

});
// Source and vector layer
//console.info(that.ol2dlist);
var vectorSource = new ol.source.Vector({
features: _.values(that.ol2dlist)
});
var tmpLayer = that.ol2d.getLayerById(that.id);
if (tmpLayer == null) {
alert("1")
tmpLayer = new ol.layer.Vector({
id: that.id,
opacity: 0.95,
maxzoom: 1224,
minzoom: 0.0001,
source: vectorSource,
style: customStyleFunction
});
console.info(that.ol2dlist)
console.info(tmpLayer)
that.ol2d.olmap.addLayer(tmpLayer);
} else {
alert("2")
tmpLayer.setSource(null);
tmpLayer.setStyle(customStyleFunction);
tmpLayer.setSource(vectorSource);
}
}
...全文
564 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈哈gogo 2019-09-26
  • 打赏
  • 举报
回复
thfn t怎么设置大小呢
CooperForever 2017-03-30
  • 打赏
  • 举报
回复
if(feature.data) { img='images/menu/u1271small.png';/*+feature.data.img*/ //alert(img) }else{ img='images/menu/u1271small.png'; }
请问在openlayers中如何删除Layer中的marker 3 在层中加了一个标记怎么永久的存到地图上 3 OpenLayers 如何设死地图边界 3 谁写过openlayers解析xml 3 openlayer.popup 3 OpenLayers 怎么做字段标注 4 字段标注不是用OL做的,而是你在SLD中定义用数据表的哪个字段做标签就可以了 4 OpenLayers 中画最短轨迹 4 使用TileCache配合OpenLayers 4 openlayers如何准确测距 9 openlayers简单实用例子 9 关于TileCache函数 13 openlayers 有函数说明的类图 14 go 14 Maker 一多,客户端就死掉 15 OpenLayers 怎么实现 AJAX 16 openlayer 要怎么研究才会应用得比较自如 16 改良OpenLayers的Popup 16 在openlayers的地图中要添加地图搜索功能一般采用什么方法 17 openlayers中如何访问geoserver发布的图片 18 什么是TMS? 18 怎样设置瓦片的大小 18 画一条线,数据量太大,怎么办? 18 怎么在图层上动态画 20 GeoExt集成google map ,地图偏移 21 用JavaScript为OpenLayers.Marker的加上单击显示详细信息的功能 21 改良OpenLayers的MousePostion 25 使用OpenLayers实现一个在鼠标击处添加标记的效果 27 openlayers 利用google maps的卫星地图 29 openLayers集成google map ,标注错位 30 openlayers可以做出谷歌效果的地图吗? 31 用OpenLayers API和类来画、线、面 32 OGC标准术语介绍WMS、WFS、WCS 35 如何控制地图的放缩 37 openLayers链接WMS的代码探讨 37 openlayers 2.5 矢量层在ie下闪烁的问题 38 openLayers 在地图上添加一个并保存 39 openLayers 各个参数的意义 42 geoserver能搞出这种风格的图来吗? 43 关于SLD的线切割后的设置 43 GEOSERVE 标注铁路,使用 SLD 44 geoserver 发布.shp 中文乱码问题 怎么解决啊 45 Geoserver怎么连postGreSql 数据库 48 Geoserver连Oracle Spatial 52 GeoServer架构浅谈 53 Geoserver发布地图无法显示问题 57 WebGIS相关的OpenGIS规范 58 geoserver中地图以外的区域以自定义图片填充 62 怎样修改 geoServer 的用户名密码 65 GeoServer中的WMS服务生成的png图片背景色为透明 65 比例尺 65 需不需要一个layer对应一个store 66 如何部署shp 66 用GeoWebCache后Marker错位 66 标签太大导致不能显示? 67 geoserver把两个shapefile格式的图叠 67 GeoServer 能够集成 Google Map? 68 gwc地图切片的缓存路径在web.xml中设置么 68 如何实现地图查询? 68 sld文件怎么用 69 在sld中怎么控制路名的间隔? 69

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧