This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
267 lines (229 loc) · 10 KB
/
index.html
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de-de" lang="de-de">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>simpleMapWizzard</title>
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="http://openlayers.org/api/theme/default/style.css" type="text/css" />
<script src="http://www.openlayers.org/api/OpenLayers.js" type="text/javascript"></script>
<script src="http://openstreetmap.org/openlayers/OpenStreetMap.js" type="text/javascript"></script>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript">
var map, layer;
var perma = "";
/* init OL, map, dragFeature */
function initOpenLayers() {
map = new OpenLayers.Map('map', {
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar()]
});
markers = new OpenLayers.Layer.Vector(
"Markers",
{
styleMap: new OpenLayers.StyleMap({
externalGraphic: "js/openlayers/img/marker-gold.png",
backgroundGraphic: "images/marker_shadow.png",
backgroundXOffset: 0,
backgroundYOffset: -7,
graphicZIndex: 10,
backgroundGraphicZIndex: 11,
pointRadius: 10
}),
rendererOptions: {yOrdering: true}
}
);
mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
displayOutsideMaxExtent: true,
wrapDateLine: true
});
map.addLayer(mapnik);
cylce = new OpenLayers.Layer.OSM.CycleMap("OpenCycleMap");
map.addLayer(cylce);
piste = new OpenLayers.Layer.OSM("openpistemap","http://openpistemap.org/tiles/contours/${z}/${x}/${y}.png");
map.addLayer(piste);
topo = new OpenLayers.Layer.OSM("topo.geofabrik.trails","http://topo.geofabrik.de/trails/${z}/${x}/${y}.png");
map.addLayer(topo);
center = new OpenLayers.LonLat(-50,40).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter (center, 2);
map.events.register( 'moveend', this, makeStaticCodeSnip);
map.addLayer(markers);
var dragFeature = new OpenLayers.Control.DragFeature(markers);
dragFeature.onComplete = makeStaticCodeSnip;
dragFeature.onDrag = makeStaticCodeSnip;
map.addControl(dragFeature);
dragFeature.activate();
layerswitcher = new OpenLayers.Control.LayerSwitcher()
map.addControl(layerswitcher);
map.events.register("changebaselayer", map, mapTypeChanged);
map.maptype = 'mapnik';
}
function mapTypeChanged(){
switch(map.baseLayer.name){
case "Mapnik" : map.maptype = 'mapnik'; break;
case "openpistemap" : map.maptype = 'piste'; break;
case "Osmarender" : map.maptype = 'osmarenderer'; break;
case "OpenCycleMap" : map.maptype = 'cycle'; break;
case "topo.geofabrik.trails" : map.maptype = 'topo'; break;
default: map.maptype = map.baseLayer.name;
}
makeStaticCodeSnip();
}
/* function for adding markers by dragging and click on image */
function mark(markerImg){
markCenter($(markerImg).attr('rel'), $(markerImg).attr('src'));
}
function markCenter(rel,img){
id = rel.split('|')[0];
width = rel.split('|')[1];
height = rel.split('|')[2];
offsetx = rel.split('|')[3];
offsety = rel.split('|')[4];
markAtPosition(id,img, $('#map').height()/2, $('#map').width()/2, width, height, offsetx, offsety);
}
function markAtPosition(id,img, y, x, width, height, offsetx, offsety){
var features = [];
lonLat = map.getCenter();
center = map.getViewPortPxFromLonLat(map.getCenter());
pixel = new OpenLayers.Pixel(center.x + x-$('#map').width()/2, center.y + y-$('#map').height()/2);
lonLat = map.getLonLatFromViewPortPx(pixel);
vector = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat)
);
vector.attributes.img = id;
vector.style = {
externalGraphic: img,
graphicWidth:parseInt(width),
graphicHeight:parseInt(height),
graphicXOffset:parseInt(offsetx),
graphicYOffset:parseInt(offsety),
backgroundGraphic: (id.substr(0,5)=='light'?'':"./images/marker_shadow.png"),
backgroundXOffset:0,
backgroundYOffset:parseInt(offsety)-2,
graphicZIndex: 11,
backgroundGraphicZIndex: 10,
pointRadius: 10
}
features.push(vector);
markers.addFeatures(features);
makeStaticCodeSnip();
}
function makeStaticCodeSnip(){
perma = '<img src="';
perma += getStaticMapImageUrl();
perma += "\" />"
$('#perma').val(perma);
}
function getStaticMapImageUrl(){
output = 'staticmap.php?';
if(map.maptype != 'mapnik') output += "maptype="+map.maptype+"&";
mapCenter = map.getCenter();
centerLonLat = mapCenter.transform(map.getProjectionObject(),new OpenLayers.Projection("EPSG:4326"));
output += "center="+centerLonLat.lat+","+centerLonLat.lon;
output += "&zoom="+map.zoom;
output += "&size="+$('#width').val()+"x"+$('#height').val();
if(markers.features.length){
output += "&markers="
for(i=0; i<markers.features.length; i++){
pos = markers.features[i].geometry.getCentroid();
lonLat = pos.transform(map.getProjectionObject(),new OpenLayers.Projection("EPSG:4326"));
if(i>0) output += '|';
output += lonLat.y+","+lonLat.x+","+markers.features[i].attributes.img
}
}
return output;
}
function showStaticInNewWindow(){
makeStaticCodeSnip();
var newWindow = window.open("../"+getStaticMapImageUrl(), '_blank');
newWindow.focus();
return false;
}
/* drag + drop */
$(document).ready(function(){
$('.draggable').draggable(
{ helper: 'clone'}
);
$(".drop").droppable({
accept: ".draggable",
activeClass: 'droppable-active',
hoverClass: 'droppable-hover',
drop: function(ev, ui) {
mapOffset = $('#map').offset();
id = ui.draggable.attr('rel').split('|')[0];
width = parseInt(ui.draggable.attr('rel').split('|')[1]);
height = parseInt(ui.draggable.attr('rel').split('|')[2]);
offsetx = parseInt(ui.draggable.attr('rel').split('|')[3]);
offsety = parseInt(ui.draggable.attr('rel').split('|')[4]);
markAtPosition(id, ui.draggable.attr('src'), ui.offset.top-mapOffset.top-offsety, ui.offset.left-mapOffset.left-offsetx, width, height, offsetx, offsety);
}
});
initOpenLayers();
makeStaticCodeSnip();
});
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
</div>
<div id="content" style="background:url(images/wizzard-bg.jpg) 50px 0px no-repeat;">
<div class="par-div">
<h2 style="font-size:2em; margin-bottom:0">
simple map wizzard
</h2>
<ol>
<li>navigate to your area of interest</li>
<li>place some markers and drag them to their desired position (optional)</li>
<li>copy image tag or press "show map in new window"</li>
<li>done! </li>
</ol>
<hr />
<div id="map" class="smallmap drop" style="-moz-user-select: none"></div>
<div id="buttons" style="-moz-user-select: none">
<h3>makers</h3>
<input style="margin-left:0;" type="button" onclick="markers.removeFeatures(markers.features); makeStaticCodeSnip();" value="clear all markers" />
<h4 style="margin:0">click or drag to add</h4>
<img style="margin-left:0;" class="draggable" src="./images/markers/lightblue1.png" onclick="mark(this);" rel="lightblue1|17|19|-2|-20" />
<img class="draggable" src="./images/markers/lightblue2.png" onclick="mark(this);" rel="lightblue2|17|19|0|-19" />
<img class="draggable" src="./images/markers/lightblue3.png" onclick="mark(this);" rel="lightblue3|17|19|0|-19" />
<img class="draggable" src="./images/markers/lightblue4.png" onclick="mark(this);" rel="lightblue4|17|19|0|-19" />
<br />
<img class="draggable" style="margin-left:0;" src="./images/markers/ol-marker.png" onclick="mark(this);" rel="ol-marker|21|25|-10|-25" />
<img class="draggable" src="./images/markers/ol-marker-gold.png" onclick="mark(this);" rel="ol-marker-gold|21|25|-10|-25" />
<img class="draggable" src="./images/markers/ol-marker-blue.png" onclick="mark(this);" rel="ol-marker-blue|21|25|-10|-25" />
<img class="draggable" src="./images/markers/ol-marker-green.png" onclick="mark(this);" rel="ol-marker-green|21|25|-10|-25" />
<br />
<img class="draggable" style="margin-left:0;" src="./images/markers/ltblu-pushpin.png" onclick="mark(this);" rel="ltblu-pushpin|32|32|-11|-33" />
<img class="draggable" src="./images/markers/pink-pushpin.png" onclick="mark(this);" rel="pink-pushpin|32|32|-11|-33" />
<img class="draggable" src="./images/markers/red-pushpin.png" onclick="mark(this);" rel="red-pushpin|32|32|-11|-33" />
<img class="draggable" src="./images/markers/ylw-pushpin.png" onclick="mark(this);" rel="ylw-pushpin|32|32|-11|-33" />
<!-- <h3>address</h3>
<input type="text" value="Mountain View, CA" /><input type="button" onclick="lookup(this.value);" value="look up" />
--> <h3>map size</h3>
<input style="margin-left:0;" type="text" name="width" id="width" value="500" size="5" onchange="makeStaticCodeSnip()" />x
<input type="text" name="height" id="height" value="350" size="5" onchange="makeStaticCodeSnip()" />px
<h3>show map</h3>
<input style="margin-left:0; background: #eee; padding: 5px 10px" type="button" onclick="showStaticInNewWindow();" value="show map in new window" />
</div>
</div>
<br style="clear: both" />
<hr />
<div class="par-div">
<p>
To create a corresponding static map, simply use following <img> tag:
</p>
<textarea id="perma" name="perma" style="width: 700px" rows="3"></textarea>
</div>
</div>
<div id="footer">
<div style="text-align:center;padding:7px;color:#ccc">
sponsored by <a href="http://dfacts.de" style="color:#ccc">dFacts Network</a>
</div>
</div>
</div>
</body>
</html>