-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
137 lines (114 loc) · 4.08 KB
/
map.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var currentPopup, currentAttributes, campusTreesFL;
// arc stuff
require([
"esri/layers/FeatureLayer",
], function(FeatureLayer) {
campusTreesFL = new FeatureLayer("http://maps.northpointgis.com/arcgis/rest/services/campus_trees/FeatureServer/0",
{
refreshInterval: 0.1,
visible: false,
outFields: ["*"]
});
});
// create map
var map = L.map('map').setView([44.97177944969965, -93.2433839753503], 18);
// add tile layer (mapbox basemap)
L.tileLayer('http://{s}.tiles.mapbox.com/v3/rumski20.i6pp2mja/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 20
}).addTo(map);
// add campus trees dynamic layer
dynLayer = L.esri.dynamicMapLayer("http://maps.northpointgis.com/arcgis/rest/services/campus_trees/MapServer/", {
opacity: 0.8,
layers: "0"
});
map.addLayer(dynLayer);
//Identifying Dynamic Map Service Features
map.on("click", function(e) {
dynLayer.identify(e.latlng, function(data) {
console.log(data.results);
if (data.results.length == 1) {
configurePopup(data.results[0]);
/*//Popup text should be in html format. Showing the Storm Name with the type
popupText = "<b>" + (data.results[0].attributes.EVENTID || data.results[0].attributes.NAME) + "<b>";*/
//Add Popup to the map when the mouse was clicked at
var popup = L.popup({
maxWidth: 260
})
.setLatLng(e.latlng)
.setContent($("#my-popup").html())
.openOn(map);
}
});
});
// find location
map.locate({
setView: true,
maxZoom: 20
});
function onLocationFound(e) {
L.marker(e.latlng).addTo(map)
.bindPopup("You are here! <br>Or at least nearby.").openPopup();
}
function onLocationError(e) {
alert(e.message + " Using default location instead.");
map.setView([44.97177944969965, -93.2433839753503], 18);
}
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
// configure popup
function configurePopup(results) {
currentAttributes = results.attributes;
$("#my-popup-content").empty();
$.each(currentAttributes, function(key, val) {
console.log(key + ": " + val);
if (key == "TREE_ID") {
c = "<p><span class='my-keys'>Tree ID:</span><span class='my-vals'>" + val + "</span></p>";
$("#my-popup-content").append(c);
} else if (key == "d_SPECIES") {
c = "<p><span class='my-keys'>Species:</span><span class='my-vals'>" + val + "</span></p>";
$("#my-popup-content").append(c);
}
});
}
map.on("popupopen", function(evt) {
currentPopup = evt.popup;
});
function hidePopup() {
if (currentPopup !== null)
currentPopup._source.closePopup();
}
function submitEdits() {
require([ "esri/tasks/query" ],
function(Query) {
var query = new Query();
query.objectIds = [currentAttributes.OBJECTID];
query.outFields = [ "*" ];
// Query for the features with the given object ID
campusTreesFL.queryFeatures(query, function(featureSet) {
console.log(featureSet);
if ( featureSet.features.length == 1 ) {
var updatedFeatures = featureSet.features[0];
updatedFeatures.attributes.Condition = $("#conditionSelect :selected").val();
updatedFeatures.attributes.Inspected = "y";
updatedFeatures.attributes.Date = getTheDate();
console.log(updatedFeatures.attributes);
campusTreesFL.applyEdits(null, [updatedFeatures], null);
}
});
});
}
function getTheDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy+'-'+mm+'-'+dd;
return today
}