<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css">
<!-- BASE - this example uses relative URLs -->
<base href="https://raw.githubusercontent.com/heremaps/jsfiddle-github/master/map-object-events-displayed/" />
<!-- SCRIPTS -->
<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>
<!-- BODY -->
<h1>Map Objects Events</h1>
<p>This example shows how to attach listeners to pointer events such as <code>pointerup</code>, <code>pointerdown</code> and <code>tap</code> to various map objects.</p>
<hr/>
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
/**
* Shows how to subscribe to different event type on different map objects
*
* @param {H.Map} map A HERE Map instance within the application
* @param {Function} logEvent Custom function for logging events
*/
function testObjectsEvents(map, logEvent) {
// Let's create the same style for all objects
var style = {
fillColor: 'rgba(35, 51, 129, 0.3)',
lineWidth: 5,
strokeColor: 'rgba(114, 38, 51, 1)'
};
// Create a rectangle map object
var rect = new H.map.Rect(new H.geo.Rect(
51.5072, 0, 48.8567, 2.3508
), {style: style});
// Create a circle map object
var circle = new H.map.Circle(
new H.geo.Point(52.3667, 4.9000), //center
198000, // Radius in meters
{style: style}
);
// Create a polyline map object
var polyline = new H.map.Polyline(new H.geo.Strip([
52.5167, 13.3833, 0,
50.0833, 14.4167, 0,
52.2333, 21.0167, 0
]), {style: style});
var svg = '<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
'<circle cx="10" cy="10" r="9" stroke="#fc3" stroke-width="2" fill="#8ac2b0" />' +
'</svg>';
var icon = new H.map.Icon(svg);
polyline.routeHoverMarker = new H.map.Marker({lat: 52.5167,lng:13.3833}, {
icon: icon,
visibility: false,
zIndex: 1
});
// Create a polygon map object
var polygon = new H.map.Polygon(new H.geo.Strip([
45.4667, 9.1833, 0,
48.1333, 11.566, 0,
50.0800, 8.2400, 0,
]), {style: style});
// Create a standard marker
var standardMarker = new H.map.Marker(new H.geo.Point(48.2000, 16.3667));
// Create image marker object
var imageMarker = new H.map.Marker(new H.geo.Point(53.5653, 10.0014), {
icon: new H.map.Icon('img/marker-house.png')
});
// Let's give names to our objects and save it as data
rect.setData('Rect');
circle.setData('Circle');
polyline.setData('Polyline');
polygon.setData('Polygon');
standardMarker.setData('Standard...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.