-
Notifications
You must be signed in to change notification settings - Fork 0
/
showMap.js
121 lines (96 loc) · 2.71 KB
/
showMap.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
function getLat() {
return new Promise((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
resolve(position.coords.latitude);
});
} else {
reject("No Navigator");
}
});
}
function getLong() {
return new Promise((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
resolve(position.coords.longitude);
});
} else {
reject("No Navigator");
}
});
}
function geocode(addr){
return new Promise((resolve, reject) => {
GMaps.geocode({
address: addr,
callback: function(results, status) {
if (status == 'OK') {
latlng = results[0].geometry.location;
resolve(latlng);
} else if (status == 'ZERO_RESULTS') {
reject('Sorry, no results found');
return -1;
}
}
});
});
}
function addToMap(addme){
return new Promise((resolve, reject) => {
geocode(addme).then(coords =>{
var lat = coords.lat();
var long = coords.lng()
var point = {
type: "point",
longitude: long,
latitude: lat
};
var simpleMarkerSymbol = {
type: "simple-marker",
color: [226, 119, 40], // orange
outline: {
color: [255, 255, 255], // white
width: 1,
size:"10000px"
}
};
var attrib = {
geometry: point,
symbol: simpleMarkerSymbol
};
resolve(attrib);
});
});
}
require(["esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/GraphicsLayer"], function(Map, MapView,Graphic,GraphicsLayer) {
var map = new Map({
basemap: "topo-vector"
});
addToMap('Santa Cruz, California').then(point => {
var graphicsLayer = new GraphicsLayer();
map.add(graphicsLayer);
var grap = new Graphic({
geometry:point.geometry,
symbol:point.symbol
});
console.log(point.geometry);
console.log(point.symbol);
graphicsLayer.add(grap);
getLat().then(latitude => {
getLong().then(longitude => {
console.log(Math.round(latitude))
console.log(Math.round(longitude))
var view = new MapView({
container: "viewDiv",
map: map,
center: [Math.round(longitude),Math.round(latitude)], // longitude, latitude
zoom: 13
});
});
});
});
});