Giter Club home page Giter Club logo

gmaps-marker-clusterer's Introduction

GitHub version npm version License License: CC BY-SA 4.0 vsts build status

Please note: This is a fork of the js-marker-clusterer library, the original repository can be found here https://github.com/googlemaps/js-marker-clusterer

Logo

Gmaps Marker Clusterer

A JavaScript API utility library for Google Maps

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

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>

Custom CSS

Customize the cluster pins by using the cssClass-option.

Adding a custom CSS-Class custom-pin to the options:

var center = new google.maps.LatLng(37.4419, -122.1419),
    map = new google.maps.Map(document.getElementById('map'), {
        zoom: 3,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }),
    markers = [],
    options = {
        cssClass: 'custom-pin'
    };

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);
}

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

Add your custom styles:

.custom-pin {
    height: 1em;
    line-height: 1;
    width: 1em;
    padding: .7em;
    text-align: center;
    cursor: pointer;
    color: white;
    background: black;
    position: absolute;
    border-radius: .5em;
    font-size: 1em;
    font-weight: bold;
    transition: all 500ms;
}

.custom-pin::after {
    content: '';
    border-width: 1em .5em;
    border-color: black transparent transparent transparent;
    border-style: solid;
    position: absolute;
    top: 99%;
    left: calc(50% - .5em);
}

.custom-pin:hover {
    transform: scale(1.15);
}

Have a look at the custom-css example.

Live Demos

Marker Clusterer Screenshot

Examples page

License

All code is licensed under Apache 2.0. See LICENSE-File.

The gmaps-marker-clusterer Logo is licensed under CC BY-SA 4.0. CC BY-SA 4.0

gmaps-marker-clusterer's People

Contributors

brendankenny avatar broady avatar crismethods avatar cristofer avatar fritz-c avatar jonatanaxe avatar justinkwanlee avatar kukkimonsuta avatar markmcd avatar masone avatar mbrezovsky avatar mgibbs189 avatar petertheone avatar remo avatar rognstad avatar skaree avatar stephenmcd avatar vhstrejo avatar xmlmxmlmx 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmaps-marker-clusterer's Issues

Poor performance in IE11

Hey guys!

We are using your library for thousands of markers at once, some clusters have 2k or more (zoom level 2), and we have experienced poor performances when using IE11, compared with Chrome and FF in IE it took up to 3 times for finishing loading the markers into the clusters. We are wondering if you could give us some advises in order to set maybe some parameters in order to achieve similar times between these three browsers.

Thanks in advance!

Cluster css classes based on cluster range.

Is it possible to add additional classes to the cluster pin based on a cluster size range that mirrors the way images are being used in the advanced example?

https://gmaps-marker-clusterer.github.io/gmaps-marker-clusterer/advanced-example/

It seems like all the images for the various representations of these ranges (e.g from m1.png through to m5) have been added inline so there's no easy way to try and mimic this with a css only approach if we were going for something basic like a simple circle or something that's shown in the custom-pin example.

Order of gestureHandling and cluster icons (z-index)

I found an usability issue due to order of gestureHandling and cluster icons.

By dragging the map with only one finger you receive a message Γ‘ la "Move the map with two fingers" (in german "Verschieben der Karte mit zwei Fingern"). As you can see, the order of this hint message and cluster icons is not correct - cluster icons are on the top, but I think the hint message should be on the top.

However, it's possible to style the hint message with CSS class .gm-style-pbt, but no z-index property can fix this problem.

Any ideas?

screenshot_2017-04-28-09-02-49

Merging pull-requests

Update the Examples

The example pages need to be update as well.

  • All links are referenced to the old repository.
  • The layout and design is very outdated.

Dynamic cluster icon

Hello, I was wondering if it's possible to set the cluster marker icon dynamically depending from the icons of the markers underneath.

Advanced Example: Cannot import multiples coordinates

Hello everyone,

Nice job with the well-documented repository!

I am a rookie, and I have been struggling to import my data (around 200 coordinates (latitude, longitude)) to the advance example you have in the repository.

I copied and pasted the HTML code of the advanced example, but cannot figure out how to import all my coordinates to the code.

I tried putting everything in the following format: "var marker = new google.maps.Marker({position: new google.maps.LatLng(-6.369028, 34.888822)});"

but the map wouldn't get uploaded correnctly.

So basically I wish to have a map with the following effect
cluteringmarker
, but couldn't figure out how to import coordinates.

Thanks in advance!

Marker Clusterer gridSize documentation unhelpful.

The marker clusterer documentation does not clearly defined the gridSize options. By reading the definition one does not understand what is meant by the gridSize and what does it do and how it does it impact the clustering processing.

I still do not have clear idea what does it to and what's its impact.

Looking at the source code I assumed the gridSize increase the area of map shown by the pixel amount set in gridSize but I am not sure.

Integration with agm?

Just wondering if there was an easy way to integrate this into agm's already existing marker clusterer or am I going to have to manually create one?

Overlaying markers over the cluster

In my project I have multiple placemarker types, one of those placemarker types is clustered and another isn't.
I would like to overlay my unclustered placemarkers over the cluster icon as they hold more important information than the cluster.

I see this is not currently possible as cluster icons are added to the overlayMouseTarget

this.getPanes().overlayMouseTarget.appendChild(this.div_);

Is there any workaround I can do?

setting cssClass results in no markers displayed

When I define the cssClass option, no cluster markers are rendered?

(According to the documentation the cssClass should be set in the styles option. Looking at the source it expects the cssClass value in the options object.)

var opts = {
        styles: [{
          'url': 'http://example.com/example.png',
          'height': 40,
          'width': 40,
          'anchor': [0,0],
          'textColor': '#fff',
          'textSize': 12,
          'backgroundPosition': '0,0'
        }],
        cssClass: 'my-cool-css-class',
        zoomOnClick: true
      };

Usage of ignoreHiddenMarkers

Hi,
I was wondering how the option ignoreHiddenMarkers ist meant to work.
For one of our projects this looks promising, but I'm not sure what counts as a 'hidden' marker. Hidden by CSS? Or visibility set to hidden with an option?

Thanks a lot
Philipp

Update the Documenation

The documentation needs a update.

  • All links are referenced to the old documentation.
  • The layout and design is very outdated.

Maybe a additional branch for a GitHub Page would be useful, to host the documentation and the examples #5?

Documentation: Please add a note about the repaint method and using it when your markers change position frequently

I think the new documentation looks much nicer! Would you please add a note about the repaint method? It's very useful for maps that have moving markers (e.g. vehicles). Calling resetViewport() and redraw() works, but causes the clusters to flicker during each update. repaint() largely avoids this (and can probably totally do so if someone uses cluster images without transparency).

Calculate number of child markers per cluster

I found your library while searching for a way to use my own CSS for styling marker clusters. I'm looking to add a dynamic class (e.g. marker-cluster-small or marker-cluster-large) based on how many markers are in each respective cluster. Leaflet offers a nice method that returns the child count while instantiating the clusterer. Do you have any suggestions to replicate this type of behavior?

screen shot 2018-11-26 at 3 34 37 pm

Zooming while clusters render causes map to freeze

Hello,
I am using the gmaps-marker-clusterer library (v1.2.0) together with the Google Maps API on an Ionic v1 app to group map markers in clusters based on the zoom level.

I am currently stuck on one particular issue caused by the library (it does not happen when I am not using it) that somehow makes the map freeze on a weird one-finger zoom mode. Essentially, when zooming in or out while the clusters are rendering, the map gets stuck, does not load anymore and instead of rendering new map textures when the user tries to move the centre of the map it just zooms in or out (but without rendering or loading). No error message is being displayed.

All markers (40/50) are loaded together, only once, when the map initialises. This only happens on an actual iPhone device. I have not tested it on Android, but I can say this is not happening while testing the app in the browser. See a screenshot of the frozen map here.

Any idea of what might cause this? Any help would be appreciated!

How to do clustering of circle markers?

Hi,
I'm trying to do clustering of circle markers

var marker =  new google.maps.Circle({
            strokeColor: strokeColor,
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: fillColor,
            fillOpacity: 0.35,
            center: center,
            radius: radius
          }); 

but when I try to cluster,

var markerCluster = new MarkerClusterer(map, marker, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});

It gives me error:
markerclusterer.js:653 Uncaught TypeError: marker.getPosition is not a function

I checked the proto and sure it does not have the getPosition() unlike in case when I create a regular marker like,

var marker = new google.maps.Marker({
            position: location
});

how to get only the markers in a specific cluster?

i want to show some infos of the markers that are in a specific cluster...

afaik the getMarkers function, returns all markers.. i want to get only for example the ones that are inside a cluster i hover over.

Is there a wau to do this? THX.

set zIndex of MarkerClusterer

Hi!!
I have some markers outside of marker clusterer, Is there anyway to set them on the top of markerer cluster icon by using zIndex or something similar?

Marker icon display bugs when setting maxZoom with custom icons

This issue was already posted on the "official" ;) repo, before I realized this one was the one being maintained. Sorry if copy-pasting the issue here is not what I should have done, I'm new to this.

I have a google map where I create markers with custom icons, and there are hundreds of these icons.
I'd like not to cluster them when zooming beyond a certain level, so I tried using the maxZoom option (I have tried values 14, 15 and 16).

Whenever I create multiple markers close to each other at high zoom levels then zoom in and out, graphical bugs start appearing.
So far, here are the bugs I've seen:

  • One or more (sometimes all) markers adopt the same icon, always one of the original icons used for one of the markers
  • Icons do not appear whole
  • Icons are shown multiple times
  • Any combination of the above

I should state that I have no problem whatsoever whenever I simply do not set the maxZoom option.

Here is an example of such a bug (I had to add a marker for the last one to happen) :

capture
capture1
capture2
capture3

In addition, I've noticed a strange behavior that may be linked : whenever i zoom in just enough to de-cluster a cluster (for example by clicking on said cluster), all of the icons appear the same (this happens without the maxZoom option as well).

Any help solving this would be greatly appreciated, thanks for all the hard work and support πŸ‘

Possible grid size bug on smaller screens

I noticed that if you set a large grid size ( 200 ) and navigate to the application with a device that uses a smaller screen such as a phone ( iphone 6s ) the clusters behave strangely. When you click the cluster the first time it recenters the map on that cluster but doesn't zoom or expand the cluster. When you try to click it again the cluster just disappears. If I manually zoom on the map the cluster expands and zooming out makes the cluster appear again.

Thanks!

Problem with offset position when using custom css

I tried using your example class with the custom-pin, but the clusters are all positioned wrong. They're positioned slightly to the left of where they're supposed to be.

There seems to be some issue with the container width while calculating the positions...? I'm not quite sure how the cluster sizes work.. any idea how to get a custom css icon position correctly ? I'm trying to use only a background color for the cluster through the css class.

While in Satellite View marker cluster do not expand

This issue has being reported in the Maps Platform Technical Support.
It looks like while in "Satellite" view, after a certain amount of "zoom" level the marker cluster do not expand, not being able to see the individual markers.

Could you give us any feedback on this?

To reproduce it:

  1. goto: http://www.alaqarie.com/map/show-map (Map view)
  2. make sure the selected Country is UAE
  3. click on the cluster (11), two smaller groups are shown (8) and (2)
  4. Keep on clicking on the groups until all the markers are shown (This is good).
  5. Now, repeate steps 1-4 but after step #1 select (Satellite view)
  6. Notice that expanding the clusters does not expand all the way to show all the markers!

removeMarkers doesn't remove all markers

Hi,
I try to remove all markers in MarkerClusterer, but it doesn't remove all of them.

I think problem could be around this line of code

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

It loops in markers array incrementing the i index, but in removeMarker_ function it performs a splice that changes the length of the array and, then, its indexes.
That causes not all markers will be removed.

Is it only me?

I tried this code:

.....
var markerCluster = new MarkerClusterer(myMap, markers);
.....
markerCluster.removeMarkers( markerCluster.getMarkers() );

Thanks in advance

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.