/* Ximple */ //OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:3826", OpenLayers.Layer.SphericalMercator.projectForward); //OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3826", OpenLayers.Layer.SphericalMercator.projectForward); OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:3826", OpenLayers.Projection.nullTransform); //GJSONPARSER function GJSonParser(options){ var parserRule={}; var applySetting=function(opt){ parserRule.sourcePrj=opt.sourcePrj || 'EPSG:4326'; parserRule.targetPrj=opt.targetPrj || 'EPSG:4326'; parserRule.root0=opt.root0||''; parserRule.rootGeom=opt.rootGeom||''; parserRule.rootAttrib=opt.rootAttrib||''; parserRule.attributeMapping=opt.attributeMapping||[]; parserRule.colX=opt.colX||'X'; parserRule.colY=opt.colY||'Y'; } applySetting(options||{}); this.getparserRule=function(){ return parserRule;} this.makeMapCol=function(src,tar){ return {"src":src,"tar":tar}; } var builder= function() { var newOptions={}; this.src=function(sourcePrj){newOptions.sourcePrj=sourcePrj;return this;}; this.tar=function(targetPrj){newOptions.targetPrj=targetPrj;return this;}; this.root0=function(root0){newOptions.root0=root0;return this;}; this.rootGeom=function(rootGeom){newOptions.rootGeom=rootGeom;return this;}; this.rootAttrib=function(rootAttrib){newOptions.rootAttrib=rootAttrib;return this;}; this.colX=function(colX){newOptions.colX=colX;return this;}; this.colY=function(colY){newOptions.colY=colY;return this;}; this.addCol=function(src,tar){ if(newOptions.attributeMapping==null)newOptions.attributeMapping=[]; newOptions.attributeMapping.push( {"src":src,"tar":tar}); return this; }; this.build=function() { return newOptions; } } this.optionsBuilder=function(){ return new builder(); } this.parser=function(gJson,opt){ dbgOption=opt; if(opt==null) opt={}; var results=[];// {"type":"FeatureCollection",features:[]}; var parserList=opt.attributeMapping||parserRule.attributeMapping; var aResult; var dx; var dy; var tempRootstr=(opt.root0||parserRule.root0); if (tempRootstr.length>0)tempRootstr='.'+tempRootstr; var Items= eval("gJson"+ tempRootstr); //(opt.root0||parserRule.root0)); //gJson[opt.root0||parserRule.root0]; //maybe deeper then1 //rootGeom var tempGeomstr=(opt.rootGeom||parserRule.rootGeom); if (tempGeomstr.length>0)tempGeomstr='.'+tempGeomstr; var tempAttrstr=(opt.rootAttrib||parserRule.rootAttrib); if (tempAttrstr.length>0)tempAttrstr='.'+tempAttrstr; for(var aItemId in Items) {//index var aItem=Items[aItemId]; //init aResult aResult={}; dx=0; dy=0; //get x,y //dx=aItem[(opt.colX||parserRule.colX)]; //dy=aItem[(opt.colY||parserRule.colY)]; dx=eval('aItem'+tempGeomstr+'.'+(opt.colX||parserRule.colX)); dy=eval('aItem'+tempGeomstr+'.'+(opt.colY||parserRule.colY)); //get properties //console.log('aItem'+tempAttrstr); var aPropItem=eval('aItem'+tempAttrstr); if(parserList.length==0) { for(var aCol in aPropItem) { if(typeof aPropItem[aCol] == "string" ) { //eval('aResult.'+aCol+'="'+ aItem[aCol]+'"'); aResult[aCol]=aPropItem[aCol]; } else if(typeof aPropItem[aCol] == "number") { //eval('aResult.'+aCol+'='+ aItem[aCol]); aResult[aCol]=aPropItem[aCol]; } //console.log('aResult.'+aCol+'="'+ aPropItem[aCol]+'"'); } } else { // [{src:'col1',tar:'hello'}] for(var aCol in parserList) { if(typeof parserList[aCol.src] == "string" ) { aResult[aCol.tar]=parserList[aCol.src]; //eval('aResult.'+aCol.tar+'="'+ aItem[aCol.src]+'"'); } else if(typeof parserList[aCol.src] == "number") { aResult[aCol.tar]=parserList[aCol.src]; //eval('aResult.'+aCol.tar+'='+ aItem[aCol.src]); } } } //console.log('x,y=',dx,dy); //combine data results.push(({"type":"Feature","geometry":{"type":"Point","coordinates":[dx||0,dy||0]},"properties":aResult})); } var geoJosnParser=new OpenLayers.Format.GeoJSON({ 'internalProjection':opt.targetPrj||parserRule.targetPrj, 'externalProjection':opt.sourcePrj||parserRule.sourcePrj }); //dbgresults=results; //dbgJp=geoJosnParser; console.log(geoJosnParser.internalProjection,'<--',geoJosnParser.externalProjection); return geoJosnParser.read(({"type":"FeatureCollection","features":(results)})); } } //GJSONPARSER^ var AProto=function(config) { var action=function(option){}; this.setAction=function(func_action,newconfig) { config= (typeof(newconfig)=='undefined'?config:newconfig); action=func_action; } this.callAction=function(option) { action(option); } this.getConfig=function(option) { return config; } }; //CreateLayer (layerType=wms,vector,google) function createLayer(layerName,config){ var tmp; switch(config.layerType) //wms,vector,google { case "mapguide": //var extent = new OpenLayers.Bounds(295199.9995, 2749893.7495, 324028.65675, 2789700.0005); var options = { // isBaseLayer: true, sphericalMercator: true, transitionEffect: "resize", buffer: 1, useOverlay: false, useAsyncOverlay: false, projection: tw97, //maxExtent: extent, singleTile: true }; var engParams = { mapdefinition: config.layerid, // mapName:"LandMap2",//,OPERATION:"GETPROVIDERCAPABILITIES" USERNAME:"Anonymous" //session:"5b4cfa12-5db6-11e5-8000-080027009ce6_en_A31D9D110B060B050B04" }; tmp = new OpenLayers.Layer.MapGuide2(layerName, config.content, engParams, options); //tmp.projection="EPSG:3826"; break; case "wmts": var matrixIds =[]; for (var i=0; i<24; ++i) { matrixIds.push( (config.projection||"EPSG:4326") +':' + i); } tmp=new OpenLayers.Layer.WMTS ( { VERSION:"1.0.0", name: layerName, url: config.content, layer: config.layerid, matrixIds: matrixIds, matrixSet: (config.projection||"EPSG:4326"), style: "_null", format: "image/png" }); break; case "wms": tmp=new OpenLayers.Layer.WMS ( layerName, config.content, { LAYERS: config.layerid, STYLES: '', format: 'image/png8', tiled: config.tiled ||true, //true, //tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom, transparent:config.transparent||true, //true, numZoomLevels: 24 , tileOptions: { eventListeners: { 'beforedraw': function(evt) { // do something on loadend //console.log('beforedraw'); } , 'loaderror': function(evt) { // do something on loadend //console.log('loaderror'); } , 'loadend': function(evt) { // do something on loadend //console.log('loadend'); } , 'loadstart': function(evt) { // do something on loadend //console.log('loadstart'); } } } //minScale : }, { projection:new OpenLayers.Projection(config.projection), isBaseLayer: config.isBaselayer||false, transparent: "true", buffer: 0, displayOutsideMaxExtent: true , displayInLayerSwitcher: true , visibility: false, transitionEffect: 'resize' // yx : {'EPSG:3826' : false} }); break; case "awms": tmp=new OpenLayers.Layer.WMS ( layerName, config.content +'/animate', { LAYERS: config.layerid, STYLES: '', FORMAT: 'image/gif;subtype=animated', FORMAT_OPTIONS: 'antialias:none;gif_loop_continuosly:true;gif_frames_delay:500', REQUEST: 'getmap', SERVICE: 'animate', // MUST BE 'animate'. A 'wms' value will break it! //tiled: config.tiled ||true, //true, //tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom, transparent:config.transparent||true, //true, VERSION: '1.1.1', aparam: 'cql_filter', avalues: '1=0;dt0=20150507,2=2;dt0=20000101', numZoomLevels: 24 , tileOptions: { eventListeners: { 'beforedraw': function(evt) { // do something on loadend //console.log('beforedraw'); } , 'loaderror': function(evt) { // do something on loadend //console.log('loaderror'); } , 'loadend': function(evt) { // do something on loadend //console.log('loadend'); } , 'loadstart': function(evt) { // do something on loadend //console.log('loadstart'); } } } //minScale : }, { projection:new OpenLayers.Projection(config.projection), isBaseLayer: config.isBaselayer||false, transparent: "true", buffer: 0, displayOutsideMaxExtent: true , displayInLayerSwitcher: true , visibility: false, transitionEffect: 'resize' // yx : {'EPSG:3826' : false} }); break; case "google": if(typeof(google)=="undefined") { tmp=new OpenLayers.Layer.Vector( layerName, { projection:epsg3857, transparent: "true", buffer: 0, transitionEffect: 'resize', displayOutsideMaxExtent: true , isBaseLayer: true , numZoomLevels: 24, displayInLayerSwitcher: true , visibility: false}); } else { tmp = new OpenLayers.Layer.Google( layerName, {type:(config.content)||google.maps.MapTypeId.ROADMAP ,numZoomLevels: 24, visibility: false, // ,projection: tw97 //,maxExtent:googleBound , //notwork // RESOLUuTIONS: [1.40625, // serverResolutions: [1.40625, transitionEffect: 'resize' }, {isBaseLayer: true, buffer: 0 } ); } break; case "vector" : if(typeof(config.styleMap)!="undefined") { var vInit={styleMap:config.styleMap}; if(typeof(config.projection)!="undefined") vInit['projection']=config.projection; tmp=new OpenLayers.Layer.Vector( layerName, vInit); } else { tmp = new OpenLayers.Layer.Vector(layerName, { styleMap: new OpenLayers.StyleMap({ 'default': OpenLayers.Util.applyDefaults({ strokeWidth: 3, graphicName: 'triangle', pointRadius:6, //'${radius}', rotation: '${angle}' }, OpenLayers.Feature.Vector.style['default'] ), 'select': OpenLayers.Util.applyDefaults({ pointRadius:6 //'${radius}' }, OpenLayers.Feature.Vector.style['select'] ) }) }); } break; default: console.log('Unsupply LayerType'); break; } return tmp; } function makeResolution(thisLayer,resolutionsLevel) { if(typeof(thisLayer.resolutions)=="undefined") return; thisLayer.resolutions.push(thisLayer.resolutions[thisLayer.resolutions.length-1]/2.0) ; if(thisLayer.resolutions.lengthmaxBoundBox['right']?features[idx].geometry.bounds.right:maxBoundBox['right']; maxBoundBox['top']=features[idx].geometry.bounds.topmaxBoundBox['bottom']?features[idx].geometry.bounds.bottom:maxBoundBox['bottom']; } } } return maxBoundBox; } var extMapResultion=function(thismap,resolutionsLevel)//太高會有alias問題 { var layerkey; var aLayer; for (layerkey in thismap.layers) { aLayer= thismap.layers[layerkey] ; makeResolution (aLayer,resolutionsLevel); makeScale (aLayer,resolutionsLevel); if(aLayer.scales==null) return; if(typeof(aLayer.scales)!="undefined"){ aLayer.maxScale=aLayer.scales[aLayer.scales.length-1] ; aLayer.minResolution=aLayer.resolutions[aLayer.resolutions.length-1] ; aLayer.numZoomLevels = resolutionsLevel; } } }; var CtlCopyFeatures=function(desLayer,config) { if(typeof(config)=="undefined")config={}; this.action=function(option){ if (typeof(option)=="undefined")option={}; var resultData={}; // !! fromProjection !! var wktReader=new OpenLayers.Format.WKT({ 'internalProjection':option.toprojection ||desLayer.projection , //target 'externalProjection':option.formprojection|| desLayer.projection //src }); if(option.clearAll) { desLayer.destroyFeatures(); } //add features if(typeof(option.features)!="undefined") { for(var idxOfFeatures=0 ;idxOfFeatures= 0 && x <= 99 && y >= 0 && y <= 99) { if (x < 10) num = "0" + String(x); else num = String(x); if (y < 10) num = num + "0" + String(y); else num = num + String(y); } return (num); } this. get1000=function(dx,dy) { var x, y; num = ""; x = parseInt((parseInt( dx) - 270400) / 800); y = parseInt((parseInt( dy)- 2743500) / 600); num = transforNum(x, y); return (num); } this. get500=function( dx, dy) { var x, y, ofx, ofy; var num = ""; x = parseInt((parseInt( dx )- 270400) / 800); y = parseInt((parseInt( dy )- 2743500) / 600); num = transforNum(x, y); ofx = parseInt((dx - x * 800 - 270400) / 400); ofy = parseInt((dy - y * 600 - 2743500) / 300); if (ofx != 0 && ofy != 0) num = num + "A"; else if (ofx != 0 && ofy == 0) num = num + "B"; else if (ofx == 0 && ofy == 0) num = num + "C"; else if (ofx == 0 && ofy != 0) num = num + "D"; return (num); } } var dgnParser=new DGNParser(); var CtlGetWKT=function(scope,config) { if(typeof(config)=="undefined")config={}; this.parser=function(feature,option) { if (typeof(option)=="undefined")option={}; var wktReader=new OpenLayers.Format.WKT({ 'internalProjection':option.toprojection ||tw97, //target 'externalProjection':option.formprojection|| scope.projection //src }); if ('featurePoint' == option.geometryType || 'featurePoint') { var geom = wktReader.read(feature.geometry.toString()); var resultobj = { wkt: geom.geometry.toString() }; if (wktReader.internalProjection == tw97) { resultobj["dgnid1000"] = dgnParser.get1000(geom.geometry.x, geom.geometry.y); resultobj["dgnid500"] = dgnParser.get500(geom.geometry.x, geom.geometry.y); } resultobj["point"] = { x: geom.geometry.x, y: geom.geometry.y }; return resultobj; } } this.action=function(option){ if (typeof(option)=="undefined")option={}; var resultData={}; var wktReader=new OpenLayers.Format.WKT({ 'internalProjection':option.toprojection ||tw97, //target 'externalProjection':option.formprojection|| scope.projection //src }); //wktReader.read(dwc1.getMap() .layers[10].features[0].geometry) var srcLayer=config.srcLayer||'drawTemp'; var workLayers=scope.getLayersByName(srcLayer); if(workLayers.length==0) return resultData; // parser97DGNID: true, extactPoints: true //dwc1.getWkt({parser97DGNID:true}).bounds.dgnid500 var tempPoints=[]; var featureData=[]; var boundOfWkt={left:0,right:0,top:0,buttom:0}; //不支援空心圖 for(var idxOfFeatures=0 ;idxOfFeaturesboundOfWkt.top)boundOfWkt.top=tempWkt1.top; if(tempWkt1.right>boundOfWkt.right)boundOfWkt.right=tempWkt1.right; if(tempWkt1.left0) { boundOfWkt['dgnid500']=dgnParser.get500(vpoint0s[0].x,vpoint0s[0].y); boundOfWkt['dgnid1000']=dgnParser.get1000(vpoint0s[0].x,vpoint0s[0].y); } } featureData.push(tempfeature); //return resultData; } return {features:featureData,bounds:boundOfWkt}; } this.cancel=function(config){ if(typeof(config)=="undefined")config={}; var vLayer=scope.getLayersByName(config.layer||"drawTemp"); vLayer[0].destroyFeatures(); } } var CtlLocate=function(scope,config){ //var zoomCtl=new OpenLayers.Control.ZoomBox(); if(typeof(config)=="undefined")config={}; //var wkt=wktgoogleFrom67; this.action=function(option) // {point:{x,y}} {pts:[xy xy xy ]} ,wkt // drawAs: point /line /polygon // zoomToView { var points=[]; var buffSize=0; var wkt=new OpenLayers.Format.WKT({ 'internalProjection':scope.projection , //target 'externalProjection': option.projection||tw97 //src }); if(typeof(option.buffsize)!="undefined") { buffSize= parseFloat (buffsize); } if(typeof(option.point)!="undefined"){ points.push(parseFloat(option.point.x)); points.push(parseFloat(option.point.y)); } if(typeof(option.points)!="undefined"){ for(var idx=0;idx0?buffSize:5); tmp+=(points[0]-bufTemp+" "+points[1]-bufTemp+","); tmp+=(points[0]+bufTemp+" "+points[1]-bufTemp+","); tmp+=(points[0]+bufTemp+" "+points[1]+bufTemp+","); tmp+=(points[0]-bufTemp+" "+points[1]+bufTemp+","); tmp+=(points[0]-bufTemp+" "+points[1]-bufTemp+")"); }else if(points.length==4){ var bufTemp=parseFloat(buffSize>0?buffSize:0); tmp+=((points[0]-bufTemp)+" "+(points[1]-bufTemp+",")); tmp+=((points[2]+bufTemp)+" "+(points[1]-bufTemp+",")); tmp+=((points[2]+bufTemp)+" "+(points[3]+bufTemp+",")); tmp+=((points[0]-bufTemp)+" "+(points[3]+bufTemp+",")); tmp+=((points[0]-bufTemp)+" "+(points[1]-bufTemp+")")); }else if(points.length==8||points.length==10){ var bufTemp=parseFloat(buffSize>0?buffSize:0); tmp=tmp+points[0]-bufTemp+" "+points[1]-bufTemp+","; tmp=tmp+points[2]+bufTemp+" "+points[3]-bufTemp+","; tmp=tmp+points[4]+bufTemp+" "+points[5]+bufTemp+","; tmp=tmp+points[6]-bufTemp+" "+points[7]+bufTemp+","; tmp=tmp+points[0]-bufTemp+" "+points[1]-bufTemp+")"; }else{ tmp=tmp+"0 0)"; } //console.log(tmp); vFeature=wkt.read(tmp); setFeature(vFeature); vLayer[0].addFeatures(vFeature); }else if(option.drawAs=='line'){ var tmp= "LINESTRING("; var bufTemp=0; for(var idx=0;idx0) { tmp=tmp+","; } tmp=tmp+points[idx]+" "+points[idx+1]; } tmp=tmp+")"; vFeature=wkt.read(tmp); setFeature(vFeature); vLayer[0].addFeatures(vFeature); }else if(option.drawAs=='polygon'){ var tmp= "POLYGON(("; var bufTemp=0; for(var idx=0;idx0) { tmp=tmp+","; } tmp=tmp+points[idx]+" "+points[idx+1]; } if(points[0]!=points[points.length-2] && points[1]!=points[points.length-1]) { tmp=tmp+","+points[0]+" "+points[1]; } tmp=tmp+"))"; vFeature=wkt.read(tmp); setFeature(vFeature); vLayer[0].addFeatures(vFeature); } else if(option.drawAs=='point'||option.drawAs=='mpoint') { var tmp; var bufTemp=0; for(var idx=0;idx