Coder Social home page Coder Social logo

googlearchive / js-marker-clusterer Goto Github PK

View Code? Open in Web Editor NEW
1.3K 86.0 776.0 625 KB

A marker clustering library for the Google Maps JavaScript API v3.

Home Page: https://googlemaps.github.io/js-marker-clusterer/docs/reference.html

License: Apache License 2.0

JavaScript 100.00%

js-marker-clusterer's Introduction

Please note: This repository is kept for historical purpose only - the current version of marker clusterer is available as part of the v3-utility-library repository.

Marker Clusterer โ€“ A Google Maps JavaScript API utility library

A Google Maps JavaScript API v3 library to create and manage per-zoom-level clusters for large amounts of markers. Analytics

Reference documentation

Migrated from the Google Maps JavaScript API utility libraries on Google Code.

Usage

Download or clone markerclusterer.js and images m1.png to m5.png, save images in images folder.

To use your own custom cluster images just name your images m[1-5].png or set the imagePath option to the location and name of your images like this: imagePath: 'customImages/cat' for images cat1.png to cat5.png.

index.html

...

<div id="map-container"><div id="map"></div></div>
<script src="markerclusterer.js"></script>
<script>
    function initialize() {
        var center = new google.maps.LatLng(51.5074, 0.1278);

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 3,
          center: center,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var markers = [];
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(51.5074, 0.1278)
        });
        markers.push(marker);

        var options = {
            imagePath: 'images/m'
        };

        var markerCluster = new MarkerClusterer(map, markers, options);
    }

    google.maps.event.addDomListener(window, 'load', initialize);
</script>
...

Live Demos

Marker Clusterer Screenshot

Examples page

Contributing

Want to contribute? Check out the contributing guide!

License

Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

js-marker-clusterer's People

Contributors

amuramoto avatar brendankenny avatar broady avatar fritz-c avatar justinkwanlee avatar kukkimonsuta avatar markmcd avatar masone avatar petertheone avatar remo avatar skaree avatar stephenmcd avatar zessx 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  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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

js-marker-clusterer's Issues

Icons at same location

Hello, thanks for the demos for markerCluterer.

I am facing an issue when I have 2 or more icons at the same location (same coordinates). In this case the markerer show only the icon with the number and it is not possible to see the icons inside, is there a solution for this??

Thanks

Cluster disappears when markers at the same position

If I have a couple markers at the same location, clicking on the cluster zooms in, and a second click makes the cluster disappear.

To reproduce, you can use the simple_example.html, and just change:

var markers = [];
for (var i = 0; i < 100; i++) {
  var dataPhoto = data.photos[i];
  var latLng = new google.maps.LatLng(dataPhoto.latitude,
      dataPhoto.longitude);
  var marker = new google.maps.Marker({
    position: latLng
  });
  markers.push(marker);
}

To:

var markers = [];
var dataPhoto = data.photos[0];
for (var i = 0; i < 100; i++) {
  var latLng = new google.maps.LatLng(dataPhoto.latitude,
      dataPhoto.longitude);
  var marker = new google.maps.Marker({
    position: latLng
  });
  markers.push(marker);
}

Result

Before click:
image

After click:
image

Disable number display

Hi!

Is there a way to turn off the numbers being display in the cluster? I'd like to use the images only.

markers_ undefined

On line 1015 there is a markers_ variable which is not defined, should be markers without _.

regards,
Tom

Not working on IE11

Looks like the MarkerClusterer is not working on IE11. I tried my own code and the Google examples.

A small performace suggestion

In MarkerClusterer.prototype.calculator_ there is a while loop. It seems to calculate the "magniitude" of the markers cluster length as a power of 10, giving "1" for 1 to 9, "2" for 10 to 99, "3" for 100 to 999... and so on:

function(markers, numStyles) {
var index = 0;
var count = markers.length;
var dv = count;
while (dv !== 0) {
dv = parseInt(dv / 10, 10);
index++;
}
...

Couldn't be faster just to count the characters in a decimal string?

function(markers, numStyles) {
index=markers.length.toString(10).length;
...

crash on big data

Hi.
i use only about 100,000 marker, but it's crash the browser!!

Clicking on cluster icon in Google Chrome not working

With the latest version of Google Chrome, clicking on a cluster icon has no affect. I believe this is down to a recent change that is meant to prevent the cluster click event from firing if a drag is taking place. To demonstrate the problem, check out the maps on the examples page.

Commenting out...

if (!isDragging) { that.triggerClusterClick(event); }

And just replacing it with:

that.triggerClusterClick(event);

Fixes the issue. I guess there may be a problem with the code that sets "isDragging"?

Own icons at max zoom

Hi,

I am currently using you api to provide status for some locations. I would like to use two "own" icons insted of the genereic marker from googles api. Is there an easy solution for doing such an event?

With kind regards,
Henning

Info Window not opening in correct location

When marker clusterer is enabled and an info window is dynamically populated using setContent(), the info window opens up in the upper left hand corner instead of being positioned near the marker:

$gmap.map = new google.maps.Map(document.getElementById('map'), {...});
$gmap.infoWindow = new google.maps.InfoWindow();
/* Push some markers to $gmap.markers */
$gmap.clusterer = new MarkerClusterer($gmap.map, $gmap.markers);
...
marker = $gmap.markers[0];
$gmap.infoWindow.setContent('Test');
$gmap.infoWindow.open($gmap.map, marker);

The interesting thing is, if I comment out setContent() then the info window shows up next to the marker. If I comment out new MarkerClusterer(), then the info window shows up correctly regardless.

Marker Clustering taking Longer time on chrome

Hi,

I am facing a unusual problem in marker clustering.
From last three years I am using this library but from last couple of weeks my application takes a huge time to clustering the points and visualize on to the google maps API V3 in Google chrome (browser). This issue occurs only in Google chrome (browser) but in other browsers such as Firefox it works fine, that's why I cannot understand what is the issue.

So kindly help me what wrong I had done.

Application URL: http://maps.dicrc.in/BM/

Chrome Version 50.0.2661.102 m
Google API v3
Fusion Table V2

Thanks and Regards
Piyush

Where to place code

I have already created my map via excel import and am wondering where I now place this code to implement the markerculsterer. In other words, when I have Developer view open, what do I place where? (All of the forums I've searched seem to assume a basic understanding of where you input this code to run it, but I am missing this piece of understanding.)

Thanks!

.setMap(null) error

I get this error when I try to disable the marker clusterer overlay:

var markerCluster = new MarkerClusterer(map, markers);
...
markerCluster.setMap(null);

Console output:

Uncaught TypeError: this.remove is not a function (js?libraries=places:36)
Uncaught TypeError: this.remove is not a function (overlay.js:1)

More diverse cluster sizes

I am current using this library on an application I am creating. It works so well! However, I am having issues separating the size of the clusters. You can tell a difference between ex. 300, 20, and 2. However, I when I am at a zoom level with smaller clusters, I would like to be able to tell the different, in size, between ex. 15, 10, and 5. Currently numbers this close, display at the same size.

Could anyone provide guidance with this problem?

Click event on ClusterIcon can't be stopped from propagating.

I have a map with clustered icons where I have registered click event for whole map and for each marker. To capture clicks on clustered markers I have also registered clusterclick listener that shows window info.

When I click cluster icon, window info is shown but in addition also map's click event is triggered. This is in contrast to ordinary markers, where click only shows window info but stops propagate event to the map.

As a workaround I have implemented simple quick fix in sodik82@a6ce478 but maybe more proper solution can be implemented (via property or something else - pass event to clusterclick callback function?)

Cluster icon on click zooms out, Internet Explorer only

Case: http://kort.danskelbilalliance.web01.cabana.dk/

MarkerClusterer initialize code:

_markerClusterer = new MarkerClusterer(map, markers, {
    maxZoom: 15,
    gridSize: 60,
    styles: [{
        url: '/resources/img/DanskElbilAlliance/m1.png',
        height: 53,
        width: 52,
        //anchor: [16, 0],
        textColor: '#ffffff',
        textSize: 10
    }, {
        url: '/resources/img/DanskElbilAlliance/m2.png',
        height: 56,
        width: 55,
        //anchor: [24, 0],
        textColor: '#000000',
        textSize: 11
    }, {
        url: '/resources/img/DanskElbilAlliance/m3.png',
        height: 66,
        width: 65,
        //anchor: [32, 0],
        textColor: '#ffffff',
        textSize: 12
    }, {
        url: '/resources/img/DanskElbilAlliance/m4.png',
        height: 78,
        width: 77,
        //anchor: [32, 0],
        textColor: '#ffffff',
        textSize: 13
    }, {
        url: '/resources/img/DanskElbilAlliance/m5.png',
        height: 90,
        width: 89,
        //anchor: [32, 0],
        textColor: '#ffffff',
        textSize: 14
    }]
});

Anyone has an idea what's going on?

Where is MarkerClustererPlus?

Is this planned for a dedicated repo on github? For now we are using curl to point to google code to pull in plus, MarkerLabel, KeyDragZoom, and InfoBox. Again will these have repos as well?

Doesn't de-cluster at max zoom, instead cluster vanishes

I tried both MarkerClusterer and MarkerClustererPlus and when I have two markers very close to one another problems arise. I keep clicking the cluster until I reach the max zoom. The next click will either do nothing to the cluster icon or remove it and not show the individual markers. I noticed the Leaflet clusterer de-clusters the markers and has lines that lead to their point of origin, so they decluster cleanly.

Any chance of fixing this to at least de-cluster at max zoom? I tried implementing it myself, but I don't know how this is achieved since each tile potentially has it's own maxZoom. The library's maxZoom property doesn't help at all when switching from Maps to Satelite, which has a much lower maxZoom in general. I found the API's "maxZoomService" but I don't want to query that for every action to see if I need de-cluster. Ideas would be greatly appreciated.

Accessing images via http

Currently, the images are accessed via http instead of https that causes warnings at some browsers, especially when the website is visited via https. Please consider changing the url in the following code at src/markerclusterer.js:

/**
 * The marker cluster image path.
 *
 * @type {string}
 * @private
 */
MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_ =
    'http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/' +
    'images/m';

Duplicate Clusters

image

Notice i only have 4 markers, and the clusters have two groups of 4. I added a debug console log to count the amount of markers created, at each zoom level only 9 are created in this image total for both zoom levels.

font-family and font-weight are static

font-family and font-weight from Cluster are static.
See: Line 1237

I added "fontFamily" and "fontWeight" in my Project (like http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/docs/reference.html#ClusterIconStyle).

My changed code snippets:

var style = this.styles_[index];
this.url_ = style['url'];
this.height_ = style['height'];
this.width_ = style['width'];
this.textColor_ = style['textColor'];
this.anchor_ = style['anchor'];
this.textSize_ = style['textSize'];
this.fontFamily_ = style['fontFamily'];  //added
this.fontWeight_ = style['fontWeight'];  //added
var txtColor = this.textColor_ ? this.textColor_ : 'black';
var txtSize = this.textSize_ ? this.textSize_ : 11;
var fontFamily = this.fontFamily_ ? this.fontFamily_ : 'Arial,sans-serif';  //added
var fontWeight = this.fontWeight_ ? this.fontWeight_ : 'bold';  //added

style.push('cursor:pointer; top:' + pos.y + 'px; left:' +
      pos.x + 'px; color:' + txtColor + '; position:absolute; font-size:' +
      txtSize + 'px; font-family:'+fontFamily+'; font-weight:'+fontWeight);   //changed

Cluster context

There's any possibility of getting the markers inside a cluster? I've looked everywhere and couldn't find anything.

Can you add composer.json?

Hello,
it would be cool, if we could use this library as dependency via composer. I think its not a big deal to add composer.json :)

Thx

Images when viewed from China

Hi,

I'm trying to use the Marker Clusterer to group locations in China, with a mixed success. The clustering works, but the image around the number (blue, yellow, red circles) does not work. See an example here: http://screencast.com/t/EonYiTaKQ

Assumption is that the images are being hosted on a server that is blocked in China, which is why they don't show up. Is it possible to define your own images or have them hosted elsewhere or...?

Thanks for the assistance, great product!

Marko

stopPropagation

Thanks for the plugin. It's great! It seems, however, that your click event does not have a stopPropagation() function. In my implementation I need to stop propagation on the clusterclick event. I wound up modifying your code to always stopPropagation based on a suggestion in stack overflow:

http://stackoverflow.com/questions/2881150/google-map-api-v3-event-click-raise-when-clickingmarkerclusterer @satyrFrost .

It would be great if you could implement a stopPropagation() method if there is enough demand.

Thanks

Event clusteringend not working

ive updeted to newst version and now the event
google.maps.event.addListener(this.markerCluster, 'clusteringend', function () {

is not working. In my old 2.0.9 [February 20, 2012] it is working.

Info Window closing when zooming out

There are cases where the Info Window is closing automatically when you zoom out of a map with many marker clusters. Please make it stay open.

Cluster icon location incorrect to most markers

I've found that the calculation(?) of the location of the cluster icon to be incorrect at times. I've attached two screenshots.
Map1 = you can see 28 locations at the Oklahoma and Arkansas border (which is incorrect). Only ONE location is near there.
Map 2 = shows the zoom when clicking on Map1 ("28" icon). Notice that the Clusterer placed the cluster icon near the Ft. Smith (far left) marker, instead of where it should, either a)..centrally located among all 28 locations, or b)..at the next-largest-cluster (26). Ideally, the cluster icon position needs to be central to all the underlying markers. It looks like it's just choosing a random marker position to represent its location?

Map1 incorrectly shows all the locations too far west Arkansas, whereas 90% of them are exactly central Arkansas.
map1
map2

Hide cluster dynamically once all markers are hidden

I'm using a toggle button to hide/show certain markers. Those that are part of a cluster have a problem. If I dyncamically hide marker.setVisible(false/true) all markers of a cluster the cluster stays visible.

I tried to call redraw and repaint, but both methods don't seem to consider the visibility of the marker. Any ideas about the correct way to do that?

Adding your own calculator, correct method?

A little confused about overriding the calculator...

should it be as per the example here http://gmaps-utility-library-dev.googlecode.com/svn/trunk/markerclusterer/examples/simple_example_with_values.html

eg passed in as a option on instantiation..
var markerCluster = new MarkerClusterer(map, markers, {'calculator': average});

or using the
markerCluster.setCalculator(function(markers, numStyles) {...});

I couldn't seem to get the example method to work, but assume there might be an overhead setting after instantiation?

ReferenceError: markers_ is not defined

Uncaught ReferenceError: markers_ is not defined
Cluster.updateIcon @ markerclusterer.js:1015
Cluster.addMarker @ markerclusterer.js:880
MarkerClusterer.addToClosestCluster_ @ markerclusterer.js:764
MarkerClusterer.createClusters_ @ markerclusterer.js:788
MarkerClusterer.redraw @ markerclusterer.js:709
(anonymous function) @ markerclusterer.js:174
_.H.trigger @ js:85
(anonymous function) @ map.js:13
_.H.trigger @ js:85
rb @ js:33
_.t.set @ js:87
Oz.R @ map.js:34

https://github.com/googlemaps/js-marker-clusterer/blob/gh-pages/src/markerclusterer.js#L1015

Repro at https://googlemaps.github.io/js-marker-clusterer/examples/simple_example.html

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.