forked from althurayya/althurayya.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
279 lines (265 loc) · 14.3 KB
/
editor.html
File metadata and controls
279 lines (265 loc) · 14.3 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
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
268
269
270
271
272
273
274
275
276
277
278
<html>
<head>
<title>Edit Sources</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://rawgit.com/emeeks/abcc82cc61c52fc47b19/raw/61a7ad001f0a3c4323b8b21071d2e749df367519/d3map.css">
<link rel="stylesheet" href="sourceEditor.css"/>
</head>
<script>
var places = {};
function saveData(data, fileName) {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var json = JSON.stringify(data),
blob = new Blob([json], {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
function trueSource(placeUri, fUri, elemId) {
// Stop events bubbling to the highest point in the DOM.
// i.e. stop firing the (parent)<li> tag's click event
window.event.stopPropagation();
places[placeUri].properties.sources_arabic[fUri].status = 'true';
d3.select("#false_"+placeUri+"_btn").remove();
d3.select("#true_"+placeUri+"_btn").remove();
if (d3.select("#edit_"+placeUri+"_btn").empty() != true)
var editBtn = d3.select("#edit_"+placeUri+"_btn");
else
var editBtn = "<button id= \"edit_"+ placeUri+ "_btn\" "
+ "onclick=\"edit('"+ placeUri+"','"+fUri+"','"+elemId+"');\" "
+ "style = \'display: inline; direction: ltr;\'>Edit!</button>";
var divHtml = d3.select("#" + elemId).html();
divHtml += editBtn ;
d3.select("#" + elemId).html(divHtml);
d3.select('#saveDiv').style("display", "block")
}
function falseSource(placeUri, fUri, elemId) {
window.event.stopPropagation();
delete places[placeUri].properties.sources_arabic[fUri];
d3.select("#false_"+placeUri+"_btn").remove();
d3.select("#true_"+placeUri+"_btn").remove();
d3.select("#saveDiv").style("display", "block");
d3.select("#" + elemId).html("<p>Already deleted!</p>");
}
function edit( placeUri, fUri, elemId) {
window.event.stopPropagation();
d3.select("#edit_"+placeUri+"_btn").remove();
var trueBtn = "<button class=\"button \" id= \"true_"+ placeUri+ "_btn\" "
+ "onclick=\"trueSource('"+ placeUri+"','"+fUri+"','"+elemId+"');\" "
+ "style = \"display: inline; direction: ltr;\">True!</button>"
var falseBtn = "<button class=\"button \" id= \"false_"+ placeUri+ "_btn\" "
+ "onclick=\"falseSource('"+ placeUri+"','"+fUri+"','"+elemId+"');\" "
+ "style = \"display: inline; direction: ltr;\">False!</button>";
var divHtml = d3.select("#" + elemId).html();
divHtml += trueBtn + falseBtn;
d3.select("#" + elemId).html(divHtml);
d3.select('#saveDiv').style("display", "none");
}
function saveChanges(){
var features = [];
Object.keys(places).forEach(function(pUri) {
features.push(places[pUri])
})
var writeplaces = {"type": "FeatureCollection", "features": features};
var blob = new Blob([JSON.stringify(writeplaces)], {type: "octet/stream"});
// Save all objects in a new file (or as the same of orignial file, places.geojson)
// The edited file should be used for each time that the page is loaded, to show the edited data
saveAs(blob, "/Users/romanov/Documents/c.GitProjects/althurayya.github.io/master/places.geojson");
// d3.select("#false_"+placeUri+"_btn").remove();
// d3.select("#true_"+placeUri+"_btn").remove();
d3.select('#saveDiv').style("display", "none");
console.log("diplay: " +d3.select('#saveDiv'))
}
// var toggleVisibility = (function( display){
// return function(){
// display = display == "none" ? "block" : "none";
// d3.select(this).style("display", display);
// }
// })();
function makeSomeMaps() {
map = d3.carto.map();
d3.select("#map").call(map);
// Carto map layer
wcLayer = d3.carto.layer.tile();
wcLayer.tileType("stamen")
.path("watercolor")
.label("Water Color Map")
.visibility(true);
modernLayer = d3.carto.layer.tile();
modernLayer
.path("elijahmeeks.map-azn21pbi")
.label("Modern Map")
.visibility(false);
// Custom modal for infobox
jsonModal = d3.carto.modal();
jsonModal.formatter(
function (d) {
return "<p>" + "Cornu name: " + d.properties.cornuData["toponym_arabic"] + "</br>"
+ "Cornu URI: " + d.properties.cornuData["cornu_URI"] + "</br>"
+ "Other cornu title: " + d.properties.cornuData["toponym_arabic_other"] + "</br>"
+ "Cornu lat: " +d.properties.cornuData["coord_lat"] + "</br>"
+ "Cornu lon: " + d.properties.cornuData["coord_lon"] + "</br>"
+ "Cornu region: " + d.properties.cornuData["region_spelled"] + "</br>"
+ "Translit: " + d.properties.cornuData["toponym_translit"] + "</br>"
+ "Sources: " + JSON.stringify(d.properties.sources_arabic) + "</br>"
+ "</p>"
}
);
pointLayer = d3.carto.layer.geojson();
pointLayer
.path("./master/places.geojson")
.label("places")
.cssClass("point")
.renderMode("svg")
.modal(jsonModal) // using custom modal to be shown in infobox
.clickableFeatures(true)
.on("load", loadPlaces);
map.addCartoLayer(wcLayer)
.addCartoLayer(pointLayer);
map.centerOn([44.361488, 33.312806], "latlong").setScale(3);
function loadPlaces() {
d3.json("../Data/places.geojson", function(error, data) {
data.features.forEach(function(d) {
places[d.properties.cornuData['cornu_URI']] = d;
})
})
d3.selectAll("circle").filter(function (c) {
return c.properties.cornuData.top_type_hom == 'xroads' ||
c.properties.cornuData.top_type_hom == 'waystations' ||
c.properties.cornuData.top_type_hom == 'regions';
}).remove();
d3.selectAll("circle")
.attr("r", 3);
d3.selectAll('circle').on('click', function (c) {
d3.select("#initDesc").style("display", 'none')
var q = queue();
// Read all the data file named as one of the sources of a place,
// using d3.queue
Object.keys(c.properties.sources_arabic).forEach(function (source) {
q = q.defer(d3.json, "./sources/" + source);
})
// Call the "onDataLoaded" function when all the files are loaded
q.await(onDataLoaded);
// Go through the all files and read the content to show them on page
function onDataLoaded(error) {
if (!error) {
// Loop files:
// for (var i=1; i<arguments.length; i++)
// slice the files into an array:
var sources = Array.prototype.slice.call(arguments, 1);
var sourcesDiv = d3.select("#sources")
// Clear the old innerhtml of sourcesDiv before adding new html
sourcesDiv.html("");
if (sources.length == 0)
sourcesDiv.html("<p>No sources available!</p>");
// For each source, add an li element holding source value as text
sourcesDiv.selectAll("li").data(sources).enter()
.append("li")
// Add html content of li to be shown/hidden when li is clicked,
// Content holds the text of relating source and relevant edit buttons
.html(function (s) {
var html = "";
var uri = s.features[0].uri;
var id = "id_" + uri.replace(/\./g,'_');
var div = s.features[0].source + ":"+ s.features[0].title
+ "<div id=\"" + id + "\" style = \"display:none;\"><span style = \"direction: rtl;\""
+ s.features[0].text + "</span>";
// Check the sources status
Object.keys(c.properties.sources_arabic).forEach(function (source) {
if (source == null) {alert("hi"); return "<p>No sources available!</p>";}
var placeTopUri = c.properties.cornuData['cornu_URI'];
if (source == uri)
// If the source status is "na", show the text and add True/False buttons to edit
if (c.properties.sources_arabic[source]['status'] == 'na') {
var trueBtn = "<button class=\"button \" id= \"true_"+ placeTopUri+ "_btn\" "
+ "onclick=\"trueSource('" + placeTopUri+"','"+uri+"','"+id+"');\" "
+ "style = \"direction: ltr;\">True!</button>"
var falseBtn = "<button class=\"button \" id= \"false_"+ placeTopUri+ "_btn\" "
+ "onclick=\"falseSource('" + placeTopUri+"','"+uri+"','"+id+"');\" "
+ "style = \"direction: ltr;\">False!</button>";
html = div + trueBtn + falseBtn + "<br><br></div>";
}
// else If the source status is "True", show it and add edit button to edit
// the false sources should be deleted in previous edits
else {
var editBtn = "<button class=\"button \" id= \"edit_"+ placeTopUri+ "_btn\" "
+ "onclick=\"edit('"+ placeTopUri+"','"+uri+"','"+id+"');\" "
+ "style = \'direction: ltr;\'>Edit!</button>";
html = div + editBtn + "<br><br></div>";
}
})
return html;
})
.on("click", collExpand);
} else
return console.log(error);
}
function collExpand(d) {
var div = d3.select(this).select("div")
var display = d3.select(this).select("div").style("display");
d3.select(this).select("div")
.style("display", display == 'none' ? 'block' : 'none')
}
})
}
}
</script>
<body onload="makeSomeMaps()">
<div id="map"></div>
<div style="right: 20px;" id="rightControls" class="controlsDiv">
<div class="buttonContainer">
<div id="sourcesContainer" class="buttonContainer">
<span style="color:gray;">Toponym Sources:</span><br/><br/>
<span id="initDesc" style="color:gray; display:block">Click on a place to see the Arabic sources available</span>
<div id="sources">
<!--<ul >-->
<!-- -->
<!--</ul>-->
<!--<input id="match" type="radio" name="match" value="match"> Match<br/>-->
<!--<input id="not-match" type="radio" name="match" value="not-match"> Not a match<br/>-->
<!--<input id="not-sure" type="radio" name="match" value="not-sure"> Not sure!<br/>-->
<!--Used for accessing the clicked circle-->
</div>
<div id="saveDiv" style="display: none">
<hr>
<button id="saveBtn" onclick="saveChanges()">Save Changes!</button>
</div>
</div>
</div>
</div>
<footer>
<script src="http://d3js.org/d3.v3.js" charset="utf-8" type="text/javascript"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js" type="text/javascript"></script>
<script src="https://rawgit.com/Masoumeh/0390.IbnAhmadMuqaddasi.AhsanTaqasim/master/js/ext_lib/tile.js" type="text/javascript"></script>
<script src="https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.min.js" type="text/javascript"></script></footer>
<script src="https://rawgit.com/eligrey/FileSaver.js/master/FileSaver.js"></script>
<!--<script src="/socket.io/socket.io.js"></script>-->
<!--Server script-->
<!--<script>-->
<!--var socket = io();-->
<!--function writeDataToFile(d, f) {-->
<!--var str = { data: d, file:f};-->
<!--socket.emit('writeDataToFile', str);-->
<!--}-->
<!--function writeJsonToFile(d,f) {-->
<!--var str = { data: d, file:f};-->
<!--socket.emit('writeJsonToFile',str);-->
<!--}-->
<!--function appendDataToFile(d, f) {-->
<!--var str = { data: d, file:f};-->
<!--socket.emit('appendDataToFile', str);-->
<!--}-->
<!--function readProcessedData(func) {-->
<!--socket.emit('readProcessedData',"hi");-->
<!--socket.on('readProcessedData', function(msg){-->
<!--func(msg);-->
<!--});-->
<!--}-->
<!--</script>-->
</body>
</html>