-
Notifications
You must be signed in to change notification settings - Fork 49
/
03-add-places-example.js
96 lines (80 loc) · 2.52 KB
/
03-add-places-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function updateDatabase(m, newPlace) {
var missing = [];
// detect errors starting at bottom
// ... we only have space for one error at a time, so this way we'll report
// ... from the top down
if (newPlace.postCode === "") missing.push("postcode");
if (newPlace.street === "") missing.push("street");
if (newPlace.name === "") missing.push("name");
// anything missing?
if (missing.length > 0) {
// return the error message so the callback doesn't progress
return "Required: " + missing.join();
}
if (newPlace) {
if (!newPlace.userData) {
// simulate a primary key being save to a db
newPlace.userData = parseInt(Math.random() * 100000);
}
var title = "";
var msg =
"userData: " + newPlace.userData +
"<br/>name: " + newPlace.name +
"<br/>street: " + newPlace.street + ", " +
newPlace.area + ", " +
newPlace.town + ", " + newPlace.postCode +
"<br/>telNo: " + newPlace.telNo +
"<br/>website: " + newPlace.website +
"<br/>more: " + newPlace.url
;
if (newPlace.place_id) {
msg += "<br/>Place_id: " + details.place_id
}
if (newPlace.markerType == "new") {
title = "New place added!";
} else {
title = "Place saved!";
}
m.showMsg(title, msg);
}
// indicate form was OK and saved
return "";
}
function runExample3() {
$("#add-places").mapsed({
disablePoi: true,
// Enables edit of custom places (to your web application, not Google Maps!)
// ... again the presence of the callback enables the functionality
onSave: function(m, newPlace) {
return updateDatabase(m, newPlace);
},
// Enables saving of new places, also adds the "+" button to the control bar
// at the top right of the map
onAddSave: function(m, newPlace) {
return updateDatabase(m, newPlace);
},
// Custom marker images
getMarkerImage: function (m, markerType, title) {
var imageUrl = "";
if (markerType == "custom")
// a place dervied from "your" database
imageUrl = "examples/images/view-place.png";
else if (markerType == "new")
// user has clicked on the add place (+) icon to add a new place
imageUrl = "examples/images/add-place.png";
else
// normal Google Places result
imageUrl = "examples/images/google-place.png";
return {
url: imageUrl,
size: new google.maps.Size(28, 40),
origin: new google.maps.Point(0, 0),
// where the little cross-hair appears (on new markers) relative to the image
anchor: new google.maps.Point(14, 45)
};
},
});
}
$(document).ready(function() {
runExample3();
});