forked from toepoke/mapsed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-add-places-example.js
60 lines (49 loc) · 1.61 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
function runExample1() {
$("#add-places").mapsed({
// Adds the "+" button to the control bar at the top right of the map
allowAdd: 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) {
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.markerType == "new") {
// 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/>g+: " + newPlace.url
;
if (newPlace.markerType == "new")
title = "New place added!";
else
title = "Place saved!";
m.showMsg(title, msg);
}
// indicate form was OK and saved
return "";
}
});
}
$(document).ready(function() {
runExample1();
});