JS Marker Clusterer Helper: Display markers on a map that may show as clusters

Recommend this page to a friend!
     
  Info   Example   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 19 All time: 535 This week: 4Up
Version License JavaScript version Categories
markerclustererhelpe 1.0MIT/X Consortium ...5HTML, Geography
Description 

Author

This package can display markers on a map that may show as clusters.

It can display a map inside a given page element using the Google Maps API.

The map may show markers that may be clustered and show a single marker when markers that are grouped are very close to each other.

Picture of Andras Toth
  Performance   Level  
Name: Andras Toth <contact>
Classes: 22 packages by
Country: Hungary Hungary
Age: 51
All time rank: 31 in Hungary Hungary
Week rank: 1 Up
Innovation award
Innovation award
Nominee: 15x

Winner: 9x

Example

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Demo</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> <style type="text/css"> #bound-list li { cursor: pointer; } </style> </head> <body> <div class="w3-row w3-padding w3-xlarge w3-blue"> <div class="w3-half"> <div class="w3-bar"> <a href="https://atandrastoth.co.uk/main/pages/plugins" class="w3-bar-item w3-button w3-hover-red"><i class="material-icons" style="line-height: 1.6;">arrow_back</i></a> <a href="https://github.com/andrastoth/markerClustererHelper" class="w3-bar-item w3-button w3-hover-light-blue">GitHub</a> <a href="https://www.jsclasses.org/browse/author/12833.html" class="w3-bar-item w3-button w3-hover-light-blue">JS Classes</a> </div> </div> <div class="w3-half"> <h3 class="w3-right">MarkerClustererHelper</h3> </div> </div> <div class="w3-row w3-margin"> <h1 class="w3-center">MarkerClustererHelper</h1> </div> <div class="w3-container w3-margin-top"> <div class="w3-container w3-center"> <h3>Simple initialization</h3> <p>With default values</p> </div> <div class="w3-row w3-row w3-center"> <div class="w3-content w3-card" style="max-width:500px"> <div id="map" style="height: 480px;width:500px;position: relative;overflow: hidden; max-width: none;"></div> </div> </div> <div class="w3-container w3-center"> <h3>Advanced initialization</h3> <p>With optional values and functions</p> </div> <div class="w3-row w3-card"> <div class="w3-quarter w3-row"> <ul id="bound-list" class="w3-ul w3-hoverable" style="height: 480px; overflow-y: scroll;"> </ul> </div> <div class="w3-half w3-row"> <div id="map1" style="height: 480px;position: relative;overflow: hidden; max-width: none;"></div> </div> <div id="result-content" class="w3-quarter w3-container"> </div> </div> <div class="w3-card"> <select id="country-select" class="w3-select"></select> </div> </div> <br> <script type="text/javascript" src="js/markerClustererHelper.js"></script> <script type="text/javascript" src="js/index_html.js"></script> <script type="text/javascript" src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script> <script type="text/javascript" async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=init"></script> </body> </html>

Details

MarkerClustererHelper

N|Link

MarkerClusterer Helper help to you to create markerclusterer map in a five minutes.

- Simple initilazation - Simple configuration - You can manage multiple maps

N|Icon

Version

1.0.0 - 2017-12-19

Initilazation - html -Javascript

<div id="map" style="height: 480px;width:500px;position: relative;overflow: hidden;"></div>

<script type="text/javascript" src="js/markerClustererHelper.js"></script>
<script type="text/javascript"">
function init() {
    var options = {
        service: {
            url: 'locations.txt', // required JSON array from file or service
        }
    };
    MarkerClustererHelper.create(options);
}
</script>
<script type="text/javascript" src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<script type="text/javascript" async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=init"></script>

Object structure

var location = {
	// number: unique identity
    id: 0,
    // number: assigned to images => options.imagePath 'p' + type + '.png' (marker groups: options.imagePath m1.png, m2.png ...)
    type: 0, 
    // latitude  
    lat: 0,
    // longitude
    lng: 0,
    /*
        your properties
    */
};

Default options

var def = {
    selector: '#map',
    imagePath: 'img/',
    service: {
        url: 'locations.txt',
        token: {
            name: '',
            value: ''
        }
    },
    defaultCountry: '',
    zoom: 7,
    maxZoom: 14,
    gridSize: 60,
    onLoaded: function(helper) {},
    onMarkerClicked: function(location) {},
    onMarkerHover: function(location) {
        return ['<h3 style="display: initial;">id: ', location.id, '</h3><div>type: ', location.type, '</div><div>lat: ', location.lat, '</div><div>lng: ', location.lng, '</div>'].join('');
    },
    onBoundsChnaged: function() {},
    onError: function(e) {
        console.error(e);
    }
}

Usage - methods

// create map
MarkerClustererHelper.create(options); 
// destroy map - identity: index or queryselector for map 
MarkerClustererHelper.destroy(identity);
// get helper for map - identity: index or queryselector for map 
MarkerClustererHelper.map(identity);
// set center on map arg: string Country name or City name etc. or index (location.id) or lat-lng object
MarkerClustererHelper.map(identity).setCenter(arg);
// set zoom number
MarkerClustererHelper.map(identity).setZoom(arg);
// select location, arg: location.id
MarkerClustererHelper.map(identity).setSelected(arg);
// clear selected state
MarkerClustererHelper.map(identity).clearSelected();
MarkerClustererHelper.map(identity).redraw();
// clear all locations from map
MarkerClustererHelper.map(identity).clear();
// reload 
MarkerClustererHelper.map(identity).reload();
// load more, based on service opject: service: {url: 'URL', (optional)token: { name: '', value: '' } } or location array
MarkerClustererHelper.map(identity).load(service);
// returns locations array
MarkerClustererHelper.map(identity).getLocations();
// returns visible locations array
MarkerClustererHelper.map(identity).getVisibleLocations();
// returns helper options
MarkerClustererHelper.map(identity).options;

License

MIT

Author: Tóth András

http://atandrastoth.co.uk/


  Files folder image Files (30)  
File Role Description
Files folder imageimg (11 files)
Files folder imageimg2 (12 files)
Files folder imagejs (2 files)
Accessible without login Plain text file index.html Example Example page
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file locations.txt Doc. Documentation
Accessible without login Plain text file locations2.txt Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (30)  /  img  
File Role Description
  Accessible without login Image file loading.gif Icon Icon image
  Accessible without login Image file m1.png Icon Icon image
  Accessible without login Image file m2.png Icon Icon image
  Accessible without login Image file m3.png Icon Icon image
  Accessible without login Image file m4.png Icon Icon image
  Accessible without login Image file m5.png Icon Icon image
  Accessible without login Image file p1.png Icon Icon image
  Accessible without login Image file p2.png Icon Icon image
  Accessible without login Image file p3.png Icon Icon image
  Accessible without login Image file p4.png Icon Icon image
  Accessible without login Image file p5.png Icon Icon image

  Files folder image Files (30)  /  img2  
File Role Description
  Accessible without login Image file loading.gif Data Auxiliary data
  Accessible without login Image file m1.png Icon Icon image
  Accessible without login Image file m2.png Icon Icon image
  Accessible without login Image file m3.png Icon Icon image
  Accessible without login Image file m4.png Icon Icon image
  Accessible without login Image file m5.png Icon Icon image
  Accessible without login Image file p1.png Icon Icon image
  Accessible without login Image file p2.png Icon Icon image
  Accessible without login Image file p3.png Icon Icon image
  Accessible without login Image file p4.png Icon Icon image
  Accessible without login Image file p5.png Icon Icon image
  Accessible without login Image file p6.png Icon Icon image

  Files folder image Files (30)  /  js  
File Role Description
  Accessible without login Plain text file index_html.js Aux. Auxiliary script
  Plain text file markerClustererHelper.js Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:19
This week:0
All time:535
This week:4Up