中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

動(dòng)易網(wǎng)站后臺(tái)密碼破解寧夏百度推廣代理商

動(dòng)易網(wǎng)站后臺(tái)密碼破解,寧夏百度推廣代理商,查詢網(wǎng)站收錄情況的方法,靜態(tài)網(wǎng)站源碼目錄 一、案例截圖 二、安裝OpenLayers庫 三、代碼實(shí)現(xiàn) 3.1、信息窗體DOM元素 3.2、創(chuàng)建Overlay 3.3、創(chuàng)建一個(gè)點(diǎn) 3.4、給點(diǎn)初始化點(diǎn)擊事件 3.5、完整代碼 四、Gitee源碼 一、案例截圖 二、安裝OpenLayers庫 npm install ol 三、代碼實(shí)現(xiàn) 初始化變量: d…

目錄

一、案例截圖

二、安裝OpenLayers庫

三、代碼實(shí)現(xiàn)

3.1、信息窗體DOM元素

3.2、創(chuàng)建Overlay

3.3、創(chuàng)建一個(gè)點(diǎn)

3.4、給點(diǎn)初始化點(diǎn)擊事件

3.5、完整代碼

四、Gitee源碼


一、案例截圖

二、安裝OpenLayers庫

npm install ol

三、代碼實(shí)現(xiàn)

初始化變量:

  data() {return {map:null,overLay:null,//所有點(diǎn)信息都放在這個(gè)圖層pointLayer: new VectorLayer({source: new VectorSource(),}),}},

3.1、信息窗體DOM元素

關(guān)鍵代碼:

  <div><div id="map-container"></div><div id="popup-box" class="popup-box"><button id="close-button" class="close-button">&times;</button><div id="popup-content" class="popup-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; /* 調(diào)整箭頭與彈出框的間距 */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、創(chuàng)建Overlay

覆蓋物(Overlay)是用于在地圖上顯示額外的HTML元素,如彈出窗口、信息框、控件等的層。與圖層不同,覆蓋物不直接渲染地理要素,而是用于展示與地圖位置相關(guān)的HTML內(nèi)容。

element (必需):指定用于作為Overlay內(nèi)容的DOM元素。通常是一個(gè)HTML元素,例如div,作為彈出框或工具提示等。

autoPan (可選) :boolean 或 { animation: { duration: number } } 默認(rèn)值:false,如果設(shè)置為 true,地圖將在Overlay顯示時(shí)自動(dòng)平移,以確保Overlay的位置始終在視圖范圍內(nèi)。如果設(shè)置為對(duì)象,可以自定義平移時(shí)的動(dòng)畫效果。例如,設(shè)置動(dòng)畫持續(xù)時(shí)間。

position (可選) :[number, number](坐標(biāo)數(shù)組) 默認(rèn)值:undefined,初始化時(shí)設(shè)置Overlay的位置,指定為地圖坐標(biāo)系中的坐標(biāo)。如果未指定,Overlay不會(huì)顯示。

stopEvent (可選) :默認(rèn)值:true,確定Overlay的點(diǎn)擊事件是否會(huì)停止事件傳播。如果設(shè)置為 false,點(diǎn)擊 Overlay 的內(nèi)容不會(huì)阻止點(diǎn)擊事件向下傳播到地圖層。

offset (可選) :默認(rèn)值:[0, 0] 說明:Overlay內(nèi)容相對(duì)于指定位置的偏移量,用于微調(diào)Overlay的顯示位置。例如,可以通過提供負(fù)值來向上或向左移動(dòng)Overlay。

關(guān)鍵代碼:

let popupBox = document.getElementById('popup-box');
let closeButton = document.getElementById('close-button');
//用于顯示詳情頁面的窗口(根據(jù)經(jīng)緯度來的,位置不固定)
this.overlay = new Overlay({element: popupBox,autoPan: {animation: {duration: 250,},},offset:[0,-20],
});
this.map.addOverlay(this.overlay);
// 關(guān)閉彈出框的事件處理
let _that = this;
closeButton.addEventListener('click', () => {_that.overlay.setPosition(undefined); // 關(guān)閉彈出框
});

3.3、創(chuàng)建一個(gè)點(diǎn)

關(guān)鍵代碼:

/*** 根據(jù)經(jīng)緯度坐標(biāo)添加自定義圖標(biāo) 支持base64*/
addPoints(coordinate) {// 創(chuàng)建feature要素,一個(gè)feature就是一個(gè)點(diǎn)坐標(biāo)信息let feature = new Feature({geometry: new Point(coordinate),});// 設(shè)置要素的圖標(biāo)feature.setStyle(new Style({// 設(shè)置圖片效果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、給點(diǎn)初始化點(diǎn)擊事件

思路就是遍歷地圖上所有圖層中的Feature,并為它們添加點(diǎn)擊事件。

關(guān)鍵代碼:

initPointEvent(){let _that = this;//給點(diǎn)初始化點(diǎn)擊事件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();// 獲取坐標(biāo)const coordinates = geometry.getCoordinates();// 更新 Overlay 位置_that.overlay.setPosition(coordinates);_that.overlay.getElement().style.display = 'block';let popupContent = document.getElementById('popup-content');popupContent.innerHTML = `<div>經(jīng)度:${coordinates[0]}</div><div>緯度:${coordinates[1]}</div>`;}});
}

3.5、完整代碼

<template><div><div id="map-container"></div><div id="popup-box" class="popup-box"><button id="close-button" class="close-button">&times;</button><div id="popup-content" class="popup-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,//所有點(diǎn)信息都放在這個(gè)圖層pointLayer: new VectorLayer({source: new VectorSource(),}),}},mounted(){this.initMap() // 加載矢量底圖},methods:{initMap() {const KEY = '你申請(qǐng)的KEY'this.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: 經(jīng)緯度投影 w: 球面墨卡托投影style: "default",crossOrigin: 'anonymous', // 解決跨域問題 如無該需求可不添加format: "tiles", //請(qǐng)求的圖層格式,這里指定為瓦片格式wrapX: true, // 允許地圖在 X 方向重復(fù)(環(huán)繞)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']})})}),// 標(biāo)注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');//用于顯示詳情頁面的窗口(根據(jù)經(jīng)緯度來的,位置不固定)this.overlay = new Overlay({element: popupBox,autoPan: {animation: {duration: 250,},},offset:[0,-20],});this.map.addOverlay(this.overlay);// 關(guān)閉彈出框的事件處理let _that = this;closeButton.addEventListener('click', () => {_that.overlay.setPosition(undefined); // 關(guān)閉彈出框});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();},/*** 根據(jù)經(jīng)緯度坐標(biāo)添加自定義圖標(biāo) 支持base64*/addPoints(coordinate) {// 創(chuàng)建feature要素,一個(gè)feature就是一個(gè)點(diǎn)坐標(biāo)信息let feature = new Feature({geometry: new Point(coordinate),});// 設(shè)置要素的圖標(biāo)feature.setStyle(new Style({// 設(shè)置圖片效果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;//給點(diǎn)初始化點(diǎn)擊事件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();// 獲取坐標(biāo)const coordinates = geometry.getCoordinates();// 更新 Overlay 位置_that.overlay.setPosition(coordinates);_that.overlay.getElement().style.display = 'block';let popupContent = document.getElementById('popup-content');popupContent.innerHTML = `<div>經(jīng)度:${coordinates[0]}</div><div>緯度:${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; /* 調(diào)整箭頭與彈出框的間距 */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源碼

地址:?Vue2+OpenLayers給標(biāo)點(diǎn)Feature添加信息窗體

http://m.risenshineclean.com/news/59418.html

相關(guān)文章:

  • 航達(dá)建設(shè)網(wǎng)站上海優(yōu)質(zhì)網(wǎng)站seo有哪些
  • 有沒有什么做統(tǒng)計(jì)的網(wǎng)站網(wǎng)絡(luò)營(yíng)銷比較好的企業(yè)
  • 如何解決網(wǎng)站只收錄首頁的一些辦法小程序制作
  • cms網(wǎng)站地圖模板東莞搜索引擎推廣
  • 開淘寶店和做網(wǎng)站有什么區(qū)別福鼎網(wǎng)站優(yōu)化公司
  • 直接打域名訪問網(wǎng)站關(guān)鍵詞推廣工具
  • 網(wǎng)站制作設(shè)及的技術(shù)產(chǎn)品營(yíng)銷策劃方案3000字
  • 廣州定制網(wǎng)站建設(shè)廣東seo網(wǎng)站推廣代運(yùn)營(yíng)
  • 成都網(wǎng)站開發(fā)哪個(gè)好深圳seo優(yōu)化排名
  • 嵌入式培訓(xùn)班多少錢seo優(yōu)化推廣軟件
  • 企業(yè)網(wǎng)站備案 名稱沈陽seo博客
  • 伊通縣建設(shè)局網(wǎng)站常德政府網(wǎng)站
  • 學(xué)校英語網(wǎng)站欄目名稱域名備案
  • WordPress漢化卡片式主題長(zhǎng)嶺網(wǎng)站優(yōu)化公司
  • 做直播網(wǎng)站需要什么環(huán)球軍事網(wǎng)
  • 網(wǎng)站建設(shè)好之后怎么自己推廣免費(fèi)推廣引流平臺(tái)有哪些
  • 服務(wù)器做網(wǎng)站需安裝哪些軟件佛山網(wǎng)站建設(shè)排名
  • 外包做網(wǎng)站賺錢么app注冊(cè)推廣拉人
  • 濟(jì)南做網(wǎng)站哪家便宜seo項(xiàng)目經(jīng)理
  • 網(wǎng)站怎么添加js廣告位免費(fèi)seo搜索優(yōu)化
  • 常德論壇網(wǎng)站看廣告賺錢
  • 住房和城鄉(xiāng)建設(shè)部網(wǎng)站安廣東省淘寶指數(shù)官網(wǎng)
  • 優(yōu)化網(wǎng)站用軟件好嗎山東一級(jí)造價(jià)師
  • 建設(shè)摩托車官網(wǎng)旗艦店寶雞seo排名
  • 甘肅省蘭州市建設(shè)廳網(wǎng)站硬件優(yōu)化大師
  • 用dreamever如何建設(shè)網(wǎng)站百度指數(shù)數(shù)據(jù)官網(wǎng)
  • 什么系統(tǒng)做網(wǎng)站好2022年最新新聞播報(bào)稿件
  • 濰坊做網(wǎng)站個(gè)人工作室cms自助建站系統(tǒng)
  • 個(gè)人網(wǎng)站建設(shè)工作室深圳網(wǎng)站設(shè)計(jì)十年樂云seo
  • 怎么做賣花的網(wǎng)站9個(gè)廣州seo推廣神技