开源地图组件leafletwx功能更新:支持POI点聚合;减少canvas渲染次数,提升性能

leafletwx是基于leaflet,使用微信原生组件开发的一套开源地图组件,可以替代小程序的原生map组件,项目开源地址: leatletwx

性能提升:

1.合并短时间内的polygon、polyline等canvas元素渲染操作,以减少渲染次数,提升性能

增加功能:

1.支持POI点聚合(POI聚合由Leaflet.markercluster项目改进而来)

示例位于leafletwx中的gdmap页面中

const container = this.selectComponent('#gd-leafletwx')
let min_zoom = 10
let max_zoom = 18
createMap(container,  {
	minZoom: min_zoom,
	maxZoom: max_zoom,
  }, function(map) {

  var geoJsonData = {
	"type": "FeatureCollection", 
	"features": [
	  { "type": "Feature", "id":"1", "properties": { "address": "2"   }, "geometry": { "type": "Point", "coordinates": [120.625348,31.294888] } },
	  { "type": "Feature", "id":"2", "properties": { "address": "151" }, "geometry": { "type": "Point", "coordinates": [120.625675,31.294898] } },
	  { "type": "Feature", "id":"3", "properties": { "address": "21"  }, "geometry": { "type": "Point", "coordinates": [120.625375,31.294636] } },
	  { "type": "Feature", "id":"4", "properties": { "address": "14"  }, "geometry": { "type": "Point", "coordinates": [120.626067,31.294609] } },
	  { "type": "Feature", "id":"5", "properties": { "address": "38B" }, "geometry": { "type": "Point", "coordinates": [120.627379,31.296556] } },
	  { "type": "Feature", "id":"6", "properties": { "address": "38"  }, "geometry": { "type": "Point", "coordinates": [120.623645,31.293604] } },
	  { "type": "Feature", "id":"7", "properties": { "address": "39"  }, "geometry": { "type": "Point", "coordinates": [120.626008,31.294435] } },
	  { "type": "Feature", "id":"8", "properties": { "address": "40"  }, "geometry": { "type": "Point", "coordinates": [120.625680,31.294315] } }
	]
  };
  L.tileLayer('http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}', { subdomains: "1234" }).addTo(map)
  
  var markers = L.markerClusterGroup();
  
  var geoJsonLayer = L.geoJson(geoJsonData, {
	src: 'https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png',
	onEachFeature: function (feature, layer) {
	  layer.bindPopup(feature.properties.address);
	}
  })
  markers.addLayer(geoJsonLayer);

  map.addLayer(markers);
  map.fitBounds(markers.getBounds());
  markers.on('clusterclick', function (a) {
	// a.layer is actually a cluster
	console.log('cluster ' + a.layer.getAllChildMarkers().length);
  });
});

POI聚合效果展示:

达到最大地图缩放等级后,点击聚合区域,相关POI分散显示

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卓伙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值