国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

高德地圖api2.0點(diǎn)聚合及點(diǎn)標(biāo)記事件

這篇具有很好參考價(jià)值的文章主要介紹了高德地圖api2.0點(diǎn)聚合及點(diǎn)標(biāo)記事件。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

在使用高德地圖API的過(guò)程中,發(fā)現(xiàn)2.0版本的點(diǎn)聚合和之前版本的使用上有很大的區(qū)別,在此做一下點(diǎn)聚合的使用以及點(diǎn)標(biāo)記的事件的記錄。

在2.0之前的版本,MarkerClusterer插件的使用如下:

new AMap.MarkerClusterer(
? ? //地圖實(shí)例對(duì)象
? ? map:Map,  
? ? //marker類(lèi)構(gòu)造對(duì)象
? ? markers:Array<Marker>,  ? 
? ? //點(diǎn)聚合屬性,具體可查閱https://lbs.amap.com/api/javascript-api/reference/plugin#AMap.MarkerClusterer
? ? opts:MarkerClustererOptions 
)

而2.0版本對(duì)MarkerClusterer進(jìn)行了改動(dòng)

new AMap.MarkerClusterer(
    //地圖實(shí)例對(duì)象
    map:Map,  
    //經(jīng)緯度數(shù)組對(duì)象
    dataOptions:Array   
    //點(diǎn)聚合屬性
    markerClusterOptions:Object 
)

dataOptions:[
? ? {
? ? ? ? weight: Number, //權(quán)重(可選)以權(quán)重高的點(diǎn)為中心進(jìn)行聚合
? ? ? ? lnglat: Array //經(jīng)緯度數(shù)組 string[] | number[]
? ? }
]

在2.0版本中,markerClusterOptions去掉了minClusterSize 集合的最小數(shù)量,zoomOnclick 點(diǎn)擊聚合點(diǎn)時(shí)是否散開(kāi);對(duì)renderClusterMarker屬性進(jìn)行了修改,去掉了renderClusterMarker:function的markers屬性;新增了renderMarker: function 用于實(shí)現(xiàn)非聚合點(diǎn)的自定義設(shè)置

new AMap.MarkerClusterer(map, marker, { 
? ? gridSize: number, //聚合計(jì)算時(shí)網(wǎng)格的像素大小,默認(rèn)60
? ? //minClusterSize 聚合的最小數(shù)量(已棄用)
? ? maxZoom: number, //最大聚合級(jí)別,超出級(jí)別不進(jìn)行聚合,默認(rèn)18
? ? averageCenter: boolean, //聚合點(diǎn)的圖標(biāo)位置是否是所有聚合內(nèi)點(diǎn)的中心點(diǎn),默認(rèn)true,如果有權(quán)重則以權(quán)重高的為中心進(jìn)行聚合
? ? clusterByZoomChange: boolean, //地圖縮放過(guò)程中是否聚合,默認(rèn)false
? ? styles: Array<Object>, //聚合后點(diǎn)標(biāo)記樣式
? ? //styles包含以下屬性
? ? ? ? //url{string} (必選)圖標(biāo)的url地址
? ? ? ? //size{AMap.Size} (必選)圖標(biāo)的圖片大小
? ? ? ? //offset{AMap.Pixel} (可選)圖標(biāo)相對(duì)于左上角的偏移量
? ? ? ? //imageOffset{AMap.Pixel} (可選)圖片在可視區(qū)域的偏移量
? ? ? ? //textColor{String} (可選)文字顏色,默認(rèn)#000000
? ? ? ? //textSize{Number} (可選)文字大小,默認(rèn)10
? ? renderClusterMarker: (cluster: any) => {
? ? ? ? cluster.count //當(dāng)前聚合點(diǎn)下marker的數(shù)量
? ? ? ? cluster.marker //當(dāng)前聚合點(diǎn)的marker對(duì)象
    },
? ? renderMarker: (context: any) => {
? ? ? ? context.marker //非聚合點(diǎn)的marker對(duì)象
? ? }
? ? //zoomOnClick 點(diǎn)擊聚合點(diǎn)時(shí)是否散開(kāi)(已棄用)
})        

點(diǎn)聚合及點(diǎn)標(biāo)記的鼠標(biāo)移入、移出、點(diǎn)擊效果的實(shí)現(xiàn)(只提供思路,不進(jìn)行數(shù)據(jù)效果實(shí)現(xiàn))文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-649886.html

const markerData: any[] //獲取的標(biāo)記坐標(biāo)等信息
const markers: [{
? ? weight: number, //權(quán)重
? ? lnglat: number[] | string [], //經(jīng)緯度
? ? extData:object //其他需要傳遞的信息,如id、name等
}] = [] 

markerData.map((item: any) => {
? ? markers.push({
? ? ? ? weight: item.weight,
? ? ? ? lnglat: [item.lon, item.lat],
? ? ? ? extData: {
? ? ? ? ? ? id: item.id,
? ? ? ? ? ? icon: url,
? ? ? ? ? ? markerIcon: url
? ? ? ? }
? ? })
})

const clu = new AMap.MarkerClusterer(map, markers, {
? ? //聚合點(diǎn)自定義樣式交互
? ? renderClusterMarker: (cluster: any) = {
? ? ? ? //marker點(diǎn)標(biāo)記API
        //自定義聚合樣式
? ? ? ? //cluster.data[0].extData可獲取到傳入的其他數(shù)據(jù)
? ? ? ? cluster.marker.setAnchor('bottom-center');
? ? ? ? cluster.marker.setIcon(new AMap.Icon({ image: cluster.data[0].extData.markerIcon }));
? ? ? ? cluster.marker.setLabel({
? ? ? ? ? ? content: `<span style="cursor: pointer;">${cluster.count}</span>`,
? ? ? ? ? ? direction: 'center',
? ? ? ? ? ? offset: new AMap.Pixel(0, -5),
? ? ? ? })
? ? ? ? //添加鼠標(biāo)移入放大效果
? ? ? ? cluster.marker.on('mouseover', () => {
? ? ? ? ? ? cluster.marker.setIcon(
? ? ? ? ? ? ? ? new AMap.Icon({
? ? ? ? ? ? ? ? ? ? image: cluster.marker.getIcon()._opts.image,
                    size: new AMap.Size(40, 50), //根據(jù)image分辨率計(jì)算放大后尺寸
                    imageSize: new AMap.Size(40, 50),
? ? ? ? ? ? ? ? }),
? ? ? ? ? ? );
? ? ? ? ? ? cluster.marker.setLabel({
? ? ? ? ? ? ? ? content: `<span style="cursor: pointer;font-size: 20px;">${cluster.count}</span>`,
? ? ? ? ? ? ? ? direction: 'center',
                offset: new AMap.Pixel(0, -5),
            });
? ? ? ? });
? ? ? ? //鼠標(biāo)移出還原
? ? ? ? cluster.marker.on('mouseout', () => {
? ? ? ? ? ? cluster.marker.setIcon(
? ? ? ? ? ? ? ? new AMap.Icon({
                ? ? image: cluster.marker.getIcon()._opts.image,
                    size: new AMap.Size(32, 40),
                    imageSize: new AMap.Size(32, 40),
? ? ? ? ? ? ? ? }),
? ? ? ? ? ? );
? ? ? ? ? ? cluster.marker.setLabel({
 ? ? ? ? ? ? ? ? content: `<span style="cursor: pointer;">${cluster.count}</span>`,
                 direction: 'center',
                 offset: new AMap.Pixel(0, -5),
? ? ? ? ? ? });
? ? ? ? });
? ? },
? ? //非聚合點(diǎn)自定義樣式交互
? ? renderMarker: (context: any) => {
? ? ? ? context.marker.setAnchor('bottom-center');
? ? ? ? context.marker.setOffset(new AMap.Pixel(0, 0));
? ? ? ? context.marker.setIcon(new AMap.Icon({ image: context.data[0].extData.markerIcon }));
? ? ? ? context.marker.setLabel({
? ? ? ? ? ? content: `<img src=${context.data[0].extData.icon} style="cursor: pointer;" />`,
            direction: 'center',
            offset: new AMap.Pixel(0, -5),
? ? ? ? });
? ? ? ? //鼠標(biāo)移入移出同上,不再重復(fù)
? ? ? ? //marker鼠標(biāo)點(diǎn)擊事件
? ? ? ? context.marker.on('click', () => {
? ? ? ? ? ? const params = context.data[0].extData;
? ? ? ? ? ? console.log(params.id) //id
? ? ? ? });
? ? }
})
//添加聚合點(diǎn)點(diǎn)擊事件
clu.on('click', (data: any) => {
? ? //判斷是否是聚合點(diǎn),不是聚合點(diǎn)就執(zhí)行單個(gè)點(diǎn)擊方式
? ? if (data.clusterData.length <= 1) return;
? ? //計(jì)算所有聚合點(diǎn)的中心點(diǎn)
? ? let alng = 0,
? ? ? ? alat = 0;
? ? for (const m of data.clusterData) {
? ? ? ? alng += m.lnglat.lng;
? ? ? ? alat += m.lnglat.lat;
? ? }
? ? const lat = alat / data.clusterData.length;
? ? const lng = alng / data.clusterData.length;
? ? //以中心點(diǎn)固定倍數(shù)放大地圖,達(dá)到展開(kāi)聚合點(diǎn)的效果
? ? map.setZoom(10);
? ? map.setCenter([lng, lat]);
});

到了這里,關(guān)于高德地圖api2.0點(diǎn)聚合及點(diǎn)標(biāo)記事件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 高德地圖的簡(jiǎn)單使用:點(diǎn)擊標(biāo)記獲取經(jīng)緯度和詳細(xì)地址

    高德地圖的簡(jiǎn)單使用:點(diǎn)擊標(biāo)記獲取經(jīng)緯度和詳細(xì)地址

    1. 先進(jìn)入高德開(kāi)發(fā)平臺(tái)注冊(cè)登錄 2.進(jìn)入地圖 js Api 按照步驟申請(qǐng)key 3 使用npm安裝依賴(lài)包 npm i @amap/amap-jsapi-loader --save 4. 高德api 都有說(shuō)明 下面看下我實(shí)現(xiàn)的功能和代碼 1. 初始化地圖加載地圖將自動(dòng)定位到您所在城市并顯示,點(diǎn)擊地圖實(shí)現(xiàn)了打點(diǎn)獲取經(jīng)緯度和詳情地址。 2.輸入提

    2024年02月12日
    瀏覽(20)
  • vue對(duì)高德地圖的簡(jiǎn)單使用:點(diǎn)擊標(biāo)記并獲取經(jīng)緯度和詳細(xì)地址

    vue對(duì)高德地圖的簡(jiǎn)單使用:點(diǎn)擊標(biāo)記并獲取經(jīng)緯度和詳細(xì)地址

    目錄 第一步:先按部就班,進(jìn)入高德開(kāi)放平臺(tái),跟著步驟注冊(cè)賬號(hào),創(chuàng)建應(yīng)用 第二步:用npm下載包,初始化地圖 第三步:實(shí)現(xiàn)點(diǎn)擊地圖添加標(biāo)記 第四步:點(diǎn)擊獲取詳細(xì)地址 第五步:搜索獲取相關(guān)地區(qū)提示 第六步:全部代碼(把密鑰和key替換可直接運(yùn)行) ? 高德地圖有AP

    2024年02月06日
    瀏覽(34)
  • vue 高德地圖 —— 點(diǎn)標(biāo)記、信息彈窗、網(wǎng)頁(yè)導(dǎo)航、獲取經(jīng)緯度及當(dāng)前城市信息

    新建 components/amap.vue 文件,封裝高德地圖組件: 接下來(lái),在需要使用的組件中引入 amap.vue :

    2023年04月15日
    瀏覽(27)
  • 141:vue+leaflet 利用高德逆地理編碼,點(diǎn)擊地圖標(biāo)記marker,popup地址信息

    141:vue+leaflet 利用高德逆地理編碼,點(diǎn)擊地圖標(biāo)記marker,popup地址信息

    第141個(gè) 點(diǎn)擊查看專(zhuān)欄目錄 本示例的目的是介紹演示如何在vue+leaflet中利用高德逆地理編碼,點(diǎn)擊地圖標(biāo)記marker,popup地址信息 。主要利用高德地圖的api將坐標(biāo)轉(zhuǎn)化為地址,然后在點(diǎn)擊的位置,彈出彈窗,在里面顯示出地址信息。 直接復(fù)制下面的 vue+leaflet源代碼,操作2分鐘即

    2024年01月24日
    瀏覽(30)
  • 高德地圖js api

    官網(wǎng):開(kāi)發(fā) | 高德地圖API vue-amap 基于vue的高德地圖:組件 | vue-amap 注意事項(xiàng):地圖盒子一定要有寬高?。。。?! 在項(xiàng)目中安裝 default-passive-events,并引入 main.js 中, 這個(gè)包的作用是通過(guò)添加 passive,來(lái)阻止 touchstart 事件,讓頁(yè)面更加流暢。 事件使用 ***.on(‘事件名比如:(cli

    2024年02月04日
    瀏覽(22)
  • Vue 高德地圖(@amap/amap-jsapi-loader)的基本使用:添加標(biāo)記、POI關(guān)鍵字搜索、路線規(guī)劃...(方法一)

    Vue 高德地圖(@amap/amap-jsapi-loader)的基本使用:添加標(biāo)記、POI關(guān)鍵字搜索、路線規(guī)劃...(方法一)

    具體的步驟可以參考我的上一篇博客,有詳細(xì)說(shuō)明如何注冊(cè)申請(qǐng)高德的Key、秘鑰,初始化地圖等等 vue-amap : vue-amap 基于 Vue 2.x 與高德的地圖組件 高德官方介紹:地圖 JS API Web服務(wù)API簡(jiǎn)介 高德Web服務(wù)API向開(kāi)發(fā)者提供HTTP接口,開(kāi)發(fā)者可通過(guò)這些接口使用各類(lèi)型的地理數(shù)據(jù)服務(wù),

    2024年01月18日
    瀏覽(33)
  • 申請(qǐng)高德地圖API【流程記錄】

    申請(qǐng)高德地圖API【流程記錄】

    現(xiàn)在我們需要使用高德地圖的api進(jìn)行功能的實(shí)現(xiàn),這就需要我們申請(qǐng)一個(gè)高德地圖的key 1.進(jìn)入官網(wǎng) 登錄賬號(hào) 點(diǎn)擊高德開(kāi)放平臺(tái) | 高德地圖API (amap.com)。進(jìn)行登錄 選擇控制臺(tái) 注冊(cè)為開(kāi)發(fā)者 填寫(xiě)郵箱獲取驗(yàn)證碼后,進(jìn)行支付寶掃碼進(jìn)行實(shí)名認(rèn)證 注冊(cè)完成 點(diǎn)擊確認(rèn)即可 2.申請(qǐng)

    2024年01月17日
    瀏覽(21)
  • 高德API JS 高德地圖獲取多個(gè)坐標(biāo)點(diǎn)的中心點(diǎn)

    高德API JS 高德地圖獲取多個(gè)坐標(biāo)點(diǎn)的中心點(diǎn)

    我需要: 在地圖上展示多個(gè)地點(diǎn) 地圖縮放到合適的大小,要求剛好能顯示全部點(diǎn)位 邊緣留有一部分間隔。 做成如圖所示這樣。 經(jīng)過(guò)一下午的研究,弄出來(lái)了。 需要以下這些 AMap 的類(lèi)庫(kù): AMap.Bounds() 區(qū)域 AMap.LngLat() 點(diǎn)坐標(biāo)(基礎(chǔ)點(diǎn)位) AMap.setBounds() 設(shè)置地圖區(qū)域,這會(huì)自動(dòng)

    2024年02月07日
    瀏覽(220)
  • Vue3+Vite連接高德地圖JS API——地圖顯示、輸入搜索

    Vue3+Vite連接高德地圖JS API——地圖顯示、輸入搜索

    1、進(jìn)入高德地圖API官網(wǎng)(https://lbs.amap.com/): 2、注冊(cè)登錄。 3、進(jìn)入控制臺(tái)。 4、點(diǎn)擊“應(yīng)用管理”,點(diǎn)擊“我的應(yīng)用”,創(chuàng)建新應(yīng)用。 5、添加Key,服務(wù)平臺(tái)選擇“Web端(JS API)”,白名單不要填寫(xiě),勾選閱讀并同意。 點(diǎn)擊提交后,就能看到Key已經(jīng)生成,記住這里的Key和安

    2024年01月17日
    瀏覽(23)
  • uniapp上高德(百度)地圖API的使用(APP安卓)

    uniapp上高德(百度)地圖API的使用(APP安卓)

    前言 由于在app中沒(méi)有document,window等對(duì)象,所以使用在pc端傳統(tǒng)方法引入的方式,將會(huì)發(fā)現(xiàn)無(wú)法引用成功,會(huì)出現(xiàn)白屏現(xiàn)象。 目前有兩種解決方式: 使用uniapp的web-view方式(百度地圖) 使用renderjs來(lái)調(diào)用document等js對(duì)象(高德地圖) map.vue: 中間實(shí)時(shí)顯示地圖上圖標(biāo)的個(gè)數(shù),以及

    2023年04月10日
    瀏覽(121)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包