變壓器位置with範圍展示
yuanhung
2016-08-16 e3d6da37ac178414e3b607cd39475963acbe6766
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
//var map;
var selectedFeature;
var offlineRest=true;
Proj4js.Proj["CRS:84"]=Proj4js["EPSG:4326"];
Proj4js.Proj["CRS:84"];
 
/* epsg variables */
//var epsg900913 = new OpenLayers.Projection("EPSG:900913");
var epsg3857= new OpenLayers.Projection("EPSG:3857");
var wgs84 = new OpenLayers.Projection("EPSG:4326");
var crs84 = new OpenLayers.Projection("EPSG:4326");
crs84.proj.srsCode="CRS:84";
crs84.proj.srsCodeInput="CRS:84";
crs84.projCode="CRS:84";
crs84.swapXY=true;
 
var tw97 = new OpenLayers.Projection("EPSG:3826");
var tw67 = new OpenLayers.Projection("EPSG:3828");
//OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.SphericalMercator.projectForward);
//OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:4326", OpenLayers.Layer.SphericalMercator.projectInverse);
 
 
Proj4js.reportError = function (msg) {
    alert(msg);
}
//IE halt @ OpenLayers.Renderer.VML.LABEL_SHIFT.e undefined
//OpenLayers.Renderer.VML.LABEL_SHIFT.e=1;//Doesn't know
var epsgws84_bounds=new OpenLayers.Bounds(117.0305,21.6294,125.7583,26.6151) ;
var bounds = new OpenLayers.Bounds(116.517197643768,20.6442266131947,124.718539835259,26.4492775120834);
var epsg3857_bounds = new OpenLayers.Bounds(116.517197643768,20.6442266131947,124.718539835259,26.4492775120834);
var geojson_format = new OpenLayers.Format.GeoJSON({
    'internalProjection': epsg3857,  //wgs84,
    'externalProjection': wgs84
    });
 
 
var featurecollection={"type":"FeatureCollection","features":[]};
//var ajaxJson= new AjaxJson();
var gJsonParser= new GJSonParser();
 
OpenLayers.Projection.transform = function(point, source, dest) {
    if (source && dest) {
    
        if (!(source instanceof OpenLayers.Projection)) {
        //console.log('new src');
            source = new OpenLayers.Projection(source);
        }
        if (!(dest instanceof OpenLayers.Projection)) {
        //console.log('new des');
            dest = new OpenLayers.Projection(dest);
        }
//        debugger;
        if (source.proj && dest.proj) {
        //console.log(source.proj,'-->', dest.proj);    
            point = Proj4js.transform(source.proj, dest.proj, point);
        } else {
        
            var sourceCode = source.getCode();
            var destCode = dest.getCode();
            var transforms = OpenLayers.Projection.transforms;
            if (transforms[sourceCode] && transforms[sourceCode][destCode]) {
                transforms[sourceCode][destCode](point);
            }
        }
    }
    return point;
};
 
 
 
 
function onPopupClose(evt) {
    selectControl.unselect(selectedFeature);
}
 
//var handlePopup;
function onFeatureSelect(feature) {
 
/*
    //selectedFeature = feature;
     if(handlePopup){      
        e.feature.layer.map.removePopup(handlePopup);
        handlePopup.destroy();
        handlePopup = null;
    }
    handlePopup=new OpenLayers.Popup.FramedCloud(
                        "chicken", 
                        feature.geometry.getBounds().getCenterLonLat(),
                        null,
                        feature.attributes.descript+'<br />'+'<a href="#" onclick="...">修改</a>',
                        null,
                        true
                    );
   feature.layer.map.addPopup(handlePopup);
    */
}
 
function onFeatureUnselect(feature) {
    //map.removePopup(feature.popup);
    //feature.popup.destroy();
    //feature.popup = null;
 
}   
//not use
 
//not use^
 
 
function onFeatureOver(e) 
{e.feature.renderIntent = "select"; e.feature.layer.drawFeature(e.feature);
}
    
function onFeatureOut(e) 
{ e.feature.renderIntent = "default"; e.feature.layer.drawFeature(e.feature);}
 
var cqlformat = new OpenLayers.Format.CQL();
 
var setCQL=function(layer,cql){
    if(cql!=null)
        if(cql.length>3500)
        {
            alert('資料過多,如無法正常顯示,請減少資料量') ;
        }
    //var nq=cqlformat.read(cql);
    delete layer.params.CQL_FILTER;
    layer.mergeNewParams({'CQL_FILTER':cql});
    //layer.redraw();
    //debugger;
    //layer.params.CQL_FILTER=nq;
   // console.log(cql);
};
var setAVALUES=function(layer,cql){
    if(cql!=null)
        if(cql.length>3500)
        {
            alert('資料過多,如無法正常顯示,請減少資料量') ;
        }
    //var nq=cqlformat.read(cql);
    delete layer.params.AVALUES;
    layer.mergeNewParams({'AVALUES':'1=0;'+cql+',2=2;'+cql});
    //layer.redraw();
    //debugger;
    //layer.params.CQL_FILTER=nq;
   // console.log(cql);
};
function init(maptag,config) {
 
    var styleHighLight = new OpenLayers.Style(
        {
            "strokeWidth": 3, "labelOutlineColor": "#FFCCCC", 
                        "labelOutlineWidth": 5 ,
            "pointRadius": 8, "fillColor": "#006666",
            "fillOpacity": 0.6, "strokeColor": "#006060",
            
            "labelYOffset": -15,
            "fontSize": "12px",
            "pointerEvents": "visiblePainted",
            "label": "${descript}",
            "labelAlign": "left"
                
           // "label" : '${key}'
        });
        var styleHighLightYellow = new OpenLayers.Style(
        {
            "strokeWidth": 3,
            "pointRadius": 8, "fillColor": "#B0B0B0",
            "fillOpacity": 0.6, "strokeColor": "#A0A0A0"
        });
//styles
    var styleJustGreen = new OpenLayers.Style(
    {
        "strokeWidth": 1,
        "pointRadius": 6, "fillColor": "#006600",
        "fillOpacity": 1, "strokeColor": "#303030"
    
        //"label" : '${location}',
    });
    var styleYellow = new OpenLayers.Style(
    {
        "strokeWidth": 1,
        "pointRadius": 6, "fillColor": "#DDDD00",
        "fillOpacity": 0.5, "strokeColor": "#D00000"
    
        //"label" : '${location}',
    });
    var styleJustGreenS1 = new OpenLayers.Style(
    {
        "strokeWidth": 5,
        "pointRadius": 4, "fillColor": "#66AA66",
        "fillOpacity": 0.7, "strokeColor": "#3030AA",
        "labelYOffset": 0,
        "labelAlign": "left",
        "labelOutlineColor": "white",
        "labelOutlineWidth": 0,
        "fontSize": "12px",
        "pointerEvents": "visiblePainted",
        //"fontWeight": "bold",
        "label" : "${number}"    ,
        "labelOutlineColor": "#FFCCCC", 
        "labelOutlineWidth": 5 
    });
// styles^
    
    //var baselayer=createLayer('TGOS地型',  {id:"tgos",baselayer:true,content:"http://gis.sinica.edu.tw/tgos/wmts",layerType:"tgos", layerid:"ROADMAP_W",projection:"EPSG:3857"});
        //{layerType:'google'});
 
    //var baselayer=createLayer('basemap0',  {baselayer:true,layerType:'vector',projection:epsg3857,maxExtent:epsg3857_bounds
    //});
    
    //TTTHHIIISS
    var baselayer=createLayer('basemap0',  {  layerType:"wmts"  ,projection:"EPSG:3857",
        baselayer:false,layerType:"wmts",content:"http://maps.nlsc.gov.tw/S_Maps/wmts", layerid:"EMAP",projection:"EPSG:3857"
    });
    
    //var baselayer=createLayer('basemap1',  {  layerType:"google"  ,projection:"EPSG:3857"
     //   baselayer:false,layerType:"wmts",content:"http://maps.nlsc.gov.tw/S_Maps/wmts", layerid:"EMAP",projection:"EPSG:3857"
    //});
 
    
    var map;
    var dwc;
if(typeof(maptag)=='undefined'||maptag=='') maptag='map';
    map = new OpenLayers.Map(maptag, {
        "projection": epsg3857,
        "displayProjection" : wgs84,
         allOverlays: true,
        "layers": [baselayer],
        //maxExtent:epsgws84_bounds,
        eventListeners:
        {
            'featureover': onFeatureOver,
            'featureout': onFeatureOut
        },
        controls:[new OpenLayers.Control.Navigation(), new OpenLayers.Control.Zoom(),new OpenLayers.Control.MousePosition(),new OpenLayers.Control.ScaleLine()
        //,new OpenLayers.Control.LayerSwitcher() 
        ],
        //bounds:bounds,
        center: new OpenLayers.LonLat(121.51, 24.95) //(121.506784, 23.03276)
            // Google.v3 uses web mercator as projection, so we have to
            // transform our coordinates
            .transform(wgs84, epsg3857),
        zoom:13
    });
    baselayer.setVisibility(true);
/*
    map.events.register("zoomend", map, function(ev)
    {
        var zLv=this.getZoom();
        if(zLv<=10){
            parent.document.getElementById("L0panel").style.display='';
            parent.document.getElementById("L1panel").style.display='none';
            parent.document.getElementById("L2panel").style.display='none';
            //show lv0
        }
        else if(zLv<=14){
            //show lv1
            parent.document.getElementById("L0panel").style.display='none';
            parent.document.getElementById("L1panel").style.display='';
            parent.document.getElementById("L2panel").style.display='none';
        }
        else
        {
            parent.document.getElementById("L0panel").style.display='none';
            parent.document.getElementById("L1panel").style.display='none';
            parent.document.getElementById("L2panel").style.display='';
            //show lv2
        }
        
    });
    */
    var tempLayer;
    var queryHandle=new AProto();
    
    //!! BUG ---@ PROJECTION 
    var facQuery = TPCFeatureInfoCtrl({ projection: "EPSG:3826", map: map, filterDgn: true}, function (e) {
    var ctlloc_facquery=new CtlLocate(map,{layer:'highlight'});
    
    if(typeof(e)!='undefined')
    {
    if(typeof( e.event)!='undefined')
    {
        if(e.event.features.length>0)
        {
            //however we require 4326, return X;
            
        var paramsOfLocate={projection:e.event.object.projection,clearAll:true,
        drawAs:'wkt',wkt:e.event.features[0].geometry.toString()};
        /* skip
        if(queryHandle.getConfig().locate||false)
        {
            paramOfLocate['zoomToRange']=true;
        }*/
        
        ctlloc_facquery.action(paramsOfLocate);
        
        queryHandle.callAction(e.event.features[0].attributes);
        }
    }
        return;
        
        //debugger;
        //var ctlLocate=null;
        var dataParams=[];
        for(var aFeatureKey in e.features)
        {
            var aFeature= e.features[aFeatureKey];
          
          
            var labelName=fscMapping.hasOwnProperty(aFeature.attributes.tid)?fscMapping[aFeature.attributes.tid]:'其他設備';
            //aPnlItem
            
 
            var oidLabel=aFeature.attributes.hasOwnProperty('oid')?aFeature.attributes.oid:'0';
 
           // attribFrm.items.get('tabpnl').add( aPnlItem  );
            var dataParam={};
            if(useProxy)
                {
                    dataParam["dmmsuser"]="";
                    dataParam["url"]=restUrl+'/json';
                }
            dataParam["distId"]=aFeature.attributes.did;
            dataParam["clsId"]=aFeature.attributes.tid;
            dataParam["oId"]=aFeature.attributes.oid;
            
            dataParams.push(dataParam);
            
        /*
            ajaxJson.ajaxGet(
                {
                    oid: aFeature.attributes.oid,
                    ret: aPnlItem,
                    url:((useProxy?OpenLayers.ProxyHost.split('?')[0]:restUrl+'/dmmsfeatureinfos.json') ),//'/geodmms/rest/dmmsfeatureinfos.json'),
                    header:{'Authorization': "Basic " + btoa('geodmms'+ ":" + 'geodmms')},
                    data:dataParam,
                    'success': function(request) {
                        //console.log(request);
                        var subPnl;
                       // lastJson= request.response;
                        var vjson=eval('('+request.response+')');
 
                        var vValueArray;
                        //alert('request.status is '+request.status);
                        //alert('vjson is '+vjson);
                        var vkeyCount=0;
                        for(var vkey in vjson[0])
                        {
                            vValueArray={items:[]};
                            var vName=(vjson[0][vkey].length>0)? vjson[0][vkey]:[];
                            var vValue;
                            if(vjson.length>1)
                            {
                                if(typeof(vjson[1][vkey])=='undefined'){vValue=[];}
                                else
                                vValue=(vjson[1][vkey].length>0)? vjson[1][vkey]:[]
                            }
                            else
                                vValue=[];
                            // var vValue=(vjson[0][vkey].length>1)? vjson[1][vkey]:'';
                            for(var idx=0;idx<vName.length;idx++)
                            {
                                vValueArray.items.push({name:vName[idx],value:(vValue.length>idx)?vValue[idx]:""});
                            }
 
                            var subStore=  Ext.create('Ext.data.Store', {
                                fields: ['name', 'value'],
                                data: vValueArray,
                                proxy: {
                                    type: 'memory',
                                    reader: {
                                        type: 'json',
                                        root: 'items'
                                    }
                                }
                            });
                           // lastStore= subStore           ;
                           // console.log(subStore)  ;
 
                            var subPnl=Ext.create('Ext.grid.Panel',
                                {title:vkey+(vkeyCount<1?('('+this.oid+')'):''),  columns: [
                                    {text: '屬性名稱', width: 140,   sortable: true,  dataIndex: 'name'},
                                    {text: '屬性值',  flex: 1, sortable: true, dataIndex: 'value'}],
                                    store:  subStore
 
                                }) ;
                            attribFrm.items.get('tabpnl').items.get(this.ret.id).add(subPnl);
                            //debugger;
                            //aPnlItem.add(subPnl);
                            attribFrm.items.get('tabpnl').setActiveTab(aPnlItem);
                            vkeyCount++;
                        }
 
                    }
                }) ;
        */
        }
        
        if(adptProc)
            {
            adptProc(dataParams);
            }
        //debugger;
    }                                                                 //{layout:'fit',width:800,height:480}
 
});
 
for(var idx=0;idx<layerList.length;idx++)
{
 
    var thisLayerDef= layerList[idx];
    if(map.getLayersByName(thisLayerDef.id).length==0)
    {
        var tempLayer;
        var content_forLayer;
        if(typeof(thisLayerDef.layerinfo.content)!='undefined')
        {
            content_forLayer = thisLayerDef.layerinfo.content;
 
        }
        else
            content_forLayer=wmsUrl ;
        var optionOfLayer={layerType:thisLayerDef.layerinfo.layerType,
            layerid:thisLayerDef.layerinfo.layerid,content:content_forLayer,
            projection:thisLayerDef.layerinfo.projection};
       /* if(typeof(thisLayerDef.proj4JSPath)!='undefined')
        {
            optionOfLayer['proj4JSPath']=thisLayerDef.proj4JSPath;
        }    */
 
        tempLayer=createLayer(thisLayerDef.id,optionOfLayer);
        
        map.addLayer(tempLayer);
 
        tempLayer.setVisibility(thisLayerDef.showdef);
 
        if(thisLayerDef.featureinfo)
        {
            if(facQuery!=null)
            {
                facQuery.layers.push(tempLayer);
            }
        }
    }
    else
    {
       // console.log('exist:'+thisLayerDef.id)
        map.getLayersByName(thisLayerDef.id)[0].setVisibility(thisLayerDef.showdef);
    }
}
    var vLayerArray={items:layerList};
    //vLayerStore
    //facQuery.activate();
    
    //----
    
    var markLayer=createLayer('markup',{
        layerType:'vector',// ,styleMap:styleHighLight
        styleMap:new OpenLayers.StyleMap({
        "default" : styleYellow,
        "select": styleHighLight
        })
    });
    map.addLayer(markLayer);
            
    tempLayer=createLayer('drawTemp',{
    layerType:'vector'
    /*styleMap:new OpenLayers.StyleMap({
        "default" : styleJustGreen,
        "select": styleJustGreenS1
        })*/
    });
 
            
    
    var highlightLayer=createLayer('highlight',{
        layerType:'vector',styleMap:styleHighLightYellow
        });
    
    map.addLayer(highlightLayer);
    
    extMapResultion(map,24);
    
    dwc=new DrawControl(tempLayer,{map:map});
    map.addLayer(tempLayer);
    
    
    var visualLayer=createLayer('visual',{
    layerType:'vector'
    });
    map.addLayer(visualLayer);
 
    var visualpoint= new OpenLayers.Control.DrawFeature(visualLayer,
                OpenLayers.Handler.Point);
    var visualwkt=new CtlGetWKT(map,{srcLayer:"visual"});
    visualLayer.setVisibility(false);
    visualpoint.setMap(map);
    var callbackVP=function(evt){};
    var vpAdded=function(evt)
    {
    visualpoint.deactivate();
        if(typeof(callbackVP)=="function")
        {    
            var result=visualwkt.parser(evt.feature,{geometryType:'featurePoint'});
            callbackVP(result);
            
        }
        
    }
    dwc["toggleVP"]=function(callVP,configVP)
    {
        callbackVP=callVP;
        visualpoint.activate();
        
    }
    visualpoint.events.register('featureadded', visualpoint,vpAdded); 
    
    //dwc.addControl('getpoint',visualpoint);
    dwc.addControl('facquery', facQuery);
 
 
    var showquery=function(params)
    {
        var bindProperty=function(vjson)
        {
            $("#propertiesA")[0].innerHTML="<p>"+params.name+"</p><p>"+vjson[0].name+"</p>";
            //$("properties.panel-collapse")
        }
        
        var queryMethod= offlineRest? restUrl+ params.fcid+'-'+ params.gid+'.json' : 'tpctyphoon.json';
        
        
        //$("#propertiesA")[0].innerHTML="<p>"+params.name+"</p>";
        $("#propertiesA")[0].innerHTML='<table class="table table-striped table-bordered table-rwd">'
          +'<tr class="tr-only-hide">'
         +'<th>名稱</th>'
         +(typeof(params.info)=="undefined" ?'': '<th>資訊</th>')
          +'</tr>'
         +'<tr>'
       +'<td data-th="名稱">'+params.name+'</td>'
         +(typeof(params.info)=="undefined" ?'': '<td data-th="資訊">'+params.info+'</td>')
         +'</tr>'
         +'</table>';
        return;
        
        $.ajax({
        srcTitle:params.name,
        url:queryMethod,
        dataType: 'json',
        //headers: {'Authorization': "Basic " + btoa('geodmms' + ":" + 'geodmms')},
        crossDomain: true,//sorry not for IE
        async:false,
        data: params,
        success: function(result)
        {
            //debugger;
            //console.log(result);
            // debugger;
            var subPnl;
            // lastJson= request.response;
            var vjson = eval('(' + result.responseText + ')');
            bindProperty(vjson);
            return;
            /*
            var vValueArray;
            //alert('request.status is '+request.status);
            //alert('vjson is '+vjson);
            var vkeyCount = 0;
            for (var vkey in vjson[0]) {
              vValueArray = {items: []};
              var vName = (vjson[0][vkey].length > 0) ? vjson[0][vkey] : [];
              var vValue;
              if (vjson.length > 1) {
                if (typeof(vjson[1][vkey]) == 'undefined') {
                  vValue = [];
                }
                else
                  vValue = (vjson[1][vkey].length > 0) ? vjson[1][vkey] : []
              }
              else
                vValue = [];
              // var vValue=(vjson[0][vkey].length>1)? vjson[1][vkey]:'';
              for (var idx = 0; idx < vName.length; idx++) {
                vValueArray.items.push({name: vName[idx], value: (vValue.length > idx) ? vValue[idx] : ""});
              }
              
            }
            */
        }
        ,
        error: function(err_result)
        {
            if(err_result.status=="200")
            {
                
                var vjson = eval('(' + err_result.responseText + ')');
                //debugger;
                bindProperty(vjson);
            }
            else
            $("#propertiesA")[0].innerHTML="<p>無資料</p>";
            
        }
        });
        
        
    };
    
    
    dwc['queryOne']=function(callQuery,newconfig)
    {
        queryHandle.setAction(callQuery||showquery, newconfig);
        
        //dwc.setToggleFac('FCID=' + newconfig.fcid);
 
        dwc.toggle('facquery');
 
        //dwc.setToggleFac("");
 
    }
 
    var ctlLocate = new CtlLocate(map, { layer: 'highlight' });
    var createQueryFrm = function (layoutOfQuery, option) {
 
        if (typeof (option) == "undefined") option = {};
        if (typeof (option.qconfig) == "undefined")
            option["qconfig"] = { catelog: 'default' };
 
        var qData;
        var featureQueryHandler = new twdQuery(option.qconfig, function (e) {
            qData = e.body;
        });//handler?
        var dummy = [];
        var idx;
        for (idx = 0; idx < layoutOfQuery.column.length; idx++) dummy.push("0");
        /*
        {
            querybyDgnUfid: true,
            DGNID: e.event.features[idx].data.DGNID,
            UFID: e.event.features[idx].data.UFID
        }
                    */
        if (option.querybyDgnUfid) {
            featureQueryHandler.queryAPI(
                               {
                                   p0: layoutOfQuery.group, p1: layoutOfQuery.name, cnd: [option.DGNID, option.UFID]
                               });
        } else if (typeof (option.qs) != "undefined") {
 
            featureQueryHandler.queryAPI(
                               {
                                   p0: layoutOfQuery.group, p1: layoutOfQuery.name, cnd: option.qs
                               });
        }
        else {
            featureQueryHandler.queryAPI(
                               {
                                   p0: layoutOfQuery.group, p1: layoutOfQuery.name, cnd: (dummy.length == 0 ? "0" : dummy.join(","))
                               });
        }
        var qSchema = featureQueryHandler.getResult().head;
 
        //qData = featureQueryHandler.getResult().body;
        //var fields = featureQueryHandler.getResult().head.ColumnKey;
        //.ColumnInfo[0]
        //{key: "DGNID", name: "圖號", hide: false, dtype: "string", index: "DGNID"} // jqgrid-format
        var evtItem = qSchema.LinkInfo;//:[{"key":"LONLAT","action":"LocateByLL","cols":["LON","LAT"]}]
        var fields = [];
        var columns = [];
        var lstbuttons = [];
 
        var gridFunc = {};
 
        gridFunc["GETVALUE"] = function (vGrid, cols) {
            //var vGrid = this.up().up();
            var idx;
            var result = [];
            var vSel = vGrid.getSelectionModel().getSelection();
            if (vSel.length > 0) {
 
                for (idx = 0; idx < cols.length; idx++) {
                    var tmpcol = vSel[0].getData()[cols[idx]];
                    result.push(tmpcol);
                }
                //cols
            }
            return result;
        }
        //funcHub["ctlLocate"] = ctlLocate;
        //pub
        gridFunc["LocateByLL"] = function (ll) {
            if (ll.length > 1) {
                ctlLocate.action({ clearAll: true, point: { x: ll[0], y: ll[1] }, zoomLevel: 19, projection: wgs84, drawAs: 'point', hide: 'N', zoomToCenter: true });
            }
        }
        gridFunc["LocateBy97"] = function (l97) {
            if (l97.length > 1) {
                ctlLocate.action({ clearAll: true, point: { x: l97[0], y: l97[1] }, zoomLevel: 19, projection: tw97, drawAs: 'point', hide: 'N', zoomToCenter: true });
            }
        }
        gridFunc["LocateBy67"] = function (l67) {
            if (l67.length > 1) {
                ctlLocate.action({ clearAll: true, point: { x: l67[0], y: l67[1] }, zoomLevel: 19, projection: tw67, drawAs: 'point', hide: 'N', zoomToCenter: true });
            }
        }
       
 
       
 
 
 
 
        //
 
        var CTLFunLinkInfo = function (aEvtItem, gridFunc) {
            this.action = function () {
 
                var vGrid = this.up().up();
                var dtCol = gridFunc.GETVALUE(vGrid, aEvtItem.cols);
                gridFunc[aEvtItem.action](dtCol);
            }
        }
        var idxE;
        for (idxE = 0; idxE < evtItem.length; idxE++) {
            var ctBtnClick = new CTLFunLinkInfo(evtItem[idxE], gridFunc);
 
            lstbuttons.push({
                xtype: 'button', text: evtItem[idxE].key, handler: ctBtnClick.action
            });
 
        }
 
 
 
        for (idx = 0; idx < qSchema.ColumnInfo.length; idx++) {
            fields.push({ name: qSchema.ColumnInfo[idx].key, type: qSchema.ColumnInfo[idx].dtype });//dateFormat
            if (qSchema.ColumnInfo[idx].name == "X(97)" || qSchema.ColumnInfo[idx].name == "Y(97)" || qSchema.ColumnInfo[idx].name == "值")
                continue;
            columns.push({
                text: qSchema.ColumnInfo[idx].name,
                hide: qSchema.ColumnInfo[idx].hide,
                //flex: 1, 導致欄位被壓縮
                sortable: true,
                asText: qSchema.ColumnInfo[idx].dtype,// == "string" ? "asText" : "asText"
                dataIndex: qSchema.ColumnInfo[idx].key
            });
 
        }
        var qStore = Ext.create('Ext.data.ArrayStore', {
            //storeId: 'simpsonsStore',
            fields: fields,
            data: qData.vList
            /*
            proxy: {
                type: 'memory',
                reader: {
                    type: 'json',
                    root: 'items'
                }
            }*/
        });
 
 
        //{group: "HYDRANT", name: "q", displayname: "消防栓", column: Array[2]}
        var colQuery = [];
        var idxCol;
        //{cname: "圖號", ctype: "num", require: true, code: Array[0]}
        //code 未寫(qVal,nVal)
 
        for (idxCol = 0; idxCol < layoutOfQuery.column.length; idxCol++) {
            var colType;
            if (layoutOfQuery.column[idxCol].ctype == "num")
                colType = 'numberfield';
            else if (layoutOfQuery.column[idxCol].ctype == "geom")
                colType = 'button';
            else
                colType = 'textfield';
            //colType = layoutOfQuery.column[idxCol].ctype == "num" ? 'numberfield' : 'textfield';
 
            if (layoutOfQuery.column[idxCol].code.length == 0) {
                if (layoutOfQuery.column[idxCol].ctype == 'geom') {//is geom
                    colQuery.push({
                        xtype: colType,
                        text: layoutOfQuery.column[idxCol].cname,
                        scale: 'large',
                        // value:'userwkt',
                        valueFun: function () {
                            var tempPP = drawControl.getWkt();
                            var pts = [];
                            if (typeof (tempPP.features) == "undefined") return "";
                            if (tempPP.features.length > 0) {
 
                                for (var idxOfPP = 0; idxOfPP < tempPP.features[0].points.length; idxOfPP++) {
                                    pts.push(parseInt(tempPP.features[0].points[idxOfPP].x));
                                    pts.push(parseInt(tempPP.features[0].points[idxOfPP].y));
                                }
 
                            }
                            return pts.join(",");
                        },
 
                        handler: function () {
                            var custFun = function (setv) {
                                userwkt = setv;
                            };
                            gridFunc['DRAWPOLYGON'](layoutOfQuery.name);
 
                        }
                    });
                }
                else {
 
                    colQuery.push({
                        xtype: colType,
                        fieldLabel: layoutOfQuery.column[idxCol].cname,
                        allowBlank: !layoutOfQuery.column[idxCol].require
                    });
                }
            } else {//NValue
                /* var lstStore = Ext.create('Ext.data.Store', {
                     
                     fields: ['name','value'],
                     data: layoutOfQuery.column[idxCol].code
                 });*/
                colQuery.push({
                    xtype: 'combobox',
                    store: { xtype: 'store', fields: ['name', 'value'], data: layoutOfQuery.column[idxCol].code },
                    fieldLabel: layoutOfQuery.column[idxCol].cname,
                    queryMode: 'local',
                    displayField: 'name',
                    valueField: 'value'
                    // allowBlank: !layoutOfQuery.column[idxCol].require
                });
 
 
                //http://localhost:1240/FMQuery/LANDMARK.0/q/0?catelog=theme
                //debugger;
            }
 
 
        }
 
        var extQuerypanel1;
        //------------->SelectLayout
        if (option.SelectLayout || 'default' == 'onlyResult') {
 
            extQuerypanel1 = extQuerypanel1 = Ext.create('Ext.window.Window', {
                id: "extQuerypanel1",
                title: '查詢',
                width: 400, height: 300,
                closable: true, //layout:'fit', //'anchor',
                layout: {
                    type: 'vbox',
                    align: 'stretch'
                },
                //items:[{xtype:'button',text:'test'},{xtype:'button',text:'test'},{xtype:'button',text:'test'}   ],
                //bbar:tbl1,
                items: [
                {
                    xtype: 'gridpanel',
                    store: qStore,
                    columns: columns,
                    flex: 1,
 
                    bbar: lstbuttons //[{ xtype: 'button', text: '定位' }, { xtype: 'button', text: '查詢' }]
                }
                ]
            });
            extQuerypanel1.showAt(Ext.getBody().getViewSize().width - 400, 10);
        }
        else {
 
            extQuerypanel1 = Ext.create('Ext.window.Window', {
                id: "extQuerypanel1",
                title: '查詢',
                width: 550, height: 400,
                closable: true, //layout:'fit', //'anchor',
                layout: {
                    type: 'vbox',
                    align: 'stretch'
                },
                //items:[{xtype:'button',text:'test'},{xtype:'button',text:'test'},{xtype:'button',text:'test'}   ],
                //bbar:tbl1,
                items: [{
                    flex: 1,
                    name: 'queryCnd',
                    xtype: 'panel', title: layoutOfQuery.displayname, collapsible: true,
                    items: colQuery,
                    /*
                    //layeroutOfQuery COND
                    items: [{
                        xtype: 'textfield',
                        name: 'dgnid',
                        fieldLabel: '圖號'
                    }, {
                        xtype: 'textfield',
                        name: 'ufid',
                        fieldLabel: '流水號'
                    }],*/
                    bbar: [{
                        xtype: 'button', text: '送出', handler: function () {
 
                            var allitem = this.up().up().items.items;
                            var idxOfI;
                            var result = [];
                            for (idxOfI = 0; idxOfI < allitem.length; idxOfI++) {
                                var tval = allitem[idxOfI].value;
                                var tvaltype = allitem[idxOfI].valueFun;
                                if (typeof (tvaltype) == "function") {
                                    tval = tvaltype();
                                }
                                if (typeof (tval) == "undefined") tval = "null";
                                //if (tval == "userwkt") tval = userwkt;
                                result.push(tval);
                            }
 
                            featureQueryHandler.queryAPI(
                                {
                                    p0: layoutOfQuery.group, p1: layoutOfQuery.name, cnd: result.join(',')
                                }, qStore, function (e) {
                                    qStore.loadData(e.body.vList);
                                    // debugger;
                                });
 
 
                        }
                    },
                        {
                            xtype: 'button', text: '取消', handler: function () {
                                this.up().up().up().close();
                            }
                        }]
                },
                {
                    xtype: 'gridpanel',
                    store: qStore,
                    columns: columns,
                    flex: 2,
                    /*
                    columns: [{
                        header: 'Name', dataIndex: 'name'
                    },
                    {
                        header: 'Email', dataIndex: 'email', flex: 1
                    },
                    {   
                        header: 'Phone', dataIndex: 'phone'
                    }],*/
                    bbar: lstbuttons //[{ xtype: 'button', text: '定位' }, { xtype: 'button', text: '查詢' }]
                }
                ]
            });
            extQuerypanel1.showAt(80, 10);
        }
 
    }
    //dwc['qf'] = createQueryFrm;
    
var fpControl = new OpenLayers.Control.FeaturePopups({
    boxSelectionOptions: {},
    layers: [
        [
        // Uses: Templates for hover & select and safe selection
            markLayer, {templates: {
            // hover: single & list
            hover: '${.popup}'
            //hoverList: '<b>編號:</b>${.number}<br /><b>場所:</b>${.location}<br /><b>位置:</b>${.address}<br />${html}',
            //hoverItem: '<b>編號:</b>${.number}<br />',
            // select: single & list
            //single: '<li><b>編號:</b>${.number}</li><li><b>場所:</b>${.location}</li><li><b>位置:</b>${.address}<li><a href="#" onClick="window.open(\'${.hyperlink}\',\'attribFrm\')">詳細資訊</a></li>',
            //single: '${showHyperlink()} <div><h2>${.name}</h2>${.description}</div>',
            //item: '${popURL()} <li><b>編號:</b>${.number}</li><li><b>場所:</b>${.location}</li><li><b>位置:</b>${.address}<br /></li>'
            //      +'<li><a href="${.hyperlink}" >資訊</a></li>'
        }}
       ]
    ]
});        
            //selectionchanged
map.addControl(fpControl);
    
    selectControl = new OpenLayers.Control.SelectFeature(markLayer,
            {onSelect: dwc.Events.onFeatureSelect, onUnselect: dwc.Events.onFeatureUnselect
            
            });
            
    
    //dwc.addToolBarButton("查詢",{eventId:"tpcquery",iconCls:'tbquery'},null);
    /*dwc.addToolBarButton("更新",{eventId:"refresh",iconCls:"refresh"},function(e)
    {    
        
        
    });*/
   // dwc.addToolBarButton("定位",{eventId:"cclocate",iconCls:'tblocate'},function(e){
    //   });
    /*
    var locateFrm= Ext.create('widget.window', {
            layout:'fit',
            title: '座標定位',
 
            width:300,height:200,
            items:[{xtype:'tabpanel' ,items:[
                
                {title:'經緯度',items:[
                    {xtype: 'textfield', id: 'lon',fieldLabel: '經度(Lon)', allowBlank: false,labelAlign:'right' },
                    {xtype: 'textfield', id: 'lat',fieldLabel: '緯度(Lat)', allowBlank: false ,labelAlign:'right'},
                    {xtype: 'button', text :'定位',handler:function(){
                        if(ctlLocate==null)
                            ctlLocate=new CtlLocate(map);
                        var x=parseFloat(this.up().items.get('lon').getValue());
                        var y=parseFloat(this.up().items.get('lat').getValue());
                        ctlLocate.action({clearAll:true,point:{x:x,y:y},projection:wgs84 ,drawAs:'point',zoomToCenter:true});
 
                    }}
                ]}
                ]
        });
 
        locateFrm.show();});
        
    */
    
    
    //toolbar = dwc.getToolbar(map,{});
    //toolbar=dwc.getExtToolbar(map);
    //ext
    //vLayerGrid
 
    //extToolpanel1
    
    //extToolpanel2
 
    //var scale = new OpenLayers.Control.Scale();
    //map.addControl(scale);
 
   // map.addControl(new OpenLayers.Control.LayerSwitcher());
    
 
    //ctlLocate=new CtlLocate(map,{});
    
    //facQuery.activate();
    
    map.addControl(selectControl);
    
    selectControl.activate();
    
    /* zoom to extent range from geojson data */
    //map.zoomToExtent(hydraulicPoint.getDataExtent());
    dwc.queryOne();
    return dwc;
}
function refreshMap(scope){
var ddt= new Date();
        var dateStr='20150611';   //String(ddt.getYear()+1900)+String(ddt.getMonth()+1)+String(ddt.getDate());
        var weekPeroid=String(ddt.getDay());
        var tmpLayers0;
        tmpLayers0=scope.getLayersByName("paverange");
        setCQL(tmpLayers0[0],"PERIOD='"+weekPeroid+"'");
        tmpLayers0[0].setVisibility(true);
        tmpLayers0=scope.getLayersByName("roadpath");
        setCQL(tmpLayers0[0],"DT0='"+dateStr+"'");
        tmpLayers0[0].setVisibility(true);
        tmpLayers0=scope.getLayersByName("caselocate");
        setCQL(tmpLayers0[0],"DT0='"+dateStr+"'");
        tmpLayers0[0].setVisibility(true);
}
 
//init();