SVG Graphic Markers
Display a map with custom SVG markers
HTML
<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css">
<!-- 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>SVG Graphic Markers</h1>
<p>This example displays a movable map of <b>Chicago</b> with two individually colored SVG markers highlighting the location of <b>Soldier Field</b> (<i>41.8625°N, 87.6166°W</i>) and <b>Wrigley Field</b> (<i>41.9483°N, 87.6555°W</i>). These locations are the home of the Chicago Bears and Chicago Cubs respectively, and each marker displays the letter <b>C</b> in the correct club colors.</p>
<hr/>
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
CSS
code, h1, h2, h3{
color: #124191;
letter-spacing: -0.03em;
}
body {
font-family:"Lucida Grande",Tahoma,sans-serif;
color: rgb(102, 102, 102);
font-size: 80%;
}
b, strong {
color: black;
}
code {
font-weight: 700;
font-size: 120%;
}
JavaScript
/**
* Adds two SVG markers over the homes of the Chicago Bears and Chicago Cubs
*
* @param {H.Map} map A HERE Map instance within the application
*/
function addSVGMarkers(map){
//Create the svg mark-up
var svgMarkup = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">' +
'<rect stroke="black" fill="${FILL}" x="1" y="1" width="22" height="22" />' +
'<text x="12" y="18" font-size="12pt" font-family="Arial" font-weight="bold" ' +
'text-anchor="middle" fill="${STROKE}" >C</text></svg>';
// Add the first marker
var bearsIcon = new H.map.Icon(
svgMarkup.replace('${FILL}', 'blue').replace('${STROKE}', 'red')),
bearsMarker = new H.map.Marker({lat: 41.8625, lng: -87.6166 },
{icon: bearsIcon});
map.addObject(bearsMarker);
// Add the second marker.
var cubsIcon = new H.map.Icon(
svgMarkup.replace('${FILL}', 'white').replace('${STROKE}', 'orange')),
cubsMarker = new H.map.Marker({lat: 41.9483, lng: -87.6555 },
{icon: cubsIcon});
map.addObject(cubsMarker);
}
/**
* Boilerplate map initialization code starts below:
*/
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: 'DemoAppId01082013GAL',
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
useCIT: true,
useHTTPS: true
});
var defaultLayers = platform.createDefaultLayers();
//Step 2: initialize a map - this map is centered over Chicago.
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map,{
center: {lat:41.881944, lng:-87.627778},
zoom: 11
});
//Step 3: make the map interactive
// 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));
// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);
// Now use the map as required...
addSVGMarkers(map);
$('head').append('<link rel="stylesheet"...