HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// This sample uses 3rd party proj4 component
4
// that makes it possible to set coordinates
5
// for the points and labels on the map and
6
// required for custom projections and grid labels formatting.
7
// See https://docs.anychart.com/Maps/Map_Projections
8
9
// create the dataset of points that are defined by latitude and longtitude values
10
var data_ACME = [
11
{lat: 33.75, long: -112.18, name: "Stepford", value: 321},
12
{lat: 33.79, long: -101.52, name: "Metropolis", value: 293},
13
{lat: 26.12, long: -113.62, name: "Haddonfield", value: 312},
14
{lat: 37.89, long: -105.09, name: "Marlberry", value: 198},
15
{lat: 40.20, long: -84.28, name: "Sunnydale", value: 309},
16
{lat: 39.44, long: -116.04, name: "Landmark", value: 215},
17
{lat: 46.31, long: -99.88, name: "Springfield", value: 219},
18
{lat: 27.63, long: -82.37, name: "Vice City", value: 179}
19
];
20
21
var data_CITRUS = [
22
{lat: 45.75, long: -88.18, name: "Bas", value: 221},
23
{lat: 43.44, long: -70.85, name: "Hillwood", value: 203},
24
{lat: 41.46, long: -99.61, name: "Shermer", value: 162},
25
{lat: 38.14, long: -90.40, name: "Venusville", value: 98},
26
{lat: 29.28, long: -100.58, name: "South Park", value: 109},
27
{lat: 47.38, long: -120.06, name: "Heavensent", value: 215},
28
{lat: 44.50, long: -106.8, name: "Wellsville", value: 201},
29
{lat: 44.63, long: -122.37, name: "Whoville", value: 138},
30
{lat: 30.66, long: -88.15, name: "Bedrock", value: 210},
31
{lat: 35.21, long: -116.44, name: "Bluffington", value: 195},
32
{lat: 24.76, long: -151.44, name: "Primwille", value: 112},
33
{lat: 34.51, long: -96.65, name: "Hillywood", value: 89}
34
];
35
36
var map = anychart.map();
37
map.geoData(anychart.maps.united_states_of_america);
38
39
// Creates the marker series
40
var series_acme = map.marker(data_ACME);
41
series_acme.name("ACME Corp.");
42
var series_citrus = map.marker(data_CITRUS);
43
series_citrus.name("CITRUS Corp. branch");
44
45
// format the tooltips
46
map.tooltip().titleFormat(" {%seriesName}");
47
map.tooltip().format("Yearly profit: ${%value}m");
48
49
// set the colors of the ACME and CITRUS series
50
series_citrus.stroke("green");
51
series_citrus.fill("gold");
52
series_acme.normal().stroke(null);
53
series_acme.hovered().stroke(null);
54
series_acme.selected().stroke(null);
55
56
// set the size of CITRUS markers
57
series_citrus.normal().size(8);
58
series_citrus.hovered().size(10);
59
series_citrus.selected().size(10);
60
61
// set the size of ACME markers
62
series_acme.normal().size(14);
63
series_acme.hovered().size(18);
64
series_acme.selected().size(18);
65
66
// create a custom marker for the CITRUS series using a function
67
series_citrus.type(customMarkerType);
68
series_citrus.hovered().type(customMarkerType);
69
70
// set the link for the directory with images
71
var image_link = 'https://static.anychart.com/images/acme.jpg';
72
73
// set the images for the ACME series
74
series_acme.normal().fill(customImageMarker(1));
75
series_acme.hovered().fill(customImageMarker(0.5));
76
series_acme.selected().fill(customImageMarker(1));
77
78
map.title("Creating custom markers");
79
80
map.container("container");
81
map.draw();
82
});
83
84
85
function customMarkerType(path, x, y, size) {
86
var numericSize = +size;
87
var point1 = {x: x + 1.3 * numericSize, y: y - 0.4 * numericSize};
88
var point2 = {x: x - 0.4 * numericSize, y: y - 0.5 * numericSize};
89
path.moveTo(point1.x, point1.y)
90
.arcToByEndPoint(point2.x, point2.y, numericSize, numericSize, true, true)
91
.arcToByEndPoint(point1.x, point1.y, numericSize / 3, numericSize / 3, false, false)
92
.moveTo(point1.x, point1.y)
93
.close();
94
return path;
95
}
96
97
function customImageMarker(op){
98
var image_link = 'https://static.anychart.com/images/acme.jpg';
99
return {
100
src: image_link,
101
mode: 'fit',
102
opacity: op
103
}
104
}