-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.js
66 lines (54 loc) · 1.67 KB
/
main.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
// Main Mapping Application.
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/Sketch/SketchViewModel",
"esri/layers/GraphicsLayer",
// image recognition (tensorflow)
"./modules/imageRecognition.js",
// url, extentObject
"./modules/returnImageByExtent.js"
], function(
Map,
MapView,
SketchViewModel,
GraphicsLayer,
imageRecognition,
returnImageByExtent
) {
var worldImageService = ""; // add your image service here!
// Note: https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Imagery/MapServer requires Developer, or AGOL Subscription.
var tempGraphicsLayer = new GraphicsLayer();
var map = new Map({
basemap: "satellite",
layers: [tempGraphicsLayer]
});
var view = new MapView({
container: "viewDiv",
map: map,
zoom: 14,
center: [-118.2176276, 33.7445614]
});
// Drawing toolbar
var sketchVM = new SketchViewModel({
layer: tempGraphicsLayer,
view: view
});
// On "draw box"
sketchVM.on("create", function(event) {
if (event.state === "complete") {
// Get image by extent defined.
var image = returnImageByExtent.getimageData(worldImageService, event.graphic.geometry.extent);
// Once image returned, get predictions.
image.then(function(results) {
imageRecognition.getPredictions(results);
});
};
});
document.getElementById("draw-button").addEventListener("click", function() {
tempGraphicsLayer.removeAll();
sketchVM.create("rectangle", {
mode: "freehand"
});
})
});