1: function showPosition(position) {
2:
3:
4:
5: var data = [{
6: Name: name,
7: Latitude: position.coords.latitude,
8: Longitude: position.coords.longitude}];
9:
10: $("#map").igMap({
11: series: [{
12: name: "Countries",
13: type: "geographicSymbol",
14: longitudeMemberPath: "Longitude",
15: latitudeMemberPath: "Latitude",
16: /*
17: The provided object should have properties called render and optionally measure.
18: These are functions which will be called that will be called to handle the user specified custom rendering.
19: */
20: markerTemplate: {
21: render: function(renderInfo) {
22: var ctx = renderInfo.context; //2d canvas context
23: var x = renderInfo.xPosition;
24: var y = renderInfo.yPosition;
25:
26: if (renderInfo.isHitTestRender) {
27: // This is called for tooltip hit test only
28: // Rough marker rectangle size calculation
29: ctx.fillStyle = "yellow";
30: ctx.fillRect(x, y, renderInfo.availableWidth, renderInfo.availableHeight);
31: } else {
32: //actual marker drawing is here:
33: var markerData = renderInfo.data;
34: var name = markerData.item()["Name"];
35: //set font or measure will be for the default one
36: ctx.font = '10pt Segoe UI';
37: var textWidth = ctx.measureText(name).width;
38:
39: //Move the path point to the desired coordinates:
40: ctx.moveTo(x, y);
41: //Draw lines:
42: ctx.beginPath();
43: ctx.lineTo(x - (textWidth / 2) - 5, y + 5);
44: ctx.lineTo(x - (textWidth / 2) - 5, y + 40); // 35width rect.
45: ctx.lineTo(x + (textWidth / 2) + 5, y + 40); // full textWidth line plus 5 margin
46: ctx.lineTo(x + (textWidth / 2) + 5, y + 5); // 35 up
47: ctx.lineTo(x, y);
48: //finish the shape
49: ctx.closePath();
50: ctx.fillStyle = "rgba(78,183,226,0.7)";
51: ctx.fill();
52: ctx.lineWidth = 0.5;
53: ctx.strokeStyle = "#185170";
54: ctx.stroke();
55: //add a point at the start
56: ctx.beginPath();
57: ctx.fillStyle = "black";
58: ctx.arc(x, y, 1.5, 0, 2 * Math.PI, true);
59: ctx.fill();
60:
61: // Draw text
62: ctx.textBaseline = "top";
63: ctx.fillStyle = "black";
64: ctx.textAlign = 'center';
65: ctx.fillText("current", x, y + 8);
66: ctx.fillText(name, x, y + 20);
67: }
68: }
69: },
70: dataSource: data}]
71: });
72:
73: var geo = {
74: height: 0.05,
75: left: position.coords.longitude - 0.035,
76: top: position.coords.latitude - 0.025,
77: width: 0.07
78: };
79:
80: var zoom = $("#map").igMap("getZoomFromGeographic", geo);
81: $("#map").igMap("option", "windowRect", zoom);
82:
83: }