Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (57 sloc) 3.12 KB
<!DOCTYPE html>
<html>
<head>
<title>Draggable HTML Marker - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This sample shows how to make an HTML marker draggable." />
<meta name="keywords" content="map, gis, API, SDK, markers, pins, pushpins, symbols, drag, draggable, mouse" />
<meta name="author" content="Microsoft Azure Maps" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<script type='text/javascript'>
var map;
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at https://azure.com/maps
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a draggable HTML marker.
var marker = new atlas.HtmlMarker({
draggable: true,
//Tip: add "pointer-events:none" as a style on the html content to disable the default drag behavior in MS Edge which will display an unwanted icon.
htmlContent: '<img src="../Common/images/icons/ylw-pushpin.png" style="pointer-events: none;" />',
position: [0, 0],
pixelOffset: [5, -15]
});
var output = document.getElementById('output');
//Add a drag event to get the position of the marker. Markers support drag, dragstart and dragend events.
map.events.add('drag', marker, function () {
var pos = marker.getOptions().position;
//Round longitude,latitude values to 5 decimal places.
output.innerText = Math.round(pos[0] * 100000) / 100000 + ', ' + Math.round(pos[1] * 100000) / 100000;
});
//Add the marker to the map.
map.markers.add(marker);
});
}
</script>
</head>
<body onload='GetMap()'>
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
<div id="output" style="position:absolute;top:580px;left:calc(50% - 100px);height:20px;width:200px;background-color:white;text-align:center;"></div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend>Draggable HTML Marker</legend>
This sample shows how to make an HTML marker draggable. HTML markers support drag, dragstart and dragend events.
</fieldset>
</body>
</html>
You can’t perform that action at this time.