-
Notifications
You must be signed in to change notification settings - Fork 31
/
FeatureInfoDisplay.js
executable file
·757 lines (655 loc) · 29.2 KB
/
FeatureInfoDisplay.js
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
*
* FeatureInfoDisplay.js -- part of Quantum GIS Web Client
*
* Copyright (2010-2012), The QGIS Project All rights reserved.
* Quantum GIS Web Client is released under a BSD license. Please see
* https://github.com/qgis/qgis-web-client/blob/master/README
* for the full text of the license and the list of contributors.
*
*/
/* FeatureInfos are presented to the user in two ways using OpenLayers.Popup classes:
* If the mouse stops and GetFeatureInfo has results for this mouse position
* a small box presents the contents of the info field (GetProjectSettings) or the
* field named "toolbox" (GetCapabilities), this is called hoverPopup throughout this script.
* If the user clicks in the map the contents of all visible fields (and if activated the wkt geometry)
* is presented in a popup called clickPopup throughout this script.
* hoverPopups are disabled when a clickPopup is open, however clicking at another position in the map
* closes the currently opened clickPopup and opens a new one (if there is GetFeatureInfo response).
* If the cursor is at a position where there is GetFeatureInfo response it indicates the possibility
* to click by changing to "hand".
*/
function showFeatureInfo(evt) {
removeClickPopup();
if (hoverPopup) {
removeHoverPopup();
}
if (identifyToolActive) {
var map = geoExtMap.map; // gets OL map object
if (window.DOMParser) {
var parser = new DOMParser();
xmlDoc = parser.parseFromString(evt.text, "text/xml");
} else {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(evt.text);
}
//start locationservices
var text = "";
var locationText = "<h2>" + TR.fiLocation + "</h2>";
var locationUnits = map.getLonLatFromPixel(evt.xy);
var locationProj = projectData.crs == Eqwc.currentMapProjection[0] ? null : Eqwc.currentMapProjection[2];
var locationObj = new QGIS.LocationService({location: locationUnits, language: projectData.lang, projection: locationProj});
var popupItems = [];
if (Eqwc.settings.showCoordinatesIdentify) {
text = "</br>";
popupItems.push(
{
xtype: 'box',
html: locationText
}, {
id: "fi_location",
//margins: '5 5 5 5',
xtype: 'box',
html: '<tr><td>' + locationObj.locationToString() + '</td></tr>'
});
}
if (projectData.locationServices != null) {
text = "</br>";
for (var l = 0; l < projectData.locationServices.length; l++) {
locationObj.getService({
name: projectData.locationServices[l].name,
key: projectData.locationServices[l].key,
provider: projectData.locationServices[l].provider
});
popupItems.push({
id: "fi_" + projectData.locationServices[l].name,
//margins: '5 5 5 5',
xtype: 'box',
html: '</br>'
});
}
}
locationObj.on("elevation", updateElevation);
locationObj.on("address", updateAddress);
// open AttributeTree panel
featureInfoResultLayers = [];
highLightGeometry = [];
parseFIResult(xmlDoc);
featureInfoResultLayers.reverse();
//highLightGeometry.reverse();
// if (hoverPopup) {
// removeHoverPopup();
// }
// if (clickPopup) {
// removeClickPopup();
// }
//
if (featureInfoResultLayers.length > 0) {
if (identificationMode == 'topMostHit') {
text += featureInfoResultLayers[0];
// featureInfoHighlightLayer.addFeatures(highLightGeometry[0]);
// //feature.geometry.getBounds().getCenterLonLat()
} else {
for (var i = 0; i < featureInfoResultLayers.length; i++) {
text += featureInfoResultLayers[i];
//featureInfoHighlightLayer.addFeatures(highLightGeometry[i]);
}
}
popupItems.push({
id: "fi_qgis",
xtype: 'box',
//margins: '3 0 3 3',
html: text
});
}
//new way GeoExt Popup
clickPopup = new GeoExt.Popup({
title: clickPopupTitleString[lang],
location: locationUnits,
map: map,
autoScroll: true,
bodyStyle: 'padding:5px',
//layout: 'accordion',
items: popupItems,
maximizable: true,
collapsible: true,
listeners: {
close: onClickPopupClosed,
beforeshow: function () {
var maxHeight = geoExtMap.getHeight() * 0.8;
var minWidth = 280;
if ((geoExtMap.getWidth() * 0.25) > minWidth) {
this.setWidth(geoExtMap.getWidth() * 0.25);
} else {
this.setWidth(minWidth);
}
if (this.getHeight() > maxHeight) {
this.setHeight(maxHeight);
}
}
}
});
if (popupItems.length>0) {
clickPopup.show();
}
//old way with OpenLayers.Popup
// clickPopup = new OpenLayers.Popup.FramedCloud(
// null, // id
// map.getLonLatFromPixel(evt.xy), // lonlat
// null, //new OpenLayers.Size(1,1), // contentSize
// text, //contentHTML
// null, // anchor
// true, // closeBox
// onClickPopupClosed // closeBoxCallBackFunction
// );
// // For the displacement problem
// clickPopup.panMapIfOutOfView = Ext.isGecko;
// clickPopup.autoSize = true;
// clickPopup.events.fallThrough = false;
// map.addPopup(clickPopup); //*/
changeCursorInMap("default");
}
activateGetFeatureInfo(true);
}
function showFeatureInfoHover(evt) {
var map = geoExtMap.map; // gets OL map object
if (identifyToolActive) {
if (hoverPopup) {
removeHoverPopup();
}
if (window.DOMParser) {
var parser = new DOMParser();
xmlDoc = parser.parseFromString(evt.text, "text/xml");
} else {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(evt.text);
}
var layerNodes = xmlDoc.getElementsByTagName("Layer");
var text = '';
var result = false;
//test if we need to show the feature info layer title
//either from global setting or from project setting
var showFILayerTitle = showFeatureInfoLayerTitle;
if (mapThemeSwitcher) {
if (mapThemeSwitcher.activeProjectData != undefined) {
showFILayerTitle = mapThemeSwitcher.activeProjectData.showFeatureInfoLayerTitle;
}
}
for (var i = layerNodes.length - 1; i > -1; --i) {
//case vector layers
var featureNodes = layerNodes[i].getElementsByTagName("Feature");
// show layer display field or if missing, the attribute 'tooltip'
var tooltipAttributeName = wmsLoader.layerProperties[layerNodes[i].getAttribute("name")].displayField || "tooltip";
for (var j = 0; j < featureNodes.length; ++j) {
if (j == 0) {
if (showFILayerTitle) {
text += '<h2 class="hoverLayerTitle">' + wmsLoader.layerProperties[layerNodes[i].getAttribute("name")].title + '</h2>';
}
result = true;
}
var attribNodes = featureNodes[j].getElementsByTagName("Attribute");
var attributesDict = {};
for (var k = 0; k < attribNodes.length; ++k) {
attributesDict[attribNodes[k].getAttribute("name")] = attribNodes[k].getAttribute("value");
}
var tooltipFieldAvailable = attributesDict.hasOwnProperty(tooltipAttributeName);
var geometryFieldAvailable = attributesDict.hasOwnProperty('geometry');
if (tooltipFieldAvailable) {
var aValue = attributesDict[tooltipAttributeName]
if (aValue.match(/</)) {
text += aValue;
}
else {
attribText = '<p>' + aValue.replace(/\n/, "<br/>");
attribText = attribText.replace("\n", "<br/>");
text += attribText + '</p>';
}
text += '<hr class="hrHoverLayer"/>';
}
else if (tooltipTemplates && tooltipTemplates.hasOwnProperty(layerNodes[i].getAttribute("name"))) {
templateText = tooltipTemplates[layerNodes[i].getAttribute("name")].template;
tooltipText = templateText.replace(/<%(\w*)%>/g, function (m, key) {
var value = attributesDict.hasOwnProperty(key) ? attributesDict[key] : "";
return value.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
});
text += tooltipText + "<br/>";
} else if (tooltipAttributeName.indexOf('[%') !== -1) { // Look into displayField for template tags...
var tooltipText = tooltipAttributeName;
var re = new RegExp(/\[%[^"]*"(.*?)"[^"]*%\]/g);
var ttmatch;
while (ttmatch = re.exec(tooltipAttributeName)) {
var key = ttmatch[1];
var val = attributesDict.hasOwnProperty(key) ? attributesDict[key] : "";
tooltipText = tooltipText.replace(ttmatch[0], val);
}
text += tooltipText + "<br/>";
}
if (geometryFieldAvailable) {
var feature = new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT(attributesDict["geometry"]));
featureInfoHighlightLayer.addFeatures([feature]);
}
}
//case raster layers
var rasterAttributeNodes = [];
var rasterLayerChildNode = layerNodes[i].firstChild;
while (rasterLayerChildNode) {
if (rasterLayerChildNode.nodeName == "Attribute") {
rasterAttributeNodes.push(rasterLayerChildNode);
}
rasterLayerChildNode = rasterLayerChildNode.nextSibling;
}
for (var j = 0; j < rasterAttributeNodes.length; ++j) {
if (j == 0) {
if (showFILayerTitle) {
text += '<h2 class="hoverLayerTitle">' + wmsLoader.layerProperties[layerNodes[i].getAttribute("name")].title + '</h2>';
}
result = true;
}
text += '<p>' + rasterAttributeNodes[j].getAttribute("name") + ": " + rasterAttributeNodes[j].getAttribute("value") + '</p>';
text += '<hr class="hrHoverLayer"/>';
}
if (identificationMode == 'topMostHit' && result) {
break;
}
}
if (result) {
changeCursorInMap("pointer");
if (!clickPopup) {
// only show hoverPopup if no clickPopup is open
//get rid of last <hr/>
text = text.replace(/<hr class="hrHoverLayer"\/>$/, '');
hoverPopup = new OpenLayers.Popup.FramedCloud(
null, // id
map.getLonLatFromPixel(evt.xy), // lonlat
null, // new OpenLayers.Size(1,1), // contentSize
text, //contentHTML
null, // anchor
false, // closeBox
null // closeBoxCallback
);
hoverPopup.autoSize = true;
hoverPopup.keepInMap = true;
hoverPopup.panMapIfOutOfView = false;
hoverPopup.events.on({"click": onHoverPopupClick});
map.addPopup(hoverPopup);
}
} else {
changeCursorInMap("default");
}
}
}
// disable all GetFeatureInfoRequest until we have a reponse
function onBeforeGetFeatureInfoClick(evt) {
evt.object.layers[0].setVisibility(thematicLayer.getVisibility());
activateGetFeatureInfo(false);
}
//function onBeforeGetExtraFeatureInfoClick(evt) {
// var lay = geoExtMap.map.getLayersBy('metadata','identify');
//
// //WATCH: only first one is used
// if (lay.length>0) {
// evt.object.layers = [geoExtMap.map.getLayersBy('metadata', 'identify')[0]];
// }
//}
// reenable GetFeatureInfo
function noFeatureInfoClick(evt) {
activateGetFeatureInfo(true);
}
/* we need this function in order to pass through the click to the map events
* */
function onHoverPopupClick(evt) {
if (hoverPopup) {
removeHoverPopup();
}
var map = geoExtMap.map; // gets OL map object
evt.xy = map.events.getMousePosition(evt); // non api function of OpenLayers.Events
map.events.triggerEvent("click", evt);
}
function onClickPopupClosed(evt) {
removeClickPopup();
// enable the hover popup for the curent mosue position
if (Eqwc.settings.enableHoverPopup)
WMSGetFInfoHover.activate();
var map = geoExtMap.map; // gets OL map object
evt.xy = map.events.getMousePosition(evt); // non api function of OpenLayers.Events
map.events.triggerEvent("mousemove", evt);
}
function removeClickPopup() {
//var map = geoExtMap.map; // gets OL map object
//map.removePopup(clickPopup);
if (clickPopup) {
clickPopup.destroy();
}
clickPopup = null;
//featureInfoHighlightLayer.removeAllFeatures();
}
function removeHoverPopup() {
var map = geoExtMap.map; // gets OL map object
map.removePopup(hoverPopup);
hoverPopup.destroy();
hoverPopup = null;
featureInfoHighlightLayer.removeAllFeatures();
}
function showFeatureSelected(args) {
//TODO It would be useful to switch on layer if it is off
var layer = args["layer"] == null ? args["fid"].split('.')[0] : args["layer"];
var layerId = wmsLoader.layerTitleNameMapping[layer];
//var layerData = projectData.layers[layerId];
featureInfoHighlightLayer.removeAllFeatures();
featureInfoHighlightLayer.addFeatures([args]);
geoExtMap.map.zoomToExtent(args.geometry.bounds);
}
function clearFeatureSelected() {
// clear selection
if (thematicLayer.params['SELECTION'] != undefined) {
thematicLayer.mergeNewParams({
"SELECTION": null
});
}
featureInfoHighlightLayer.removeAllFeatures();
}
function parseFIResult(node) {
if (node.hasChildNodes()) {
//test if we need to show the feature info layer title
//either from global setting or from project setting
var showFILayerTitle = showFeatureInfoLayerTitle;
if (mapThemeSwitcher) {
if (mapThemeSwitcher.activeProjectData != undefined) {
showFILayerTitle = mapThemeSwitcher.activeProjectData.showFeatureInfoLayerTitle;
}
}
if (node.hasChildNodes() && node.nodeName == "Layer") {
var hasAttributes = false;
var rasterData = false;
var htmlText = "";
var layerChildNode = node.firstChild;
var sourceLayerId = node.getAttribute("name");
var sourceLayerName = wmsLoader.layerProperties[sourceLayerId].title;
var layerName = Eqwc.common.getIdentifyLayerNameRevert(sourceLayerName);
var layerId = wmsLoader.layerTitleNameMapping[layerName];
var layer = wmsLoader.layerProperties[layerId];
var countRelations = 0;
var layerTitle = layer.title;
if (showFILayerTitle) {
htmlText += "<h2>" + layerTitle + "</h2>";
}
if(projectData.relations[layerName]) {
countRelations = projectData.relations[layerName].length;
}
while (layerChildNode) {
var id = layerChildNode.id;
var fid = layerTitle+"."+id;
if (layerChildNode.hasChildNodes() && layerChildNode.nodeName === "Feature") {
var attributeNode = layerChildNode.firstChild;
htmlText += '<table><tbody>';
//case vector data
//add geometry actions if layer is WFS published or geometry is added to response
var addActions = projectData.use_ids ? (projectData.layers[layerId].wfs || projectData.add_geom) : false;
if (projectData.user == 'guest') {
addActions = false;
}
if (addActions) {
var select = '<a class="i-select" href="javascript:;" onclick="identifyAction(\'select\',\'' + fid + '\');"></a>';
var clear = '<a class="i-clear" href="javascript:;" onclick="identifyAction(\'clear\',\'\');"></a>';
var edit = '';
if (Eqwc.plugins["editing"] !== undefined) {
edit = '<a class="i-edit" href="javascript:;" onclick="identifyAction(\'edit\',\'' + fid + '\');"></a>';
}
htmlText += "<tr><td colspan='2'>" + select + edit + clear + "</td></tr>";
}
if (countRelations == 1) {
var show = '';
var table = projectData.relations[layerName][0].relate_layer;
var field = projectData.relations[layerName][0].join_field;
var rid = table+"."+id;
var add = '<a class="i-add" href="javascript:;" onclick="identifyAction(\'addRelation\',\'' + rid + '\',\'' + field + '\');"></a>';
htmlText += "<tr><td colspan='2'>" + show + add + "</td></tr>";
}
while (attributeNode) {
if (attributeNode.nodeName == "Attribute") {
var attName = attributeNode.getAttribute("name");
var attNameCase = attName.toUpperCase();
var attValue = attributeNode.getAttribute("value").replace(/null/ig, Eqwc.settings.noDataValue);
if ((attName !== mapInfoFieldName) && ((suppressEmptyValues == true && attValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '') !== "") || suppressEmptyValues == false)) {
if (attNameCase === "GEOMETRY") {
var feature = new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT(attValue));
//var feature = {};
//feature.geometry = attValue;
feature.fid = fid;
highLightGeometry.push(feature);
if (!suppressInfoGeometry) {
htmlText += "\n <tr>";
if (showFieldNamesInClickPopup) {
htmlText += "<td>" + attName + ":</td>";
}
htmlText += "<td>" + attValue + "</td></tr>";
hasAttributes = true;
}
} else {
//specific check if attribute name is "files" and we have an alias
var filesAlias = Eqwc.settings.qgisFilesFieldAlias ? Eqwc.settings.qgisFilesFieldAlias : 'files';
filesAlias = filesAlias.toUpperCase();
//if (attName !== "maptip") {
htmlText += "\n <tr>";
if (showFieldNamesInClickPopup && attNameCase !== "MAPTIP" && attNameCase!== filesAlias) {
htmlText += "<td>" + attName + ":</td>";
}
//TODO finish this for layers with more than 1 relation
if(countRelations > 1) {
var search = projectData.relations[layerName].find(function(currentValue, index, arr) {
return currentValue.count_field.toUpperCase() === attNameCase;
});
if(search) {
attValue += ' ' + search.join_field+'='+id;
}
}
if (attNameCase == filesAlias){
if (attValue>'') {
var attArr = Ext.util.JSON.decode(attValue);
var newArr = [];
Ext.each(attArr, function (item, index, array) {
var value = this;
value.push(Eqwc.common.manageFile(item, true));
}, newArr);
attValue = newArr.join('</br>');
}
} else {
attValue = Eqwc.common.createHyperlink(attValue, null, mediaurl);
}
if (attNameCase == 'MAPTIP' || attNameCase == filesAlias) {
htmlText += "<td colspan='2'>" + attValue + "</td></tr>";
} else {
htmlText += "<td>" + attValue + "</td></tr>";
}
hasAttributes = true;
//}
}
}
}
attributeNode = attributeNode.nextSibling;
}
htmlText += "\n </tbody>\n </table></br>";
}
else if (layerChildNode.nodeName === "Attribute") {
//case raster data
if (rasterData == false) {
htmlText += "\n <p></p>\n <table>\n <tbody>";
}
htmlText += '\n<tr><td>' + Eqwc.common.getRasterFieldName(layerTitle, layerChildNode.getAttribute("name")) + '</td><td>' + layerChildNode.getAttribute("value") + '</td></tr>';
hasAttributes = true;
rasterData = true;
}
layerChildNode = layerChildNode.nextSibling;
}
//htmlText += "\n</ul>";
if (hasAttributes) {
if (rasterData) {
htmlText += "\n </tbody>\n </table></br>";
}
//alert(htmlText);
featureInfoResultLayers.push(htmlText);
}
} else {
var child = node.firstChild;
while (child) {
parseFIResult(child);
child = child.nextSibling;
}
}
}
}
function listLayersWithFeatures(node) {
if (node.hasChildNodes()) {
if (node.nodeName == "Layer") {
featureInfoResultLayers.push(node.getAttribute("name"));
} else {
var child = node.firstChild;
while (child) {
listLayersWithFeatures(child);
child = child.nextSibling;
}
}
}
}
function getFeatures(layerName, node) {
if (node.hasChildNodes()) {
if (node.nodeName == "Layer" && node.getAttribute("name") == layerName) {
return node.firstChild;
} else {
var child = node.firstChild;
while (child) {
getFeatures(layerName, child);
child = child.nextSibling;
}
}
}
}
function updateElevation(data, location, field, template) {
var pan = Ext.getCmp('fi_elevation');
if (pan == undefined) {
return;
}
var tem = new Ext.Template(template);
if (data !== undefined) {
if (!(isNaN(data[field])) && data[field] !== null) {
if (data[field] === parseInt(data[field])) {
//
}
else {
data[field] = data[field].toFixed(elevationPrecision);
}
var label = tem.apply(data);
pan.update(label);
}
}
}
function updateAddress(data, location, field, template, templateMin, factor) {
var pan = Ext.getCmp('fi_address');
if (pan == undefined) {
return;
}
var distance = 0;
var results;
if ((field == '') || (field == null))
results = data;
else
results = data[field];
if (results.distance != null) {
distance = results.distance;
results.distance = distance * factor;
}
if (distance * factor > minimumAddressRange) {
tem = new Ext.Template(templateMin);
}
else {
tem = new Ext.Template(template);
}
var label = tem.apply(results);
pan.update(label);
}
function identifyAction(type, id, extra) {
var layer = id.split('.')[0];
if (id.split('.')[1] == 'undefined') {
return;
}
var layerId = wmsLoader.layerTitleNameMapping[layer];
switch (type) {
case 'clear' :
clearFeatureSelected();
break;
case 'edit' :
var check = checkEditorState(layerId);
if(check) {
var preparePass = prepareEdit(projectData.layers[layerId]);
if (preparePass) {
editor.attributesForm.requestAndLoadFeature(id);
}
}
break;
case 'addRelation' :
var check = checkEditorState(layerId);
if(check) {
var preparePass = prepareEdit(projectData.layers[layerId]);
var feat = new OpenLayers.Feature.Vector();
feat.state = OpenLayers.State.INSERT;
if (preparePass) {
feat.data[extra] = id.split('.')[1];
editor.editLayer.addFeatures([feat]);
editor.attributesForm.loadRecord(feat);
}
}
break;
case 'select' :
var hasGeom = false;
Ext.each(highLightGeometry, function (feature, index, array) {
if (feature.fid === this[1]) {
showFeatureSelected(feature);
hasGeom = true;
}
}, arguments);
//no geometry, make WFS call
if (!hasGeom) {
var filter = new OpenLayers.Filter.FeatureId({
fids: [id]
});
var protocol = new OpenLayers.Protocol.WFS({
version: '1.0.0',
url: wmsURI,
headers: {'Content-Type':'text/xml; charset=utf-8'},
featureType: layer,
//featureNS: "http://www.qgis.org/gml",
geometryName: "geometry", //always geometry not this: layer.geom_column,
filter: filter
//srsName: projectData.crs //doesn't work, have to transform results
});
function callback(response) {
//check response status
if(response.priv.status==200) {
if(response.features.length==1) {
var feat = response.features[0];
var layer = feat.fid.split('.')[0];
var layerId = wmsLoader.layerTitleNameMapping[layer];
var layerData = projectData.layers[layerId];
feat.geometry.transform(layerData.crs,projectData.crs);
highLightGeometry.push(feat);
showFeatureSelected(feat);
}
} else {
Ext.Msg.alert('Get feature error', response.priv.status + ' ' + response.priv.statusText+ '</br></br>'+response.priv.responseText);
}
}
protocol.read({
maxFeatures: 1,
callback: callback,
scope: this
});
}
break;
}
}