forked from MarkusH/django-osm-field
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
186 lines (145 loc) · 7.62 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
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>osm-field jQuery Plugin by sinnwerkstatt</title>
<link rel="stylesheet" href="stylesheets/vendor/styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="osm_field/static/css/vendor/leaflet.css">
<link rel="stylesheet" href="osm_field/static/css/osm_field.css">
<script src="osm_field/static/js/vendor/jquery-2.1.0.min.js"></script>
<script src="osm_field/static/js/vendor/leaflet.js"></script>
<script src="osm_field/static/js/osm_field.js"></script>
<style type="text/css">
@font-face { font-family: sanchez; src: url(osm_field/static/sanchez.woff); }
body {
padding: 1em 3em 1em 3em;
font-family: sanchez, sans-serif;
background: radial-gradient(ellipse at center, rgba(254,255,255,1) 0%,rgba(224,241,249,1) 100%);
}
pre {
color: #fff;
background-color: #555;
padding: 15px;
}
</style>
</head>
<body>
<h1>osm-field jQuery Plugin</h1>
<p>
View the Project on GitHub:
<a href="https://github.com/sinnwerkstatt/django-osm-field">sinnwerkstatt/django-osm-field</a>
</p>
<h3>The jQuery plugin</h3>
<p>This page describes the jQuery part of the Django osm field plugin. You can use this stand alone in your own projects if you just pick the <a href="osm_field/static/js/osm_field.js">osm_field.js</a> plugin file. Everything else in the repository is the Django project. You might also find it <a href="https://pypi.python.org/pypi/django-osm-field">on python.org</a>.
<p>The jQuery osmfield plugin is a geolocation picker that turns three INPUT elements into a position locator. Type in the address. If the <a href="http://wiki.openstreetmap.org/wiki/Nominatim">OpenStreetMap Nominatim API</a> finds matching coordinates, a map will be shown. You can specify details in the INPUT now and correct the location in the map. Finally, the Address and coordinates will be saved in the original INPUT elements. The dependencies are <a href="http://leafletjs.com/">Leaflet</a> and <a href="http://jquery.com/">jQuery</a>.</p>
<h3>Simple osmfield</h3>
<p>Let's start with jQuery, Leaflet, the Plugin and some lines CSS…</p>
<pre><code><link rel="stylesheet" href="leaflet.css">
<link rel="stylesheet" href="osm_field.css">
<script src="jquery-2.1.0.min.js"></script>
<script src="leaflet.js"></script>
<script src="osmfield.js"></script></code></pre>
<p>…add the INPUT elements…</p>
<pre><code><input class="osmfield" id="example1" />
<input type="hidden" id="example1_lat" />
<input type="hidden" id="example1_lon" /></code></pre>
<p>...it will initialize itself if it has the class <em>osmfiled</em>.</p>
<p>Try it! Type Berlin or something.</p>
<p>
<input class="osmfield" id="example1" />
<input type="hidden" id="example1_lat" />
<input type="hidden" id="example1_lon" />
</p>
<p>The address' INPUT element must have an ID. The same ID with appended “_lat” and “_lon” are the IDs of (usually hidden) latitude and longitude INPUTs.</p>
<h3>osmfield with address</h3>
<p>Set a default address.</p>
<pre><code><input class="osmfield" id="example2" value="Thinkfarm Berlin" />
<input type="hidden" id="example2_lat" />
<input type="hidden" id="example2_lon" /></code></pre>
<p>
<input class="osmfield" id="example2" value="Thinkfarm Berlin" />
<input type="hidden" id="example2_lat" />
<input type="hidden" id="example2_lon" />
</p>
<h3>osmfield with address and geo coordinates</h3>
<p>In this example, the geo coordinates are already given on initialization. They do not have to match the address.</p>
<pre><code><input class="osmfield" id="example3" value="Thinkfarm Berlin" />
<input id="example3_lat" value="41.6147605" type="hidden" />
<input id="example3_lon" value="0.6267842" type="hidden" /></code></pre>
<p>
<input class="osmfield" id="example3" value="Thinkfarm Berlin" />
<input id="example3_lat" value="41.6147605" type="hidden" />
<input id="example3_lon" value="0.6267842" type="hidden" />
</p>
<h3>osmfield with just geo coordinates</h3>
<pre><code><input class="osmfield" id="example4" />
<input id="example4_lat" value="41.6147605" type="hidden" />
<input id="example4_lon" value="0.6267842" type="hidden" /></code></pre>
<p>Works but does not make sense.</p>
<p>
<input class="osmfield" id="example4" />
<input id="example4_lat" value="41.6147605" type="hidden" />
<input id="example4_lon" value="0.6267842" type="hidden" />
</p>
<h3>Internationalization</h3>
<pre><code><input class="osmfield" id="example5"
value="München"
lang="de" />
<input id="example5_lat" type="hidden" />
<input id="example5_lon" type="hidden" /></code></pre>
<p><em>Munich</em> or <em>München</em>? Usually you have a document wide setting like <em><html lang="en-US"></em>. osmfield uses the <em>lang</em> attribute that is set nearest to the selector.</p>
<p>
<input class="osmfield" id="example5" value="München" lang="de" />
<input id="example5_lat" type="hidden" />
<input id="example5_lon" type="hidden" />
</p>
<h3>Use the data</h3>
<pre><code><script type="application/javascript">
$(function() {
$('button#getvalues').click(function() {
$('pre#values').text(
'address: '+$('input[name=yourhome]').val()+'\n'+
'latitude: '+$('input[name=yourhome_lat]').val()+'\n'+
'longitude: '+$('input[name=yourhome_lon]').val()
);
});
});
</script>
<form action="." method="get">
<input name="address" class="osmfield" id="example6" value="European Quarter, Brussels" />
<input name="latitude" id="example6_lat" type="hidden" />
<input name="longitude" id="example6_lon" type="hidden" />
<input type="submit" />
</form>
<button id="getvalues" />Get me the values!</button>
<pre id="values"></pre></code></pre>
<p>You can read the address and geo coordinates whenever you want. This even works without user interaction simply after initailzation. Click the buttons.</p>
<form action="." method="get">
<p>
<input name="address" class="osmfield" id="example6" value="European Quarter, Brussels" />
<input name="latitude" id="example6_lat" type="hidden" />
<input name="longitude" id="example6_lon" type="hidden" />
</p>
<p>Click and look at the URL:
<input type="submit" />
</form>
<button id="getvalues" />Get me the values!</button>
<pre id="values"></pre>
<script type="application/javascript">
$(function() {
$('button#getvalues').click(function() {
$('pre#values').text(
'address: ' + $('#example6').val() + '\n' +
'latitude: ' + $('#example6_lat').val() + '\n' +
'longitude: ' + $('#example6_lon').val()
);
});
});
</script>
</body>
</html>