-
Notifications
You must be signed in to change notification settings - Fork 2
/
image-local-coordinates.html
241 lines (193 loc) · 6.48 KB
/
image-local-coordinates.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
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.2/proj4.min.js" integrity="sha512-EKjCCRjU5ClBwaRb6dGbElFNWJTE7Ek7+PlXelkum5uofPwlf6u2VRch1ty3csFCQn9XdyX89Te8jVg61qtm3Q==" crossorigin="anonymous"></script>
<script async src="https://cdn.jsdelivr.net/npm/geotiff"></script>
<script>
var sepChar;
var tiff;
var canvas;
var global_rgb, global_canvas;
var layerControl;
var map;
var markerGroup;
$(function() {
map = L.map("map", {minZoom: -10, maxZoom: 25, crs: L.CRS.Simple});
markerGroup = L.layerGroup().addTo(map);
map.on('click', function(e) {
// create marker
var m = new L.marker(e.latlng, {draggable: true}).addTo(markerGroup);
// add a species attribute
m.species = undefined;
// dragging the marker will update the CSV
m.on('dragend', writeCSV);
// create and show empty popup, will be filled on popupopen
m.bindPopup("<div/>").openPopup();
// store in global speciesMarkers array
// speciesMarkers.push(m);
});
map.on('popupopen', function(evt) {
// create a select dropdown menu
var selectElement = $(constructSelectElementText(evt.popup._source.species));
// attach event handler
selectElement.on('change', function() {
// popup._source is the marker, store the selected list value on the marker
evt.popup._source.species = selectElement.val();
// trigger marker change function
markerChange(evt.popup._source, evt.popup._source.species);
});
var pc = $("<div/>");
// construct a "delete this marker" link
var del_link = $('<a href="#" style="color:red; align:right">delete marker</a>');
del_link.on('click', function() {
evt.popup._source.removeFrom(markerGroup);
markerChange(evt.popup._source, undefined);
});
pc.append(selectElement,"<br/>",del_link);
// set the select element as the contents of the popup. The [0] gets the native DOM element, which is necessary for setContent.
evt.popup.setContent(pc[0]);
});
// dataset id is first column in csv; write CSV if changed
$(datasetid).on('change', writeCSV);
// CSV separator character; store and write CSV if changed
$(sc).on('change',function() {
sepChar = $(sc).val();
writeCSV();
});
sepChar = $(sc).val();
$(helpcard).hide();
$(loadingindicator).hide();
$(openhelp).on('click', function(e) {
$(helpcard).toggle();
$(helpcard).css({
"position": "absolute",
"background-color":"white",
"left": e.pageX + 'px',
"top": e.pageY + 'px'
})
});
$(closehelp).on('click',function() {
$(helpcard).hide();
});
$(load_remote_image).on('click', function() {
var imageLayer = L.imageOverlay($(url).val(), [[0,0],[Number($(h).val()),Number($(w).val())]]).addTo(map);
map.fitBounds(imageLayer._bounds);
});
}); // end $(), which is the jquery init function
/**
* called after a marker has changed
*
* @param marker the leaflet marker
* @param species the new species value
*/
var markerChange = function(marker,species) {
// don't do anything fancy, just redraw the CSV
writeCSV();
}
/**
* write the CSV textbox from the speciesMarkers array
*/
var writeCSV = function() {
// csv header
var res = "datasetid"+sepChar+"y"+sepChar+"x"+sepChar+"species\n";
const dsid = $(datasetid).val();
speciesMarkers = markerGroup.getLayers();
for (var i=0;i<speciesMarkers.length;i++) {
res += dsid + sepChar
+ speciesMarkers[i].getLatLng().lat.toFixed(0) + sepChar
+ speciesMarkers[i].getLatLng().lng.toFixed(0) + sepChar
+ speciesMarkers[i].species
+ "\n";
}
// write CSV to the textbox
$(outcsv).val(res);
}
/**
* construct a select element with values from the form element "#possiblespecies".
*
* @param selectedText the string that should be selected, defaults to undefined
*
* @return A string like '<select><option value="...">...</option></select>'
*/
var constructSelectElementText = function(selectedText="undefined") {
var r = "<select>";
var sp = $(possiblespecies).val().split(",");
// add undefined as selectable value
sp.push("undefined");
for (var i=0;i<sp.length;i++) {
// create option, mark selected if its equal to the function parameter
r += "<option value='"+sp[i]+"'"+(sp[i]==selectedText?" selected":"")+">"+sp[i]+"</option>";
}
r += "</select>";
return r;
}
</script>
<style type="text/css">
#map {
height: 500px;
width: 500px;
}
h2 {
margin-top:0.1em;
margin-left:0.1em;
font-family: Arial, Helvetica, sans-serif;
}
#helpcard {
width: 30%;
height: 500px;
scrolling: auto;
z-index: 1000;
}
#loadingindicator {
position: relative,
display: none,
background-color: white,
left: 200px,
top: 80px,
width: 30%,
z-index: 1000
}
</style>
</head>
<body>
<div class="w3-container w3-right">
<a href="#" id="openhelp">about/help</a>
<ul class="w3-ul w3-border">
<li>
Image URL: <input type="text" id="url" size="60" value="https://upload.wikimedia.org/wikipedia/commons/9/94/Monodon_monoceros_pod.jpg"><br/>
Width: <input type="text" id="w" size="6" value="2197"><br/>
Height:<input type="text" id="h" size="6" value="1742"><br/>
<input type="button" id="load_remote_image" value="Load remote image"><span id="loadingindicator" class="w3-yellow">Loading...please wait</span> <br/>
</li>
<li>
Possible observations, separated by comma: <input type="text" id="possiblespecies" value="sheep,cow,velociraptor,trex,elefant,another_cow" size="70"/><br/>
Dataset id: <input type="text" id="datasetid" name="datasetid" value="s1"/><br/>
Separator character: <input type="text" id="sc" name="sc" value=";" size="1"/><br/>
</li>
<li>
<textarea id="outcsv" rows="10" cols="50">
</textarea>
</li>
<li>
<div id="log" class="w3-yellow">
</div>
</li>
</ul>
</div>
<div id="map" class="w3-left w3-margin"></div>
<div class="w3-container" id="helpcard">
<div class="w3-card-4">
<header class="w3-container w3-blue">
<h1>About this tool / help <span id="closehelp" class="w3-button w3-display-topright">×</span></h1>
</header>
<div class="w3-container">
<p>Image annotation for non-georeferenced images
</p>
</div>
</div>
</div>
</body>
</html>