-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZoomToExtent.js
111 lines (97 loc) · 3.52 KB
/
ZoomToExtent.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
define([
'dojo/_base/declare',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dijit/_WidgetsInTemplateMixin',
'dijit/form/Button',
'dojo/_base/lang',
'dojo/_base/array',
'dojo/dom',
'dojo/domReady!',
'dojo/aspect',
'dojo/on',
'dojo/text!./ZoomToExtent/templates/ZoomToExtent.html',
'dojo/topic',
'xstyle/css!./ZoomToExtent/css/ZoomToExtent.css',
'dojo/dom-construct',
'dojo/_base/Color',
'esri/geometry/webMercatorUtils',
'esri/toolbars/draw',
'esri/graphic',
'esri/symbols/SimpleFillSymbol',
'esri/symbols/SimpleLineSymbol',
'esri/Color'
], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Button, lang, arrayUtils, dom, ready, aspect, on, template, topic, css, domConstruct, Color1, webMercatorUtils, Draw, Graphic, SimpleFillSymbol, SimpleLineSymbol, Color) {
var map;
var clickmode;
var drawToolbar;
var theGeometry;
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
name: 'ZoomToExtent',
map: true,
widgetsInTemplate: true,
templateString: template,
mapClickMode: null,
postCreate: function(){
this.inherited(arguments);
map = this.map;
drawToolbar= new Draw(this.map);
drawToolbar.on("draw-end", lang.hitch(this, 'addToMap'));
this.own(topic.subscribe("mapClickMode/currentSet", lang.hitch(this, "setMapClickMode")));
if (this.parentWidget) {
if (this.parentWidget.toggleable) {
this.own(aspect.after(this.parentWidget, 'toggle', lang.hitch(this, function () {
this.onLayoutChange(this.parentWidget.open);
})));
}
}
},
onLayoutChange: function (open) {
if (open) {
//this.onOpen();
} else {
this.onClear();
}
open || "draw" === this.mapClickMode && topic.publish("mapClickMode/setDefault")
},
disconnectMapClick: function() {
topic.publish("mapClickMode/setCurrent", "draw");
},
connectMapClick: function() {
topic.publish("mapClickMode/setDefault");
},
addToMap: function (evt) {
var symbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255, 0, 0]), 2),
new Color([255, 255, 0, 0.2])
);
var graphic = new Graphic(evt.geometry, symbol);
map.graphics.add(graphic);
theGeometry = evt.geometry;
map.setExtent(theGeometry.getExtent());
this.connectMapClick();
drawToolbar.deactivate();
map.setMapCursor("default");
this.map.graphics.clear();
},
onDrawExtent: function()
{
this.disconnectMapClick();
this.onClear();
drawToolbar.activate(Draw.EXTENT);
this.map.setMapCursor('crosshair');
},
onClear: function()
{
this.map.graphics.clear();
this.connectMapClick();
drawToolbar.deactivate();
map.setMapCursor("default");
theGeometry = null;
},
setMapClickMode: function (mode) {
this.mapClickMode = mode;
}
});
});