-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay-sample.html
More file actions
163 lines (134 loc) · 4.62 KB
/
overlay-sample.html
File metadata and controls
163 lines (134 loc) · 4.62 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Overlaying with PictureMarkerSymbol</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.6/js/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
background-color: #FFF;
overflow: hidden;
font-family: "Trebuchet MS";
}
</style>
<script src="http://js.arcgis.com/3.6/"></script>
<script>
var map, transparentSymbol, pictureSymbol, pictureOverlayLayer, picturePoint, pictureGraphic, extentGraphicLayer, extentOverlay,
extentGraphic, dojoShape, moveable, moveStopToken, firstInit, initial_width, initial_height, picture_width, picture_height;
require([
"dojo/_base/connect",
"dojo/_base/Color",
"dojox/gfx/Moveable",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/PictureMarkerSymbol",
"esri/layers/GraphicsLayer",
"esri/graphic",
"esri/geometry/Extent",
"esri/geometry/Point",
"esri/map",
"dojo/domReady!"], function(
connect,
Color,
Moveable,
SimpleFillSymbol,
SimpleLineSymbol,
PictureMarkerSymbol,
GraphicsLayer,
Graphic,
Extent,
Point,
Map) {
firstInit = true;
map = new Map("map", {
basemap: "topo",
center: [-122.45,37.75], // long, lat
zoom: 13,
sliderStyle: "small"
});
map.on("load", mapLoad);
map.on("update-end", updateEnd);
map.on("extent-change", extentChange);
transparentSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0,0,0,0]), 1),
new Color([255,255,255,0])
);
picture_width = 685;
picture_height = 332;
pictureSymbol = new PictureMarkerSymbol("image/overlay.png", picture_width, picture_height);
extentGraphicLayer = new GraphicsLayer();
pictureOverlayLayer = new GraphicsLayer();
extentOverlay = new Extent({
"xmin" : -122.502099227903,
"ymin" : 37.736357791231,
"xmax" : -122.384854507444,
"ymax" : 37.7813471858105,
"spatialReference" : {"wkid":4326}
});
extentGraphic = new Graphic(extentOverlay, transparentSymbol);
extentGraphicLayer.add(extentGraphic);
map.addLayers([extentGraphicLayer, pictureOverlayLayer]);
function extentChange() {
if (typeof pictureGraphic !== 'undefined')
{
var screenPoint1 = map.toScreen(new Point(extentOverlay.xmin, extentOverlay.ymin));
var screenPoint2 = map.toScreen(new Point(extentOverlay.xmax, extentOverlay.ymax));
width = Math.abs((screenPoint2.x - screenPoint1.x));
height = Math.abs((screenPoint1.y - screenPoint2.y));
new_width = width / (initial_width / picture_width);
new_height = height / (initial_height / picture_height);
pictureSymbol.setWidth(new_width);
pictureSymbol.setHeight(new_height);
if (pictureGraphic.getDojoShape() != null)
{
connect.disconnect(moveStopToken);
dojoShape = pictureGraphic.getDojoShape();
moveable = new Moveable(dojoShape);
moveStopToken = connect.connect(moveable, "onMoveStop", moveStop);
}
}
}
function updateEnd() {
if (firstInit && typeof pictureGraphic !== 'undefined')
{
if (pictureGraphic.getDojoShape() != null)
{
var screenPoint1 = map.toScreen(new Point(extentOverlay.xmin, extentOverlay.ymin));
var screenPoint2 = map.toScreen(new Point(extentOverlay.xmax, extentOverlay.ymax));
initial_width = Math.abs((screenPoint2.x - screenPoint1.x));
initial_height = Math.abs((screenPoint1.y - screenPoint2.y));
dojoShape = pictureGraphic.getDojoShape();
moveable = new Moveable(dojoShape);
moveStopToken = connect.connect(moveable, "onMoveStop", moveStop);
firstInit = false;
}
}
}
function mapLoad(map) {
picturePoint = extentOverlay.getCenter();
pictureGraphic = new Graphic(picturePoint, pictureSymbol);
pictureOverlayLayer.add(pictureGraphic);
pictureOverlayLayer.setOpacity(0.6);
}
function moveStop(mover) {
var tx = dojoShape.getTransform();
var startPoint = pictureGraphic.geometry;
var endPoint = map.toMap(map.toScreen(startPoint).offset(tx.dx, tx.dy));
dojoShape.setTransform(null);
pictureGraphic.setGeometry(endPoint);
}
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>