日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

vue 引入json地图_使用vue引入maptalks地图及聚合效果的实现

發(fā)布時(shí)間:2024/1/8 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue 引入json地图_使用vue引入maptalks地图及聚合效果的实现 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、安裝maptalks.js

npm install maptalks --save

2、安裝聚合mapkercluster

npm install maptalks.markercluster

3、vue頁(yè)面引入

import * as maptalks from 'maptalks'

import {clusterlayer} from 'maptalks.markercluster'

4、初始化地圖并添加聚合

mounted() {

let that = this

//--0--//地圖對(duì)象的初始化

this.map = new maptalks.map('map', {

center: [109.1748453547,21.4586700546],

//中心點(diǎn)標(biāo)記紅十字,用于開(kāi)發(fā)debug

centercross : false,

zoom: 13,

minzoom : 10,

maxzoom : 18,

//縮放級(jí)別控件

zoomcontrol : false, // add zoom control

scalecontrol : true, // add scale control

//鷹眼控件

overviewcontrol : true, // add overview control

//設(shè)置瓦片圖層的空間參考spatialreference默認(rèn)就是3857,googlemap的分辨率

spatialreference : {

projection : 'epsg:3857'

//與map一樣,支持更詳細(xì)的設(shè)置resolutions,fullextent等

},

baselayer: new maptalks.tilelayer('base', {

// urltemplate: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',

//renderer : 'canvas', // set tilelayer's renderer to canvas

//底圖服務(wù)器地址,如下為瓦片地址

urltemplate: 'http://xxx.xx.xxx.xxx:xxxx/mapdata/tiles/{z}/{x}/{y}.png',

//tilesystem 控制瓦片的x,y以及行列,后兩個(gè)是origin原點(diǎn)位置(很重要)

tilesystem : [1, 1, -20037508.3427890,-20037508.3427890], // tile system

//subdomains: ['a','b','c'],

minzoom : 10,

maxzoom : 18

// css filter 濾鏡配置

// cssfilter : 'sepia(60%) invert(95%)',

// attribution: '? maptalk for amap contributors'

}),

layers : [

new maptalks.vectorlayer('v')

],

attribution: {//左下角info

content: '?qmap'

}

})

// 拖動(dòng)范圍限制,黑框控

let extent = new maptalks.extent(108.8584570000,20.9790840000,110.0569128018,22.1177123207)

// var extent = new maptalks.extent(112.5381688894,26.8876543885,112.5605009244,26.9012691519);

// set map's max extent to map's extent at zoom 14

this.map.setmaxextent(extent)

this.map.setzoom(this.map.getzoom(), { animation : false })

this.map.getlayer('v')

.addgeometry(

new maptalks.polygon(extent.toarray(), {

symbol : { 'polygonopacity': 0, 'linewidth': 0 }

})

)

// 往地圖上添加點(diǎn)位

this.markinfo()

},

methods: {

setcenter: function(center) {

//標(biāo)注點(diǎn)平移到某個(gè)點(diǎn)

let centerv = maptalks1.crstransform.transform(center, 'bd09ll', 'gcj02')

this.map.animateto({

zoom: 17,

center: centerv

}, {

duration: 1000

})

},

// 上圖

markinfo: function () {

let that = this

that.map.removelayer(that.clusterlayer)

let markers = []

//--2--//前端聚合查詢(xún)

// data from realworld.50000.1.js

//需要引入maptalks.markercluster.js

//數(shù)據(jù)格式[lon,lat,name]

// 如:[[21.8129763667, 109.2714296333, "曉港名城4號(hào)樓"],[21.8131727667, 109.2710308833, "曉港名城6號(hào)樓"]]

for (let i = 0; i < that.addresspoints.length; i++) {

let a = that.addresspoints[i]

markers.push(new maptalks.marker(maptalks1.crstransform.transform([a.latitude, a.longitude], 'bd09ll', 'gcj02'),

{

'properties': {

'name': a.name,

'onsale': a.onsale

},

symbol : [

{

'markerfile' : a.onsale ? require('../../../static/img/on.png') : require('../../../static/img/off.png'),//標(biāo)注點(diǎn)圖標(biāo)

'markerwidth' : 30,

'markerheight' : 35

},{

'textname' : '{name}',

'textsize' : 12,

'textdy' : -50,

'texthaloradius' : 5,

'texthalofill' : a.onsale ? '#ffb427' : '#b9b9b9',

'textfill' : '#fff' // color

}

]

}

))//.on('mousedown', onclick))

}

let clusterlayer = new clusterlayer('cluster', markers, {

'noclusterwithonemarker' : true,

'noclusterwithhowmany': 8,//聚合的最小個(gè)數(shù)

'maxclusterzoom' : 15,

//"count" is an internal variable: marker count in the cluster.

'symbol': {

'markertype' : 'ellipse',

'markerfill' : { property:'count', type:'interval', stops: [[0, 'rgb(135, 196, 240)'], [9, '#1bbc9b'],[50, 'rgb(116, 115, 149)'],

[99, 'rgb(216, 115, 149)']]},

'markerfillopacity' : 0.7,

'markerlineopacity' : 1,

'markerlinewidth' : 3,

'markerlinecolor' : '#fff',

'markerwidth' : { property:'count', type:'interval', stops: [[0, 40], [9, 60], [50, 70],[99, 80]] },

'markerheight' : { property:'count', type:'interval', stops: [[0, 40], [9, 60], [50, 70],[99, 80]] }

},

'drawclustertext': true,

'geometryevents' : true,

'single': true

})

that.map.addlayer(clusterlayer)

that.clusterlayer = clusterlayer

function onclick(e) {

e.target.setinfowindow({

'content': '

' + e.target.properties.name + ' ',

'width' : 150,

'dy' : 5,

'autopan': true,

'custom': false,

'autoopenon' : 'click', //set to null if not to open when clicking on marker

'autocloseon' : 'click'

})

}

}

}

補(bǔ)充知識(shí):vue集成maptalk實(shí)現(xiàn)geojson3d渲染

我就廢話不多說(shuō)了,大家還是直接看代碼吧~

//實(shí)例化地圖對(duì)象

let map = new maptalks.map("map",{

center: [13.416935229170008, 52.529564137540376],

zoom: 20,

dragpitch : true,

//allow map to drag rotating, true by default

dragrotate : true,

//enable map to drag pitching and rotating at the same time, false by default

dragrotatepitch : true,

baselayer: new maptalks.tilelayer('base', {

urltemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',

subdomains: ['a','b','c','d'],

attribution: '? openstreetmap contributors, ? carto'

})

});

// features to draw

//將buildings中的數(shù)據(jù),添加到features中

let features = [];

buildings.foreach(function (b) {

console.log(b.features);

features = features.concat(b.features);

});

// the threelayer to draw buildings

let threelayer = new threelayer('t', {

forcerenderonmoving : true,

forcerenderonrotating : true

});

threelayer.preparetodraw = function (gl, scene, camera) {

let me = this;

let light = new three.directionallight(0xffffff);

light.position.set(0, -10, 10).normalize();

scene.add(light);

features.foreach(function (g) {

let heightperlevel = 5;

let levels = g.properties.levels || 1;

let color = 0x2685a7

let m = new three.meshphongmaterial({color: color, opacity : 0.7});

//change to back side with three <= v0.94

// m.side = three.backside;

let mesh = me.toextrudemesh(maptalks.geojson.togeometry(g), heightperlevel, m, heightperlevel);

if (array.isarray(mesh)) {

scene.add.apply(scene, mesh);

} else {

scene.add(mesh);

}

});

};

threelayer.addto(map);

以上這篇使用vue引入maptalks地圖及聚合效果的實(shí)現(xiàn)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持萬(wàn)仟網(wǎng)。

如您對(duì)本文有疑問(wèn)或者有任何想說(shuō)的,請(qǐng)點(diǎn)擊進(jìn)行留言回復(fù),萬(wàn)千網(wǎng)友為您解惑!

總結(jié)

以上是生活随笔為你收集整理的vue 引入json地图_使用vue引入maptalks地图及聚合效果的实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。