• JavaScript
  • HTML
                  
                  
    
function orderMarkers() {
  var zIndex = 1,
      // create a set of markers
      marker = new mapsjs.map.Marker(
        {lat: 52.508249, lng: 13.338931}
      ),
      marker2 = new mapsjs.map.Marker(
        {lat: 52.506682, lng: 13.332107}
      ),
      marker3 = new mapsjs.map.Marker(
        {lat: 52.503730, lng: 13.331678}
      ),
      marker4 = new mapsjs.map.Marker(
        {lat: 52.531, lng: 13.380}
      );

  // add markers to the map
  map.addObjects([marker, marker2, marker3, marker4]);

  map.addEventListener('tap', function (evt) {
    if (evt.target instanceof mapsjs.map.Marker) {
      // increase z-index of the marker that was tapped
      evt.target.setZIndex(zIndex++);
    }
  });
}

/**
 * Boilerplate map initialization code starts below:
 */

// initialize communication with the platform
var platform = new H.service.Platform({
  app_id: window.app_id,
  app_code: window.app_code,
  useHTTPS: true
});
var pixelRatio = window.devicePixelRatio || 1;
var defaultLayers = platform.createDefaultLayers({
  tileSize: pixelRatio === 1 ? 256 : 512,
  ppi: pixelRatio === 1 ? undefined : 320
});

var map = new H.Map(document.getElementById('map'),
  defaultLayers.normal.map,{
  center: {lat: 52.5, lng: 13.4},
  zoom: 10,
  pixelRatio: pixelRatio
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());


// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));


// Now use the map as required...
orderMarkers();                  
                
                  
                  
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    
    <title>Ordering Overlapping Markers</title>
    <link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
    <link rel="stylesheet" type="text/css" href="demo.css" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <link rel="stylesheet" type="text/css" href="../template.css" />
    <script type="text/javascript" src='../test-credentials.js'></script>
    <script type="text/javascript" src='../js-examples-rendering-helpers/iframe-height.js'></script> 
    <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
  </head>
  <body id="markers-on-the-map">
    <div class="page-header">
        <h1>Ordering Overlapping Markers</h1>
        <p>Arrange the order in which a series of map objects are displayed</p>
    </div>
    <p>This example shows how to arrange the visibility order of markers by clicking them. Zoom in and out to overlap markers and try re-arranging them.</p>
    <div id="map"></div>
    <h3>Code</h3>
    <p>This example uses marker's z-index value to set its rendering order.</p>
    <script type="text/javascript" src='demo.js'></script>
  </body>
</html>