asp网站路径,嘉兴网站系统总部,Wordpress可以卸载吗,域名解析查询入口目录
一、案例截图
二、安装OpenLayers库
三、代码实现
3.1、信息窗体DOM元素
3.2、创建Overlay
3.3、创建一个点
3.4、给点初始化点击事件
3.5、完整代码
四、Gitee源码 一、案例截图 二、安装OpenLayers库
npm install ol
三、代码实现
初始化变量#xff1a; d…目录
一、案例截图
二、安装OpenLayers库
三、代码实现
3.1、信息窗体DOM元素
3.2、创建Overlay
3.3、创建一个点
3.4、给点初始化点击事件
3.5、完整代码
四、Gitee源码 一、案例截图 二、安装OpenLayers库
npm install ol
三、代码实现
初始化变量 data() {return {map:null,overLay:null,//所有点信息都放在这个图层pointLayer: new VectorLayer({source: new VectorSource(),}),}},
3.1、信息窗体DOM元素
关键代码 divdiv idmap-container/divdiv idpopup-box classpopup-boxbutton idclose-button classclose-buttontimes;/buttondiv idpopup-content classpopup-content/div/div/div
css样式
style scoped#map-container {width: 100%;height: 100vh;
}
.popup-box {background: rgba(255, 255, 255, 0.95);border: 1px solid #ccc;border-radius: 8px;padding: 20px;z-index: 1000;box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);transition: all 0.3s ease;max-width: 300px;font-family: Arial, sans-serif;position: absolute;transform: translate(-50%, -100%); /* 使弹出框上移并居中 */
}/* 添加箭头样式 */
.popup-box::after {content: ;position: absolute;top: 100%; /* 箭头位于弹出框的底部 */left: 50%; /* 箭头横向居中 */margin-left: -6px; /* 调整箭头与弹出框的间距 */border-width: 6px; /* 箭头的大小 */border-style: solid;border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent; /* 箭头的颜色 */
}.close-button {background: none;color: gray;border: none;font-size: 20px;position: absolute;top: 10px;right: 10px;cursor: pointer;
}.popup-content {width: 240px;margin-top: 10px;font-size: 16px;line-height: 1.5;
}
/style
3.2、创建Overlay
覆盖物Overlay是用于在地图上显示额外的HTML元素如弹出窗口、信息框、控件等的层。与图层不同覆盖物不直接渲染地理要素而是用于展示与地图位置相关的HTML内容。
element (必需)指定用于作为Overlay内容的DOM元素。通常是一个HTML元素例如div作为弹出框或工具提示等。
autoPan (可选) boolean 或 { animation: { duration: number } } 默认值false如果设置为 true地图将在Overlay显示时自动平移以确保Overlay的位置始终在视图范围内。如果设置为对象可以自定义平移时的动画效果。例如设置动画持续时间。
position (可选) [number, number]坐标数组 默认值undefined初始化时设置Overlay的位置指定为地图坐标系中的坐标。如果未指定Overlay不会显示。
stopEvent (可选) 默认值true确定Overlay的点击事件是否会停止事件传播。如果设置为 false点击 Overlay 的内容不会阻止点击事件向下传播到地图层。
offset (可选) 默认值[0, 0] 说明Overlay内容相对于指定位置的偏移量用于微调Overlay的显示位置。例如可以通过提供负值来向上或向左移动Overlay。
关键代码
let popupBox document.getElementById(popup-box);
let closeButton document.getElementById(close-button);
//用于显示详情页面的窗口根据经纬度来的位置不固定
this.overlay new Overlay({element: popupBox,autoPan: {animation: {duration: 250,},},offset:[0,-20],
});
this.map.addOverlay(this.overlay);
// 关闭弹出框的事件处理
let _that this;
closeButton.addEventListener(click, () {_that.overlay.setPosition(undefined); // 关闭弹出框
});
3.3、创建一个点
关键代码
/*** 根据经纬度坐标添加自定义图标 支持base64*/
addPoints(coordinate) {// 创建feature要素一个feature就是一个点坐标信息let feature new Feature({geometry: new Point(coordinate),});// 设置要素的图标feature.setStyle(new Style({// 设置图片效果image: new Icon({src: http://api.tianditu.gov.cn/img/map/markerA.png,// anchor: [0.5, 0.5],scale: 1,}),}),);return feature;
},
将其添加到图层上再将图层添加到地图上。
let feature this.addPoints([118.958412, 32.119130]);
this.pointLayer.getSource().addFeature(feature);
this.map.addLayer(this.pointLayer);feature this.addPoints([118.948627, 32.120428]);
this.pointLayer.getSource().addFeature(feature);
3.4、给点初始化点击事件
思路就是遍历地图上所有图层中的Feature并为它们添加点击事件。
关键代码
initPointEvent(){let _that this;//给点初始化点击事件this.map.on(singleclick, (e) {let pixel this.map.getEventPixel(e.originalEvent);let feature this.map.forEachFeatureAtPixel(pixel, function(feature) { return feature; });if(feature){// 获取 Feature 的几何体const geometry feature.getGeometry();// 获取坐标const coordinates geometry.getCoordinates();// 更新 Overlay 位置_that.overlay.setPosition(coordinates);_that.overlay.getElement().style.display block;let popupContent document.getElementById(popup-content);popupContent.innerHTML div经度${coordinates[0]}/divdiv纬度${coordinates[1]}/div;}});
}
3.5、完整代码
templatedivdiv idmap-container/divdiv idpopup-box classpopup-boxbutton idclose-button classclose-buttontimes;/buttondiv idpopup-content classpopup-content/div/div/div
/template
script
import {Feature, Map, View} from ol
import { Tile as TileLayer } from ol/layer
import { get } from ol/proj;
import { getWidth, getTopLeft } from ol/extent
import { WMTS } from ol/source
import WMTSTileGrid from ol/tilegrid/WMTS
import { defaults as defaultControls} from ol/control;
import Overlay from ol/Overlay;
import {Point} from ol/geom;
import VectorLayer from ol/layer/Vector;
import VectorSource from ol/source/Vector;
import {Icon, Style} from ol/style;export const projection get(EPSG:4326);
const projectionExtent projection.getExtent();
const size getWidth(projectionExtent) / 256;
const resolutions [];
for (let z 0; z 19; z) {resolutions[z] size / Math.pow(2, z);
}export default {data() {return {map:null,overLay:null,//所有点信息都放在这个图层pointLayer: new VectorLayer({source: new VectorSource(),}),}},mounted(){this.initMap() // 加载矢量底图},methods:{initMap() {const KEY 你申请的KEYthis.map new Map({target: map-container,layers: [// 底图new TileLayer({source: new WMTS({url: http://t{0-6}.tianditu.com/vec_c/wmts?tk${KEY},layer: vec, // 矢量底图matrixSet: c, // c: 经纬度投影 w: 球面墨卡托投影style: default,crossOrigin: anonymous, // 解决跨域问题 如无该需求可不添加format: tiles, //请求的图层格式这里指定为瓦片格式wrapX: true, // 允许地图在 X 方向重复环绕tileGrid: new WMTSTileGrid({origin: getTopLeft(projectionExtent),resolutions: resolutions,matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16,17,18]})})}),// 标注new TileLayer({source: new WMTS({url: http://t{0-6}.tianditu.com/cva_c/wmts?tk${KEY},layer: cva, //矢量注记matrixSet: c,style: default,crossOrigin: anonymous,format: tiles,wrapX: true,tileGrid: new WMTSTileGrid({origin: getTopLeft(projectionExtent),resolutions: resolutions,matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,16,17,18]})})})],view: new View({center: [118.958366,32.119577],projection: projection,zoom: 12,maxZoom: 17,minZoom: 1}),//加载控件到地图容器中controls: defaultControls({zoom: false,rotate: false,attribution: false})});let popupBox document.getElementById(popup-box);let closeButton document.getElementById(close-button);//用于显示详情页面的窗口根据经纬度来的位置不固定this.overlay new Overlay({element: popupBox,autoPan: {animation: {duration: 250,},},offset:[0,-20],});this.map.addOverlay(this.overlay);// 关闭弹出框的事件处理let _that this;closeButton.addEventListener(click, () {_that.overlay.setPosition(undefined); // 关闭弹出框});let feature this.addPoints([118.958412, 32.119130]);this.pointLayer.getSource().addFeature(feature);this.map.addLayer(this.pointLayer);feature this.addPoints([118.948627, 32.120428]);this.pointLayer.getSource().addFeature(feature);this.initPointEvent();},/*** 根据经纬度坐标添加自定义图标 支持base64*/addPoints(coordinate) {// 创建feature要素一个feature就是一个点坐标信息let feature new Feature({geometry: new Point(coordinate),});// 设置要素的图标feature.setStyle(new Style({// 设置图片效果image: new Icon({src: http://api.tianditu.gov.cn/img/map/markerA.png,// anchor: [0.5, 0.5],scale: 1,}),}),);return feature;},initPointEvent(){let _that this;//给点初始化点击事件this.map.on(singleclick, (e) {let pixel this.map.getEventPixel(e.originalEvent);let feature this.map.forEachFeatureAtPixel(pixel, function(feature) { return feature; });if(feature){// 获取 Feature 的几何体const geometry feature.getGeometry();// 获取坐标const coordinates geometry.getCoordinates();// 更新 Overlay 位置_that.overlay.setPosition(coordinates);_that.overlay.getElement().style.display block;let popupContent document.getElementById(popup-content);popupContent.innerHTML div经度${coordinates[0]}/divdiv纬度${coordinates[1]}/div;}});}}
}
/script
style scoped#map-container {width: 100%;height: 100vh;
}
.popup-box {background: rgba(255, 255, 255, 0.95);border: 1px solid #ccc;border-radius: 8px;padding: 20px;z-index: 1000;box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);transition: all 0.3s ease;max-width: 300px;font-family: Arial, sans-serif;position: absolute;transform: translate(-50%, -100%); /* 使弹出框上移并居中 */
}/* 添加箭头样式 */
.popup-box::after {content: ;position: absolute;top: 100%; /* 箭头位于弹出框的底部 */left: 50%; /* 箭头横向居中 */margin-left: -6px; /* 调整箭头与弹出框的间距 */border-width: 6px; /* 箭头的大小 */border-style: solid;border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent; /* 箭头的颜色 */
}.close-button {background: none;color: gray;border: none;font-size: 20px;position: absolute;top: 10px;right: 10px;cursor: pointer;
}.popup-content {width: 240px;margin-top: 10px;font-size: 16px;line-height: 1.5;
}
/style
四、Gitee源码
地址 Vue2OpenLayers给标点Feature添加信息窗体 文章转载自: http://www.morning.gjtdp.cn.gov.cn.gjtdp.cn http://www.morning.nwfxp.cn.gov.cn.nwfxp.cn http://www.morning.twgzq.cn.gov.cn.twgzq.cn http://www.morning.npcxk.cn.gov.cn.npcxk.cn http://www.morning.ckwrn.cn.gov.cn.ckwrn.cn http://www.morning.ntqjh.cn.gov.cn.ntqjh.cn http://www.morning.egmux.cn.gov.cn.egmux.cn http://www.morning.lhgkr.cn.gov.cn.lhgkr.cn http://www.morning.glrzr.cn.gov.cn.glrzr.cn http://www.morning.xtrzh.cn.gov.cn.xtrzh.cn http://www.morning.pqhgn.cn.gov.cn.pqhgn.cn http://www.morning.txnqh.cn.gov.cn.txnqh.cn http://www.morning.jjnry.cn.gov.cn.jjnry.cn http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.jnhhc.cn.gov.cn.jnhhc.cn http://www.morning.kgqpx.cn.gov.cn.kgqpx.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.mqldj.cn.gov.cn.mqldj.cn http://www.morning.jmbgl.cn.gov.cn.jmbgl.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.pdkht.cn.gov.cn.pdkht.cn http://www.morning.dmcqy.cn.gov.cn.dmcqy.cn http://www.morning.tzzkm.cn.gov.cn.tzzkm.cn http://www.morning.kbqbx.cn.gov.cn.kbqbx.cn http://www.morning.lcbnb.cn.gov.cn.lcbnb.cn http://www.morning.kpbn.cn.gov.cn.kpbn.cn http://www.morning.nndbz.cn.gov.cn.nndbz.cn http://www.morning.dbqg.cn.gov.cn.dbqg.cn http://www.morning.dncgb.cn.gov.cn.dncgb.cn http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn http://www.morning.wtdhm.cn.gov.cn.wtdhm.cn http://www.morning.thwcg.cn.gov.cn.thwcg.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.tytly.cn.gov.cn.tytly.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.cwknc.cn.gov.cn.cwknc.cn http://www.morning.wpqcj.cn.gov.cn.wpqcj.cn http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.trrhj.cn.gov.cn.trrhj.cn http://www.morning.fllfz.cn.gov.cn.fllfz.cn http://www.morning.plhhd.cn.gov.cn.plhhd.cn http://www.morning.qygfb.cn.gov.cn.qygfb.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.ngznq.cn.gov.cn.ngznq.cn http://www.morning.pdbgm.cn.gov.cn.pdbgm.cn http://www.morning.pkrb.cn.gov.cn.pkrb.cn http://www.morning.xywfz.cn.gov.cn.xywfz.cn http://www.morning.tgmwy.cn.gov.cn.tgmwy.cn http://www.morning.mcpby.cn.gov.cn.mcpby.cn http://www.morning.kuaijili.cn.gov.cn.kuaijili.cn http://www.morning.mtbth.cn.gov.cn.mtbth.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.sbncr.cn.gov.cn.sbncr.cn http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn http://www.morning.yswxq.cn.gov.cn.yswxq.cn http://www.morning.nnqrb.cn.gov.cn.nnqrb.cn http://www.morning.hclplus.com.gov.cn.hclplus.com http://www.morning.srhqm.cn.gov.cn.srhqm.cn http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn http://www.morning.rfxw.cn.gov.cn.rfxw.cn http://www.morning.c7493.cn.gov.cn.c7493.cn http://www.morning.ffptd.cn.gov.cn.ffptd.cn http://www.morning.mwmtk.cn.gov.cn.mwmtk.cn http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn http://www.morning.kdgcx.cn.gov.cn.kdgcx.cn http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.pabxcp.com.gov.cn.pabxcp.com http://www.morning.smry.cn.gov.cn.smry.cn http://www.morning.ggqcg.cn.gov.cn.ggqcg.cn http://www.morning.xtxp.cn.gov.cn.xtxp.cn http://www.morning.pfkrw.cn.gov.cn.pfkrw.cn http://www.morning.ktblf.cn.gov.cn.ktblf.cn http://www.morning.nkmw.cn.gov.cn.nkmw.cn http://www.morning.zlnyk.cn.gov.cn.zlnyk.cn http://www.morning.lsgsn.cn.gov.cn.lsgsn.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.rqbkc.cn.gov.cn.rqbkc.cn http://www.morning.cfnsn.cn.gov.cn.cfnsn.cn