Coder Social home page Coder Social logo

maptalks.markercluster's Introduction

maptalks.markercluster

CircleCI NPM Version

A plugin of maptalks.js to draw markers as clusters.

screenshot

Examples

Install

  • Install with npm: npm install maptalks.markercluster.
  • Download from dist directory.
  • Use unpkg CDN: https://unpkg.com/maptalks.markercluster/dist/maptalks.markercluster.min.js

Usage

As a plugin, maptalks.markercluster must be loaded after maptalks.js in browsers.

<script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/maptalks.markercluster/dist/maptalks.markercluster.min.js"></script>
<script>
var data = [marker1, marker2, marker3];
var clusterLayer = new maptalks.ClusterLayer('cluster', data).addTo(map);
</script>

Supported Browsers

IE 9-11, Chrome, Firefox, other modern and mobile browsers.

API Reference

ClusterLayer is a subclass of maptalks.VectorLayer and inherits all the methods of its parent.

Constructor

new maptalks.ClusterLayer(id, data, options)
  • id String layer id
  • data Marker[] layer data, an array of maptalks.Marker
  • options Object options
    • maxClusterRadius Number max cluster radius (160 by default)
    • symbol Object symbol of clusters
    • textSymbol Object symbol of cluster texts
    • drawClusterText Boolean whether to draw cluster texts (true by default)
    • textSumProperty String property name to sum up to display as the cluster text
    • maxClusterZoom Number the max zoom to draw as clusters (null by default)
    • animation Boolean whether animate the clusters when zooming (true by default)
    • animationDuration Number the animation duration
    • noClusterWithOneMarker Boolean whether display cluster with only one marker (false by default)
    • Other options defined in maptalks.VectorLayer

config(key, value)

config layer's options and redraw the layer if necessary

clusterLayer.config('maxClusterRadius', 100);
clusterLayer.config({
    'textSymbol' : {
        'textFaceName'      : 'monospace',
        'textSize'          : 16
    }
});

Returns this

addMarker(marker)

add more markers

  • marker Marker[] markers to add

Returns this

toJSON()

export the layer's JSON.

var json = clusterLayer.toJSON();

Returns Object

Contributing

We welcome any kind of contributions including issue reportings, pull requests, documentation corrections, feature requests and any other helps.

Develop

The only source file is index.js.

It is written in ES6, transpiled by babel and tested with mocha and expect.js.

Scripts

  • Install dependencies
$ npm install
  • Watch source changes and generate runnable bundle repeatedly
$ gulp watch
  • Tests
$ npm test
  • Watch source changes and run tests repeatedly
$ gulp tdd
  • Package and generate minified bundles to dist directory
$ gulp minify
  • Lint
$ npm run lint

maptalks.markercluster's People

Contributors

fomoire avatar fuzhenn avatar heqinghuanb avatar liubgithub avatar ray93 avatar ryfilucy avatar wsw0108 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maptalks.markercluster's Issues

请问_initGridSystem是不是有问题?

_class.prototype._initGridSystem = function _initGridSystem() {
var points = [];
var extent = void 0,
extent_1 = void 0,
c = void 0;

    this.layer.forEach(function (g) {
        if (!g.isVisible()) {
            return;
        }
        c = g._getPrjCoordinates();
        if (!extent) {
            extent = g._getPrjExtent();
            extent_1=g.getExtent();
        } else {
            //这里用投影的Extent做合并,并不是想要的结果,我理解extent是不是应该和extent_1是对应的extent 是投影坐标,extent_1是经纬度,但我这里测试了,并不对应
            extent = extent._combine(g._getPrjExtent());       
            extent_1=extent_1._combine(g.getExtent());        
        }
          
        points.push({
            x: c.x,
            y: c.y,
            id: g._getInternalId(),
            geometry: g
        });
    });
    this._markerExtent = extent;
    this._markerPoints = points;

}

在_combine方法中
this.projection.project({x:-13720.015920780175,y:6715329.280305414})={x:-1527305185.9768558,y:20037508.34278074}

this.projection.unproject({x:-1527305185.9768558,y:20037508.34278074})={x:-40.01592078017529,y:85.0511287798}

不是原来的坐标了

在生产环境中聚合图层和添加到聚合图层中的所有marker同时显示出来, 在开发环境中又是正常的

在生产环境中聚合图层和添加到聚合图层中的所有marker同时显示出来, 在开发环境中又是正常的,
初始化聚合图层的代码:

  new ClusterLayer('cluster', [], {
          zIndex: 100,
          noClusterWithOneMarker: false,
          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,
      })

添加marker的代码

 if (isArray(data) && !isEmpty(data)) {
        const markerImg = require('@jdhnw/assets/images/dashboard/soil-position-blue.png')
        const markers = []
        data.forEach((m) => {
          const { latitude, longitude, status, id } = m
          const point = new maptalks.Marker([longitude, latitude], {
            id,
            symbol: [
              {
                markerFile: markerImg,
                markerWidth: 46,
                markerHeight: 32,
              },
            ],
          })
          point.on('click', () => {
            this.map.setCenter([longitude, latitude])
            this.$nextTick(() => {
              const { soildMapDialogRef } = this.$refs
              soildMapDialogRef.open({ type: 'ID', data: { cropCateId: this.filter.cropCategory, quotaDataId: m.id } })
            })
          })
          markers.push(point)
          // 添加聚合图层
          this.clusterLayer.addMarker(point)
          console.log('添加聚合图层: ', point)
        })
        this.map.addLayer(this.clusterLayer)
      }

聚合插件不能正常使用

我在地图初始化完成之后创建了一个Cluster图层,并添加到map上,然后在请求到数据之后添加到Cluster图层中之后,只有第一次能正常显示,当我进行缩放之后,聚合图层就会不显示了,只有在缩放过程中会显示,缩放完成就没了。并且会报错,见下图:

http://p7wghdplg.bkt.clouddn.com/code1.png
http://p7wghdplg.bkt.clouddn.com/code2.png
http://p7wghdplg.bkt.clouddn.com/error.png
http://p7wghdplg.bkt.clouddn.com/error2.png

  • 效果GIF: 好像gif放不上来,链接:http://p7wghdplg.bkt.clouddn.com/gif.gif
    http://p7wghdplg.bkt.clouddn.com/gif.gif

How to add altitude for cluster layer or directly cluster itself

Hi there. I have maptalks with drawn 3d polygons through three layer, and than only needs to add markers and clusters with altitude above them. I spent a week to understand how to add altitude for clusters, delved all sources for markercluster and maptalks, but anyway couldn't get it. Could you explain to me how to do that or point to a way?

聚合动画

设置聚合动画效果的时候,不在聚合内的marker能否不加动画显示效果?

最新版maptalks地图会使聚合失效

"maptalks": "^1.0.0-rc.29",
"maptalks.markercluster": "^0.8.5",
该版本maptalks会使地图上应当聚合的marker以及聚合后的marker同时出现在地图上

vue引入聚合报错

[Vue warn]: Error in nextTick: "TypeError: _maptalks3.Clusterlayer is not a constructor"

请问如何给每个聚合点初始化开始的值

每个聚合点有个初始数字,比如10,100啥的。 然后在聚合的时候,需要把这个初始值进行累加得出聚合后的数量,但目前聚合图层只是简单的累加marker点的数量。 请问有没有方法能够实现这样的需求呢?

No cluster spiderfication?

Leaflet has a really nice marker clusterer that offers the ability to spidery the markers in a cluster when the cluster icon is clicked/tap. How, if at all possible, can this be done with the Maptalks Clusterer?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.