var features = [];
for (var i = 0; i < list.length; i++) {
if (list[i].longitude != null && list[i].latitude != null) {
var coord = [list[i].longitude, list[i].latitude];
//创建图标特性
var iconFeature = new mapconfig.ol.Feature({
geometry: new mapconfig.ol.geom.Point(coord, "XY"),
name: list[i].companyName,
guid: list[i].guid
});
//创建图标样式
var iconStyle = new mapconfig.ol.style.Style({
image: new mapconfig.ol.style.Icon({
// opacity: 0.75,
src: blueImg,
// anchor: [0.5, 46],
anchorXUnits: "fraction",
anchorYUnits: "pixels",
opacity: 1
})
});
iconFeature.setStyle(iconStyle);
features.push(iconFeature);
}
}
var vectorSource = new mapconfig.ol.source.Vector({
features: features
});
//创建矢量层
this_.gisGlobal.superLayer = new mapconfig.ol.layer.Vector({
source: vectorSource
});
//添加进map层
this_.gisGlobal.map.addLayer(this_.gisGlobal.superLayer);
this_.gisGlobal.map.on("click", function(e) {
var feature = this_.gisGlobal.map.forEachFeatureAtPixel(
e.pixel,
function(feature) {
return feature;
}
);
if (feature) {
this_.companyTitle = feature.N.name;
this_.qyGuid = feature.N.guid;
this_.noPoint = false;
this_.gisVisible = true;
}
});
/**
* 为map添加鼠标移动事件监听,当指向标注时改变鼠标光标状态
*/
this_.gisGlobal.map.on("pointermove", function(e) {
if (e.dragging) return;
var pixel = this_.gisGlobal.map.getEventPixel(e.originalEvent);
var hit = this_.gisGlobal.map.hasFeatureAtPixel(pixel);
this_.gisGlobal.map.getTargetElement().style.cursor = hit
? "pointer"
: ""; 上边代码执行后是图片效果,正常点击事件应该在图标上,现在是在图标的右侧,底图是iserver发布的地图
});