Skip to content

Commit ff2495f

Browse files
Merge pull request #2 from DevExpress-Examples/readme
Update example
2 parents 210efab + d8e9bf6 commit ff2495f

File tree

4 files changed

+45
-42
lines changed

4 files changed

+45
-42
lines changed

Readme.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66

77
# Map for DevExtreme - How to add a marker with a label
88

9-
This example demonstrates how to add a marker with a label to the Google map. We used the <a href="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.8/docs/reference.html">MarkerWithLabel</a> class for this task. This class constructor requires the Google map instance. dxMap allows obtaining the instance in the <a href="http://phonejs.devexpress.com/Documentation/ApiReference/Widgets/dxMap/Configuration?version=13_2#readyAction">dxMap.readyAction</a> event handler using the <strong>originalMap</strong> parameter. The <a href="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.8/docs/examples.html">MarkerWithLabel Examples</a> web page demonstrates how to use the <strong>MarkerWithLabel</strong> class. We can use the same code in the <strong>dxMap.readyAction</strong> event handler. However, we should remember that dxMap loads the map's APIs dynamically and that is why we need to load a file that contains code for the <strong>MarkerWithLabel</strong> class when a map is completely loaded. We used <a href="http://api.jquery.com/jquery.getscript/">jQuery.getScript</a> for this purpose as shown below:
10-
11-
```js
12-
readyAction: function (s) {
13-
$.getScript("js/markerwithlabel.js", function () {
14-
var map = s.originalMap;
15-
var markerSettings = {
16-
position: new google.maps.LatLng(40.749825, -73.987963),
17-
map: map,
18-
labelContent: "Label text",
19-
labelAnchor: new google.maps.Point(26, 0),
20-
labelClass: "mylabel"
21-
};
22-
var marker = new MarkerWithLabel(markerSettings);
23-
});
24-
}
25-
```
9+
This example demonstrates how to add a marker with a label to the Google map. We used the <a href="https://github.com/googlemaps/js-markerwithlabel">js-markerwithhlabel</a> library for this task.
10+
11+
![Markers with labels](./map-marker-with-label.png)
12+
13+
The Map component allows obtaining the instance in the <a href="https://js.devexpress.com/jQuery/Documentation/ApiReference/UI_Components/dxMap/Configuration/#onReady">onReady</a> event handler using the <strong>originalMap</strong> parameter.
2614

2715
## Files to Review
2816

jQuery/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88

99
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.js"></script>
10-
<link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/18.1.11/css/dx.common.css">
11-
<link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/18.1.11/css/dx.light.css">
12-
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/18.1.11/js/dx.all.js"></script>
10+
<script src="https://unpkg.com/@googlemaps/markerwithlabel/dist/index.min.js"></script>
11+
<link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/23.1.4/css/dx.light.css">
12+
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/23.1.4/js/dx.all.js"></script>
13+
14+
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
1315

1416
<script type="text/javascript" src="script.js"></script>
1517
</head>

jQuery/script.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1-
$(function(){
2-
$("#map").dxMap({
3-
location: "40.749825, -73.987963",
4-
width: 1200,
5-
height: 620,
6-
zoom: 12,
7-
provider: "google",
8-
readyAction: function (s) {
9-
$.getScript("markerwithlabel.js", function () {
10-
var map = s.originalMap;
11-
var markerSettings = {
12-
position: new google.maps.LatLng(40.749825, -73.987963),
13-
map: map,
14-
labelContent: "Label text",
15-
labelAnchor: new google.maps.Point(26, 0),
16-
labelClass: "mylabel"
17-
};
18-
var marker = new MarkerWithLabel(markerSettings);
19-
});
20-
}
21-
});
22-
});
1+
$(function () {
2+
$("#map").dxMap({
3+
apiKey: "YOUR_API_KEY",
4+
width: 1200,
5+
height: 620,
6+
zoom: 14,
7+
center: "49.47805, -123.84716",
8+
provider: "google",
9+
onReady: function (s) {
10+
const map = s.originalMap;
11+
var homeLatLng = new google.maps.LatLng(49.47805, -123.84716);
12+
13+
var marker1 = new markerWithLabel.MarkerWithLabel({
14+
position: homeLatLng,
15+
draggable: false,
16+
clickable: false,
17+
map: map,
18+
labelContent: "$425K",
19+
labelAnchor: new google.maps.Point(-21, 3),
20+
labelClass: "labels", // the CSS class for the label
21+
labelStyle: { opacity: 0.75 },
22+
});
23+
24+
var marker2 = new markerWithLabel.MarkerWithLabel({
25+
position: new google.maps.LatLng(49.475, -123.84),
26+
draggable: true,
27+
map: map,
28+
labelContent: "$395K",
29+
labelAnchor: new google.maps.Point(-21, 3),
30+
labelClass: "labels", // the CSS class for the label
31+
labelStyle: { opacity: 1.0 },
32+
});
33+
},
34+
});
35+
});

map-marker-with-label.png

219 KB
Loading

0 commit comments

Comments
 (0)