个人做网站需要学什么只是,优秀的国外设计网站,柯桥建设集团网站,seo网站关键词优化价格上次是在地图上打点 这次鼠标移动在图标上面显示相关的信息 首先有两个事件 鼠标移入 和 鼠标移出事件 pointermove pointerout
鼠标放上去之前 放上去后 代码如下
templatediv classcontainerdiv idvue-openlayers classtemplatediv classcontainerdiv idvue-openlayers classmap-x/divdividinfo-boxclassinfo-boxstylewidth: 100px; height: 100px/divdiv idcanv stylewidth: 100px; height: 100px/div/div
/template
script
import ol/ol.css;
import { Map, View, style, Feature, geom, Overlay } from ol;
import TileLayer from ol/layer/Tile;
import XYZ from ol/source/XYZ;
import { Vector as VectorSource } from ol/source;
import VectorLayer from ol/layer/Vector;
import { Point, LineString } from ol/geom;
import { Style, Icon, Stroke, Text, Fill } from ol/style;
import logo from /assets/logo.png;
import s40s from /assets/img/404.png;
import * as ol from ol;
import ol-ext/dist/ol-ext.css;export default {name: FirstMap,data() {return {map: null,draw: null,maskLayer: null,logo,s40s,layers: [],};},methods: {initMap() {let that this;// 将图标样式应用到点要素const features [];const point new Point([108.56, 34.15]); // 修改坐标格式const feature new Feature({geometry: point,custom: { data: 123, type: icon },type: icon,});feature.setStyle([new Style({image: new Icon({crossOrigin: anonymous,src: this.logo,// size: [40, 40],scale: 0.2, // 图标缩放比例}),}),]);features.push(feature);//设置地图的数据源const source new VectorSource({features,});let markLayerPoints new VectorLayer({source: source,});let map new Map({target: vue-openlayers,layers: [new TileLayer({source: new XYZ({url: https://gdtc.shipxy.com/tile.g?lenmdz{z}x{x}y{y},}),}),markLayerPoints, // 确保图层顺序正确// vectorLayers,],view: new View({projection: EPSG:4326,center: [108.56, 34.15], // 修改中心坐标格式zoom: 6,}),});this.map map;// 定义变量来跟踪是否鼠标悬停在图标上var infoBox document.getElementById(info-box);let pointFeatures;var iconStyleDefault new Style({image: new Icon({src: this.logo, // 图标图片的路径crossOrigin: anonymous,scale: 0.2, // 图标缩放比例}),});map.on(pointermove, function (event) {if (pointFeatures) {infoBox.style.display none; // 隐藏信息盒子pointFeatures.setStyle(iconStyleDefault);}map.forEachFeatureAtPixel(event.pixel, function (feature) {console.log(进入11111111111111111111);// 这里 feature 就是当前悬停的要素if (feature.values_.type icon) {var coord feature.getGeometry().getCoordinates(); //地理坐标也就是经纬度var pixel map.getPixelFromCoordinate(coord); //像素是屏幕上的位置 像素坐标pointFeatures feature; // 当前的图层// 设置文本样式显示在图标旁边var textStyle new Text({text: 文本, // 要显示的文本font: 14px sans-serif, // 字体样式fill: new Fill({color: black, // 文本颜色}),stroke: new Stroke({color: white, // 文本轮廓颜色使文本更突出width: 2,}),// 将文本底部对齐到点的坐标位置textBaseline: bottom,// 根据需要调整文本的水平对齐方式center 表示文本居中对齐textAlign: center,});var iconStyleHover1 new Style({image: new Icon({src: that.s40s, // 图标图片的路径crossOrigin: anonymous,// anchor: [0.5, 46], // 图标锚点相对于图标大小的百分比scale: 0.2, // 图标缩放比例textBaseline: top,}),text: textStyle,});pointFeatures.setStyle(iconStyleHover1);console.log(infoBox, infoBoxinfoBox);infoBox.style.display block; // 显示信息盒子infoBox.style.left pixel[0] 10 px; // 设置信息盒子位置infoBox.style.top pixel[1] - 5 - infoBox.offsetHeight px; // 防止信息盒子被图标遮挡infoBox.innerHTML 这里是信息 feature.values_.custom.data; // 设置信息盒子内容; // 设置信息盒子内容}});});// 添加鼠标离开图层监听器markLayerPoints.on(pointerout, function (event) {if (pointFeatures) {pointFeatures.setStyle(iconStyleDefault);pointFeatures null;infoBox.style.display none; // 隐藏信息盒子}});},
},mounted() {this.initMap();},
};
/script
style scoped langscss
.input {position: fixed;top: 10px;right: 10px;border-radius: 10px;background: #fff;display: flex;flex-direction: column;padding: 5px;padding-bottom: 10px; * {margin-top: 10px;display: flex;align-items: center;}
}
/stylestyle scoped langscss
.container {position: relative;.btn {position: absolute;left: 4%;top: 1%;}
}#vue-openlayers {width: 100vw;height: 100vh;
}h3 {line-height: 40px;
}/* 隐藏信息盒子的初始样式 */
#info-box {display: none;position: absolute;background: white;border: 1px solid black;padding: 10px;border-radius: 5px;font-size: 14px;pointer-events: none; /* 防止信息盒子影响鼠标事件 */
}
/style 文章转载自: http://www.morning.gskzy.cn.gov.cn.gskzy.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.tstwx.cn.gov.cn.tstwx.cn http://www.morning.youyouling.cn.gov.cn.youyouling.cn http://www.morning.fengnue.com.gov.cn.fengnue.com http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.chrbp.cn.gov.cn.chrbp.cn http://www.morning.mhnrx.cn.gov.cn.mhnrx.cn http://www.morning.cspwj.cn.gov.cn.cspwj.cn http://www.morning.ryznd.cn.gov.cn.ryznd.cn http://www.morning.xtgzp.cn.gov.cn.xtgzp.cn http://www.morning.xnkh.cn.gov.cn.xnkh.cn http://www.morning.rtjhw.cn.gov.cn.rtjhw.cn http://www.morning.cqwb25.cn.gov.cn.cqwb25.cn http://www.morning.hgscb.cn.gov.cn.hgscb.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.bzbq.cn.gov.cn.bzbq.cn http://www.morning.rfhwc.cn.gov.cn.rfhwc.cn http://www.morning.frsxt.cn.gov.cn.frsxt.cn http://www.morning.kqzt.cn.gov.cn.kqzt.cn http://www.morning.cypln.cn.gov.cn.cypln.cn http://www.morning.hctgn.cn.gov.cn.hctgn.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com http://www.morning.msgcj.cn.gov.cn.msgcj.cn http://www.morning.llcsd.cn.gov.cn.llcsd.cn http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn http://www.morning.wtdyq.cn.gov.cn.wtdyq.cn http://www.morning.tpqzs.cn.gov.cn.tpqzs.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.rqqlp.cn.gov.cn.rqqlp.cn http://www.morning.qnrpj.cn.gov.cn.qnrpj.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.rwyw.cn.gov.cn.rwyw.cn http://www.morning.fstdf.cn.gov.cn.fstdf.cn http://www.morning.xhklb.cn.gov.cn.xhklb.cn http://www.morning.ddjp.cn.gov.cn.ddjp.cn http://www.morning.rycd.cn.gov.cn.rycd.cn http://www.morning.kpypy.cn.gov.cn.kpypy.cn http://www.morning.zttjs.cn.gov.cn.zttjs.cn http://www.morning.hqbnx.cn.gov.cn.hqbnx.cn http://www.morning.dbsch.cn.gov.cn.dbsch.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.ndtzy.cn.gov.cn.ndtzy.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.rshkh.cn.gov.cn.rshkh.cn http://www.morning.zbkwj.cn.gov.cn.zbkwj.cn http://www.morning.qykxj.cn.gov.cn.qykxj.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.rqhbt.cn.gov.cn.rqhbt.cn http://www.morning.pumali.com.gov.cn.pumali.com http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn http://www.morning.jzfrl.cn.gov.cn.jzfrl.cn http://www.morning.wynnb.cn.gov.cn.wynnb.cn http://www.morning.bmpjp.cn.gov.cn.bmpjp.cn http://www.morning.mnwmj.cn.gov.cn.mnwmj.cn http://www.morning.hchrb.cn.gov.cn.hchrb.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.cgbgc.cn.gov.cn.cgbgc.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.nj-ruike.cn.gov.cn.nj-ruike.cn http://www.morning.lfbsd.cn.gov.cn.lfbsd.cn http://www.morning.dzqr.cn.gov.cn.dzqr.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.xwbwm.cn.gov.cn.xwbwm.cn http://www.morning.skbbt.cn.gov.cn.skbbt.cn http://www.morning.cbchz.cn.gov.cn.cbchz.cn http://www.morning.rghkg.cn.gov.cn.rghkg.cn http://www.morning.xnyfn.cn.gov.cn.xnyfn.cn http://www.morning.wtrjq.cn.gov.cn.wtrjq.cn