管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
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
<html>
    <head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
        <title>Image Comparison Tool</title>
<link rel="StyleSheet" href="../Style.css" type="text/css">
<style>
.TintColorButton {border-color: black;border-width:1px;  height:12px;width:15px;margin-right:5px;margin-left:1px;margin-bottom: 4px;}
</style> 
</head>
<body style="border: 0px;overflow:hidden; margin:0;" id="Body"  class="hideUntillTranslated" onload="Init()" onunload="exitTool();">
 
    <table id="topPanel" cellpadding ="3px" style="background-color: #151515" cellspacing = "0" border="0" width="100%"  class="s8w">
            <tr valign="top">
            <!-- <td rowspan=2>
                <img src="ToolIcon.png"  style="margin-left: 5px; margin-right: 10px; ">
            </td> -->
            <td style="width:60px;" align="center">
                    <span class="i18n s8w" style="margin-right: 0px;">Text_Layer</span>
            </td>
            <td style="width:calc(100%-60px);" align="left">
                    <select id="LayersListID" class="SelectDark"  style="width:100%; " onchange="FindAttributes();">
                    </select>
             </td>
        <tr>
                <td style="width:60px;" align="center">
                        <span class="i18n s8w"  style="margin-right: 0px;">Text_Attribute</span>
                </td>
                <td style="width:calc(100%-60px);" align="left">
                        <select id="AttributesListID" class="SelectDark"   style="width:100%; " onchange="ShowAttributeValues(false);">
                        </select>
                 </td>
            </tr>
    </table>
    <!-- This is the header of the Display by Attribute result. Added dynamically when needed  -->
    <div id="visibilityHeader"  style="display:none; visibility: hidden;"> 
        <div  class="s8"  style="background-color:#DFDEDF; padding-bottom:3px;padding-top: 3px;margin-bottom: 3px;"> 
                    <input type="checkbox"  checked="checked" value="All" onchange="CheckAll(this);" />
                <span class="i18n">Text_All</span><br>
        </div>
    </div>
 
    <!-- This is the header of the Colorize by Attribute result. Added dynamically when needed  -->
    <div id="colorizeHeader" class="s8"  style="display:none; visibility: hidden;"> 
       <div  class="s8"  style="background-color:#DFDEDF; padding-bottom:3px;padding-top: 3px;margin-bottom: 3px;"> 
            <span class="i18n">Text_SetAll</span>
            <input id="AllColors" class="jscolor s6 TintColorButton" value="ffffff" style="width:40px;text-align: center" />
            <input type="button" class="MenuButtonSmall  i18n" onclick="setAllColors();" value="Text_Set" />
            <hr style="width:1px; height:20px; display: inline; margin-left: 3px; margin-right: 3px; ">
            <input type="button" class="MenuButtonSmall  i18n" onclick="reshuffleColors();" value="Text_Reshuffle" />
            <hr style="width:1px; height:20px; display: inline; margin-left: 3px; margin-right: 3px; ">
            <span class="i18n">Text_Opacity</span>&nbsp;&nbsp;
            <input id="opacityID"  value="50" style="width:25px;" onkeypress="if (event.keyCode == 13) {setOpacity($(this));}" onchange="setOpacity($(this));"/>%
        </div>    
    </div>    
 
    <div id="AttributesDiv" style="width:100%; height:90%; overflow-y:auto" class="s8"></div>
 
    <table id="bottomPanel" cellpadding ="3px" style="background-color: #151515" cellspacing = "0" border="0" width="100%"  class="s9w">
        <tr valign="top">
            <td align="right">
                    <input type="button" id="SaveID" class="MenuButtonSmallWhite MenuButtonLast i18n" onclick="Save(true);" value="Text_Save" />
                </td>
        </tr>
    </table>
    
<script src="../jquery/jquery-1.10.2.js"  type="text/javascript"></script>
<script src="./jscolor.js" type="text/javascript" ></script>
<script language="javascript" src="../ToolsCommon71.js"></script>
<script language="jscript">
 
var SGWorld = new ActiveXObject("TerraExplorerX.SGWorld71");
 
var gDebug = false;
var gType=0;
var gSaved = false;
var g3DMLID;
var g3DMLObj;
var gFeatures;
var gQueryBulk = 50000;
var gOpacity = 128;
var gLayersProperties=[];
var gLayersColor=[];
var gColors = ["ff0000","00ff00","0000ff","ff00ff","ffff00","00ffff","800000","808000","000080","800080","008080","ccff66","ff66ff","00cc99","0099ff","333399","663300","b35900","999966","b3e6b3","19004d"];
 
$(window).resize(function(e) {
    $("#AttributesDiv").height($( window ).height()-$("#topPanel").height()-$("#bottomPanel").height());
});
 
//--------------
//  Init
function Init() {
    try {
        $("#AttributesDiv").height($( window ).height()-80);
        gType = GetParamValue("Type", 0);
        g3DMLID  = GetParamValue("ID", "");
        if (g3DMLID=="")
            g3DMLID = SGWorld.ProjectTree.GetNextItem (SGWorld.ProjectTree.RootID,10); 
 
        g3DMLObj = SGWorld.Creator.GetObject(g3DMLID);
        if (g3DMLObj.ObjectType == 39){ // feature layer under 3DML - get the parent 3DML
                g3DMLID = SGWorld.ProjectTree.GetNextItem (g3DMLID,15);
                g3DMLObj = SGWorld.Creator.GetObject(g3DMLID);
            }
 
        if (g3DMLObj.ObjectType != 38){
            TEAlert (SGLang.i18n("Text_AlertCaption"), SGLang.i18n("Text_3DMLNotFound"));
            return;
        }
 
        FindLayers();
        FindAttributes();
    }
    catch (e) { TEAlert (SGLang.i18n("Text_AlertCaption"),SGLang.i18n("Text_3DMLNotFound") ); exitTool(); return;}
}
//--------------
//  FindLayers
function FindLayers() {
 
    try{
        for (var i=0; i<g3DMLObj.FeatureLayers.Count; i++){
            $('#LayersListID').append($('<option>', { 
                value: g3DMLObj.FeatureLayers.Item(i).ID,
                text : g3DMLObj.FeatureLayers.Item(i).TreeItem.Name 
            }));
 
            var FeatureLayerID = $('#LayersListID').val();
 
        }
        Save(false); // save initial visibility state for all layers
    }
    catch (e) {if (gDebug) alert(e.message);}
}
//--------------
//  FindAttributes
function FindAttributes() {
    try{
        $('#AttributesListID').html("");
        var FeatureLayerID = $('#LayersListID').val();
        var featureLayer = SGWorld.Creator.GetObject(FeatureLayerID);
        var firstFeature = featureLayer.ExecuteQuery ("",1,"",SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(null));
        for (var i=0; i<firstFeature.Item(0).FeatureAttributes.Count; i++) {
            $('#AttributesListID').append($('<option>', { 
                    value: i,
                    text : firstFeature.Item(0).FeatureAttributes.Item(i).Name 
                }));
        }
        ShowAttributeValues(true);
    }
    catch (e) {$("#AttributesDiv").html("");}
}
//--------------
//  ShowAttributeValues
function ShowAttributeValues(fromInit) {
    
    try {
        var FeatureLayerID = $('#LayersListID').val();
        var featureLayer = SGWorld.Creator.GetObject(FeatureLayerID);
        var attributeIndex = $('#AttributesListID').val();
        var attributeName  = $('#AttributesListID').children("option").filter(":selected").text()
        var serverPrefix = (checkUrl(g3DMLObj.path))?"SQL: ":"";
        try{
         gFeatures = featureLayer.ExecuteQuery (serverPrefix+attributeName+" Like '%%' or "+attributeName+" is null GROUP BY lower("+attributeName+")",gQueryBulk,"",SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(null));
        }
        catch (e) { if (serverPrefix!="") TEAlert (SGLang.i18n("Text_AlertCaption"), SGLang.i18n("Text_SGSTooOld") ); else TEAlert (SGLang.i18n("Text_AlertCaption"),e.message); exitTool(); return;}
 
// Need a try-catch and a message telling that the SGS server is lower then 7.2
        if (gFeatures.Count>=gQueryBulk) {
            if (fromInit && !$('#AttributesListID').children("option").filter(":selected").is ($('#AttributesListID').children().last())){
                $('#AttributesListID option:selected').next().attr('selected', 'selected');
                ShowAttributeValues(fromInit);
                return;
            }
            htmlText = "<br><label class='s9red' >"+SGLang.i18n("Text_TooManyAttributes")+"</label><br>";
            $("#AttributesDiv").html(htmlText);
            if (gType==0)
                featureLayer.FeatureProperties.SetClassification ("Visibility", "");
            else
                featureLayer.FeatureProperties.Tint = SGWorld.Creator.CreateColor(255,255,255,0);
            return;
        }
 
        var htmlText = "";
        var attributes=[];
        for (var i=0; i<gFeatures.Count; i++) {
            if (gFeatures.Item(i).FeatureAttributes.Item(attributeIndex).Value == "")
                attributes.push (SGLang.i18n("Text_Empty"));
            else
                attributes.push (gFeatures.Item(i).FeatureAttributes.Item(attributeIndex).Value);
        }
        attributes.sort();
        
        if (gType==0) {    // Visibility
            htmlText += $("#visibilityHeader").html();
 
            for (var i=0; i<gFeatures.Count; i++) {
                var uniqueValue = attributes[i];
                htmlText += '<input id="' + uniqueValue + '" type="checkbox"  checked="checked" name="' + uniqueValue + '" value="' + uniqueValue + '" onchange="ChangeSelection();">';
                htmlText += '<label for="' + uniqueValue + '">'+uniqueValue+'</label><br>';
            }
            $("#AttributesDiv").html(htmlText);
            ChangeSelection();
        }
        else {
            htmlText += $("#colorizeHeader").html();
 
            for (var i=0; i<gFeatures.Count; i++) {
                var uniqueValue = attributes[i];
                htmlText += '<input id="' + uniqueValue + '" class="jscolor TintColorButton s6" onchange="ChangeTintColor();" value="'+getRandomColor(i)+'" style="width:40px;text-align: center;"  />';
                htmlText += '<label for="' + uniqueValue + '">'+uniqueValue+'</label><br>';
            }
            
            $("#AttributesDiv").html(htmlText);
            setTimeout ("ChangeTintColor();",10);
            jscolor.installByClassName("jscolor");
        }
    }
     catch (e) {if (gDebug) alert(e.message);}
}
//--------------
//  getRandomColor
function getRandomColor(index) {
    var color;
    if (index<20)
        color = gColors[index];
    else
        color =  componentToHex(Math.round(Math.random()*255)) + componentToHex(Math.round(Math.random()*255)) + componentToHex(Math.round(Math.random()*255));
 
    return color;
}
//--------------
//  componentToHex
function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}
 
//--------------
//  CheckAll
function CheckAll(t) {
    var checkValue = $(t).is(":checked");//  $(this).val();
    $('#AttributesDiv').find(':checkbox').each(function() {
            this.checked = checkValue;
    });
    ChangeSelection();
 
}
//--------------
//  checkUrl
function checkUrl(s) {
     var regexp = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
     return regexp.test(s); 
}
//--------------
//  ChangeSelection
function ChangeSelection() {
    try{
        var attName = $('#AttributesListID').children("option").filter(":selected").text();
        var query="";
        var first=true;
        var checkAll=true;
        $('#AttributesDiv').find(':checkbox').each(function(index) {
            if (index!=0) {  // ignore first checkbox (All)
                if ($(this).prop("checked")){
                    if (!first)
                            query += " OR ";
                    var attValue = $(this).attr('name');
                    var find = "'";
                    var re = new RegExp(find, 'g');
                    attValue = attValue.replace(re, "''");
                    if (attValue==SGLang.i18n("Text_Empty"))
                        attValue="";
                    query += "\""+attName+"\" = '"+attValue+"'";
                    first=false;
                }
                else
                    checkAll=false;
            }  
        });
        if (checkAll)
            query = "";
        else if (query=="")
            query = "\""+attName+"\" = '-9999'"; // in case of all checkboxes are off this fake query should hide all elements
        var FeatureLayerID = $('#LayersListID').val();
        var featureLayer = SGWorld.Creator.GetObject(FeatureLayerID);
        featureLayer.FeatureProperties.SetClassification ("Visibility", query);
    }
    catch (e) {if (gDebug) alert(e.message);}
}
//--------------
//  setAllColors
function setAllColors(){
    var allColors;
    $('#AttributesDiv').find('.jscolor').each(function(index) {
            if (index==0)
                allColors = $(this)[0].jscolor.toHEXString();
            else 
                $(this)[0].jscolor.fromString(allColors);
        });
    setTimeout ("ChangeTintColor();",10);
}
//--------------
//  reshuffleColors
function reshuffleColors(){
    $('#AttributesDiv').find('.jscolor').each(function(index) {
            if (index>0)
                $(this)[0].jscolor.fromString(getRandomColor(index+100)); 
        });
    setTimeout ("ChangeTintColor();",10);
}
//--------------
//  setOpacity
function setOpacity(t) {
    var n = parseFloat(t.val());
    if ( isNaN(n) || n < 0 || n > 100){
        t.val("50");
    }
    gOpacity=t.val()*2.56;
    ChangeTintColor();
}
//--------------
//  ChangeTintColor
function ChangeTintColor() {
    try{
        var attName = $('#AttributesListID').children("option").filter(":selected").text();
        var query="<Classification FuncType='0'>";
        var first=true;
        $('#AttributesDiv').find('.jscolor').each(function(index) {
                var attValue = $(this).attr('id');
                var find = "'";
                var re = new RegExp(find, 'g');
                attValue = attValue.replace(re, "''");
                var HexColor = rgb2hex($(this).css("backgroundColor"));
                var BGRcolor = HexColor.substr(4,2)+HexColor.substr(2,2)+HexColor.substr(0,2);
                var color = parseInt(BGRcolor, 16);
                attValue= htmlSpecialChars(attValue);
                if (attValue==SGLang.i18n("Text_Empty"))
                    attValue="";
                if (index==0)   // default color
                    query+= '<DefaultValue>'+color+'</DefaultValue>';
                else
                    query += '<Class><Condition>&lt;"['+attName+']"="'+attValue+'"&gt;</Condition><Value>'+color+'</Value></Class>';
        });
        query +="</Classification>";
        var FeatureLayerID = $('#LayersListID').val();
        var featureLayer = SGWorld.Creator.GetObject(FeatureLayerID);
        featureLayer.FeatureProperties.Tint = SGWorld.Creator.CreateColor(255,255,255,gOpacity);
        featureLayer.FeatureProperties.SetClassification ("Tint Color", query);
    }
    catch (e) {if (gDebug) alert(e.message);}
}
//--------------
//  htmlSpecialChars
function htmlSpecialChars(unsafe) {
    return unsafe
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;");
    //.replace(/"/g, "&quot;");
}
//--------------
//  rgb2hex
function rgb2hex(rgb) {
    rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    function hex(x) {
        return ("0" + parseInt(x).toString(16)).slice(-2);
    }
    return  hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
 
//--------------
//  Save
function Save(fromButton) {
    
    try{
        for (var i=0; i<g3DMLObj.FeatureLayers.Count; i++){
            if (gType==0)
                gLayersProperties[i] = g3DMLObj.FeatureLayers.Item(i).FeatureProperties.GetClassification("Visibility");
            else{
                gLayersProperties[i] = g3DMLObj.FeatureLayers.Item(i).FeatureProperties.GetClassification("Tint Color");
                if (gLayersProperties[i]=="")
                    gLayersColor[i] = g3DMLObj.FeatureLayers.Item(i).FeatureProperties.Tint.ToABGRColor();
            }
        }
        if (fromButton){
            TEAlert (SGLang.i18n("Text_AlertCaption"),SGLang.i18n("Text_SaveMessage"),true);
            gSaved = true;
        }
    }
    catch (e) {  if (gDebug) alert(e.message);}
}
//--------------
//  exitTool
function exitTool() {
    try {
        for (var i=0; i<g3DMLObj.FeatureLayers.Count; i++){
            if (gType==0) // Display by Attribute
                g3DMLObj.FeatureLayers.Item(i).FeatureProperties.SetClassification("Visibility",gLayersProperties[i]);
            else  // Colorize
            {
                if (gLayersProperties[i]!=""){
                    g3DMLObj.FeatureLayers.Item(i).FeatureProperties.Tint = SGWorld.Creator.CreateColor(255,255,255,gOpacity);
                    g3DMLObj.FeatureLayers.Item(i).FeatureProperties.SetClassification("Tint Color",gLayersProperties[i]);
                }
                else
                    g3DMLObj.FeatureLayers.Item(i).FeatureProperties.Tint.FromABGRColor(gLayersColor[i]);
            }
       }
       //SGWorld.Window.RemovePopupByCaption(SGLang.i18n("ToolName"));
 
    }
    catch (e) { if (gDebug) alert(SGLang.i18n("Text_ErrorWhileExit") +e.message); }
}
      
</script>
 
</body>
</html>
 
 
 
 
<!--Sig:00000040tBCwtQRZuIXgN24Lj4YU5Nf2MZ#8T7hT69FZiWKHZmovcNw7BskI03tkmCVWphsMcqiEZKR#.X4OjlCpiy8mXbJJ-->