-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
124 lines (108 loc) · 3.63 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
require([
"esri/Map",
"esri/views/MapView",
"esri/views/SceneView",
"esri/core/watchUtils",
"dojo/domReady!"
], function(Map, MapView, SceneView, watchUtils) {
var map = new Map({
basemap: "topo",
ground: "world-elevation"
});
var view1 = new SceneView({
id: 'view1',
container: 'viewDiv',
map: map
});
var view2 = new MapView({
id: 'view2',
container: 'map',
map: map,
constraints: {
snapToZoom: false
}
});
/**
* utility method that synchronizes the viewpoint of a view to other views
*/
var synchronizeView = function(view, others) {
others = Array.isArray(others) ? others : [others];
var viewpointWatchHandle;
var viewStationaryHandle;
var otherInteractHandlers;
var scheduleId;
var clear = function() {
if (otherInteractHandlers) {
otherInteractHandlers.forEach(function(handle) {
handle.remove();
});
}
viewpointWatchHandle && viewpointWatchHandle.remove();
viewStationaryHandle && viewStationaryHandle.remove();
scheduleId && clearTimeout(scheduleId);
otherInteractHandlers = viewpointWatchHandle =
viewStationaryHandle = scheduleId = null;
};
var interactWatcher = view.watch('interacting,animation',
function(newValue) {
if (!newValue) {
return;
}
if (viewpointWatchHandle || scheduleId) {
return;
}
// start updating the other views at the next frame
scheduleId = setTimeout(function() {
scheduleId = null;
viewpointWatchHandle = view.watch('viewpoint',
function(newValue) {
others.forEach(function(otherView) {
otherView.viewpoint = newValue;
});
});
}, 0);
// stop as soon as another view starts interacting, like if the user starts panning
otherInteractHandlers = others.map(function(otherView) {
return watchUtils.watch(otherView,
'interacting,animation',
function(
value) {
if (value) {
clear();
}
});
});
// or stop when the view is stationary again
viewStationaryHandle = watchUtils.whenTrue(view,
'stationary', clear);
});
return {
remove: function() {
this.remove = function() {};
clear();
interactWatcher.remove();
}
}
};
/**
* utility method that synchronizes the viewpoints of multiple views
*/
var synchronizeViews = function(views) {
var handles = views.map(function(view, idx, views) {
var others = views.concat();
others.splice(idx, 1);
return synchronizeView(view, others);
});
return {
remove: function() {
this.remove = function() {};
handles.forEach(function(h) {
h.remove();
});
handles = null;
}
}
}
// bind the views
synchronizeViews([view1, view2]);
});