@@ -113,7 +113,123 @@ <h3>Edit GraphQL Query</h3>
113
113
114
114
// GraphQL query
115
115
116
+
116
117
const simpleQuery = `
118
+ {
119
+ locations(limit: 10)
120
+ @pattern(of: "?s a coy:Country", from: "s", to: "s")
121
+ @prefix(name: "rdfs", iri: "http://www.w3.org/2000/01/rdf-schema#")
122
+ @prefix(name: "geo", iri: "http://www.opengis.net/ont/geosparql#")
123
+ @prefix(name: "geof", iri: "http://www.opengis.net/def/function/geosparql/")
124
+ @prefix(name: "norse", iri: "https://w3id.org/aksw/norse#")
125
+ @prefix(name: "coy", iri: "https://schema.coypu.org/global#")
126
+ {
127
+ type @one @pattern(of: "BIND(?x AS ?xx) BIND('Feature' AS ?y)", from: "x", to: "y")
128
+
129
+ # Properties container
130
+ properties @one @pattern(of: "BIND(?x AS ?y)", from: "x", to: "y") {
131
+
132
+ # Style
133
+ style @one @pattern(of: """
134
+ BIND(?x as ?y)
135
+ BIND(norse:json.object("fillColor", "red") AS ?json)
136
+ """, from: "x", to: "json")
137
+
138
+ label @one
139
+ @pattern(of: """
140
+ SELECT ?s ?o {
141
+ ?s rdfs:label ?o .
142
+ FILTER(langMatches(lang(?o), 'en'))
143
+ }
144
+ """, from: "s", to: "o")
145
+ }
146
+
147
+ # Geometry container
148
+ # Note: simplifyDp simplifies polygons on query time
149
+ # Reduces amount of data and thus loading time
150
+ geometry @one
151
+ @pattern(of: """
152
+ ?s geo:hasGeometry/geo:asWKT ?x .
153
+ BIND(STRDT(STR(geof:asGeoJSON(
154
+ geof:simplifyDp(?x, 0.2)
155
+ )), norse:json) AS ?o)
156
+ """, from: "s", to: "o")
157
+ }
158
+ }
159
+ ` ;
160
+
161
+ const complexQuery = `
162
+ {
163
+ locations(limit: 1000)
164
+ @pattern(of: "?s a coy:Country", from: "s", to: "s")
165
+ @prefix(name: "", iri: "https://schema.coypu.org/global#")
166
+ @prefix(name: "rdfs", iri: "http://www.w3.org/2000/01/rdf-schema#")
167
+ @prefix(name: "geo", iri: "http://www.opengis.net/ont/geosparql#")
168
+ @prefix(name: "geof", iri: "http://www.opengis.net/def/function/geosparql/")
169
+ @prefix(name: "norse", iri: "https://w3id.org/aksw/norse#")
170
+ @prefix(name: "afn", iri: "http://jena.apache.org/ARQ/function#")
171
+ @prefix(name: "coy", iri: "https://schema.coypu.org/global#")
172
+ {
173
+ type @one @pattern(of: "BIND(?x AS ?xx) BIND('Feature' AS ?y)", from: "x", to: "y")
174
+
175
+ # Properties container
176
+ properties @one @pattern(of: "BIND(?x AS ?y)", from: "x", to: "y") {
177
+
178
+ # Style
179
+ style @one @pattern(of: """
180
+ BIND(?x as ?y)
181
+ BIND(CONCAT('#', SUBSTR(MD5(STR(?x)), 1, 6)) AS ?color)
182
+ BIND(norse:json.object("fillColor", ?color) AS ?json)
183
+ """, from: "x", to: "json")
184
+
185
+
186
+ label @one
187
+ @pattern(of: """
188
+ SELECT ?s ?o {
189
+ ?s rdfs:label ?o .
190
+ FILTER(langMatches(lang(?o), 'en'))
191
+ }
192
+ """, from: "s", to: "o")
193
+
194
+ features
195
+ @pattern(of: """
196
+ SELECT * {
197
+ {
198
+ ?s ?p ?o .
199
+ FILTER(?p NOT IN (rdfs:label))
200
+ }
201
+ # Auto-derive property cardinalities from all data
202
+ { SERVICE <cache:> {
203
+ { SELECT ?p (MAX(?c) AS ?pc) {
204
+ SELECT ?x ?p (COUNT(*) AS ?c) {
205
+ ?x ?p ?z
206
+ } GROUP BY ?x ?p
207
+ } GROUP BY ?p }
208
+ }
209
+ }
210
+ }
211
+ """, from: "s", to: "o")
212
+ @index(by: "afn:localname(?p)", oneIf: "?pc = 1")
213
+ }
214
+
215
+ # Geometry Section
216
+ geometry @one
217
+ @pattern(of: """
218
+ ?s geo:hasGeometry/geo:asWKT ?x .
219
+ BIND(STRDT(STR(geof:asGeoJSON(
220
+ geof:simplifyDp(?x, 0.2)
221
+ )), norse:json) AS ?o)
222
+ """, from: "s", to: "o")
223
+ }
224
+ }
225
+ ` ;
226
+
227
+
228
+
229
+
230
+
231
+
232
+ const simpleQueryOld = `
117
233
{
118
234
locations(limit: 10)
119
235
@pattern(of: "?s a coy:Country", from: "s", to: "s")
@@ -144,7 +260,7 @@ <h3>Edit GraphQL Query</h3>
144
260
}
145
261
` ;
146
262
147
- const complexQuery = `
263
+ const complexQueryOld = `
148
264
{
149
265
locations(limit: 1000)
150
266
@pattern(of: "?s a coy:Country", from: "s", to: "s")
@@ -242,7 +358,7 @@ <h3>Edit GraphQL Query</h3>
242
358
// Add data to the map
243
359
async function addDataToMap ( ) {
244
360
const query = document . getElementById ( 'graphqlQuery' ) . value ;
245
- const locations = await fetchData ( query ) ;
361
+ var locations = await fetchData ( query ) ;
246
362
247
363
// Clear existing map layers
248
364
map . eachLayer ( ( layer ) => {
@@ -252,10 +368,13 @@ <h3>Edit GraphQL Query</h3>
252
368
} ) ;
253
369
254
370
locations . forEach ( location => {
255
- L . geoJSON ( location . geometry , {
371
+ L . geoJSON ( location , {
256
372
onEachFeature : ( feature , layer ) => {
257
- const popupContent = createPopupContent ( location ) ;
373
+ const popupContent = createPopupContent ( feature . properties ) ;
258
374
layer . bindPopup ( popupContent ) ;
375
+ } ,
376
+ style : ( feature ) => {
377
+ return feature . properties && feature . properties . style ;
259
378
}
260
379
} ) . addTo ( map ) ;
261
380
} ) ;
0 commit comments