1、安装maptalks.js

npm install maptalks --save

2、安装聚合mapkercluster

npm install maptalks.markercluster

3、vue页面引入

import * as maptalks from 'maptalks'

import {clusterlayer} from 'maptalks.markercluster'

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

mounted() {

let that = this

//--0--//地图对象的初始化

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

center: [109.1748453547,21.4586700546],

//中心点标记红十字,用于开发debug

centercross : false,

zoom: 13,

minzoom : 10,

maxzoom : 18,

//缩放级别控件

zoomcontrol : false, // add zoom control

scalecontrol : true, // add scale control

//鹰眼控件

overviewcontrol : true, // add overview control

//设置瓦片图层的空间参考spatialreference默认就是3857,googlemap的分辨率

spatialreference : {

projection : 'epsg:3857'

//与map一样,支持更详细的设置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

//底图服务器地址,如下为瓦片地址

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

//tilesystem 控制瓦片的x,y以及行列,后两个是origin原点位置(很重要)

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'

}

})

// 拖动范围限制,黑框控

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 }

})

)

// 往地图上添加点位

this.markinfo()

},

methods: {

setcenter: function(center) {

//标注点平移到某个点

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--//前端聚合查询

// data from realworld.50000.1.js

//需要引入maptalks.markercluster.js

//数据格式[lon,lat,name]

// 如:[[21.8129763667, 109.2714296333, "晓港名城4号楼"],[21.8131727667, 109.2710308833, "晓港名城6号楼"]]

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'),//标注点图标

'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,//聚合的最小个数

'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'

})

}

}

}

补充知识:vue集成maptalk实现geojson3d渲染

我就废话不多说了,大家还是直接看代码吧~

//实例化地图对象

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中的数据,添加到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地图及聚合效果的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持萬仟网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

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

  1. vue.js 构建项目_使用Vue.js和AWS Amplify构建Chatbot

    vue.js 构建项目 Over the last few years, chatbots have exploded in popularity. It makes sense that busin ...

  2. vue单选框选中_使用vue如何默认选中单选框

    使用了vue以后,发现这真的是一个灵活高效的框架,能够轻松实现页面的实时刷新. 那么,今天先聊聊单选框的使用.一般我们使用单选框,会这么写: //HTML one two three 有"c ...

  3. 基于vue前端聊天插件_基于Vue聊天的实现

    基于vue前端聊天插件 基本视频聊天 (basic-vue-chat) Easy to use VueJS chat. 易于使用的VueJS聊天. 安装 (Installation) You can ...

  4. python画交互式地图_使用Python构建交互式地图-入门指南

    python画交互式地图 Welcome to The Beginner's Guide to Building Interactive Maps in Python 欢迎使用Python构建交互式地 ...

  5. arcgis制作瓦片地图_一种GIS瓦片地图的存储方式的制作方法

    本发明涉及一项测绘与地理信息行业数据存储方式. 背景技术: 目前主要使用的GIS瓦片存储技术有两种一种是数据库文件存储,另一种是压缩包存储方式:数据库存储文件方式存在存储数据的冗余,数据格式体积较大的 ...

  6. arcgis制作瓦片地图_【转】ArcGIS地图缓存制作简介

    ArcGIS地图缓存制作简介 制作好的电子地图只有发布为服务后才能为更多的用户所查看与使用.ArcGIS Server 为共享 GIS 资源(如地图)提供了一个平台,无论您是坐在同一间办公室使用 Ar ...

  7. vue 引入json地图_使用vue+echarts快速进行全国地图与各省市地图联动(下钻地图), 引入省份js文件...

    项目源码附js/json地图数据(下载项目源码后请使用Npm install 来安装相关依赖) 效果 使用前请使用npm(cnpm)安装echarts,详情见官网. 本文作为笔记demo只引入5个省( ...

  8. vue 给圆遮盖物添加文字 高德地图_通过 Vue + 高德地图 JS API 在地图上标记咖啡店...

    通过 Vue + 高德地图 JS API 在地图上标记咖啡店 由 学院君 创建于2年前, 最后更新于 2年前 版本号 #1 在上一篇教程中我们为咖啡店地址进行了地理编码,这样,就可以调用高德地图支持的 ...

  9. import引入json文件_关于TypeScript中import JSON的正确姿势详解

    前言 Typescript是微软内部出品的,用actionscript的语法在写js的一门新语言,最近 TypeScript 中毒,想想我一个弱类型出身的人,怎么就喜欢上了类型约束--当然这不是重点, ...

最新文章

  1. Spring源码分析【9】-SpringSecurity密码Remove原理
  2. 5分钟 搭建免费个人博客
  3. 如何成为一名成功的 iOS 程序员?
  4. 人工智能加“医真云”,每年让5700万人告别误诊
  5. 软考经过 之 天助自助者
  6. c语言规定对使用的变量必须,C语言为什么要规定对所用到的变量要“先定义,后使用”...
  7. 使用qsort对不连续的内存数据排序_常见的内排序和外排序算法
  8. 统计建模与r软件_【统计建模与R软件笔记】008 描述统计量(1)
  9. linux笔记_timeval
  10. 目录:关于【稳定性建设之道】大纲速览
  11. php 批量删除挂马文件夹,万能删除服务器被挂马后删不掉的文件夹
  12. 在 Mac 上如何放大或缩小?
  13. SPSS操作(五):主成分分析
  14. Java MD5 加密工具类 生成32位加密码值
  15. 译文|Apache Pulsar 如何保证消息不丢不重?
  16. c语言源文件经过编译后生成文件的后缀是什么?
  17. ElasticSearch集群黄色原因以及解决方案
  18. 预应力锚具的分类和使用领域
  19. R语言--rep函数
  20. 「完美解决」关于最新Ubuntu22.04.1安装launchpad里面PPA报错:“InRelease not available“,“not found file“等

热门文章

  1. vue项目无法启动,谷歌浏览器报:您与此网站之间建立的连接不安全,实际是cdn服务器过期
  2. 自然拼读(程序员必备技能)
  3. 企业微信的表格和word里单元格内如何换行【Alt+Enter】
  4. 数字功放和模拟功放差异介绍
  5. 教你如何利用canvas画布绘制哆啦A梦
  6. 上海落户计算机水平毕业研究生,2021应届生落户上海打分标准,部分毕业生可直接落户上海...
  7. python安装出错0xc00006b_python 装不起来,提示0x80240017错误,咋办?
  8. A320M HDV 4.0主板用CH341A手动刷BIOS支持5600g
  9. Habor镜像仓库的使用
  10. 捕获阿里云异常日志遇到的问题