add dragzoom.js in the advance search function.
This commit is contained in:
parent
c0b3dbba64
commit
a40b390bc4
|
@ -0,0 +1,30 @@
|
|||
|
||||
function DragZoomControl(a,b,c){this.globals={draggingOn:false,cornerTopDiv:null,cornerRightDiv:null,cornerBottomDiv:null,cornerLeftDiv:null,mapPosition:null,outlineDiv:null,mapWidth:0,mapHeight:0,mapRatio:0,startX:0,startY:0,borderCorrection:0};this.globals.style={opacity:.2,fillColor:"#000",border:"2px solid blue"};var d=this.globals.style;for(var s in a){d[s]=a[s]}var e=d.border.split(' ');d.outlineWidth=parseInt(e[0].replace(/\D/g,''));d.outlineColor=e[2];d.alphaIE='alpha(opacity='+(d.opacity*100)+')';this.globals.backStack=[];this.globals.options={buttonHTML:'zoom ...',buttonStartingStyle:{width:'52px',border:'1px solid black',padding:'2px'},buttonStyle:{background:'#FFF'},backButtonHTML:'zoom back',backButtonStyle:{background:'#FFF',display:'none'},buttonZoomingHTML:'Drag a region on the map',buttonZoomingStyle:{background:'#FF0'},overlayRemoveTime:6000,backButtonEnabled:false,stickyZoomEnabled:false};for(var s in b){this.globals.options[s]=b[s]}if(c==null){c={}}this.globals.callbacks=c}
|
||||
DragZoomControl.prototype=new GControl();
|
||||
DragZoomControl.prototype.saveMapContext=function(a){if(this.globals.options.backButtonEnabled){this.saveBackContext_(a,true);this.globals.backButtonDiv.style.display='block'}};
|
||||
DragZoomControl.prototype.initiateZoom=function(){this.buttonclick_()};
|
||||
DragZoomControl.prototype.initiateZoomBack=function(){if(this.globals.options.backButtonEnabled)this.backbuttonclick_()};
|
||||
DragZoomControl.prototype.initButton_=function(a){var G=this.globals;var b=document.createElement('div');b.innerHTML=G.options.buttonHTML;b.id='gzoom-control';DragZoomUtil.style([b],{cursor:'pointer',zIndex:200});DragZoomUtil.style([b],G.options.buttonStartingStyle);DragZoomUtil.style([b],G.options.buttonStyle);a.appendChild(b);return b};
|
||||
DragZoomControl.prototype.initBackButton_=function(a){var G=this.globals;var b=document.createElement('div');b.innerHTML=G.options.backButtonHTML;b.id='gzoom-back';DragZoomUtil.style([b],{cursor:'pointer',zIndex:200});DragZoomUtil.style([b],G.options.buttonStartingStyle);DragZoomUtil.style([b],G.options.backButtonStyle);a.appendChild(b);return b};
|
||||
DragZoomControl.prototype.setButtonMode_=function(a){var G=this.globals;if(a=='zooming'){G.buttonDiv.innerHTML=G.options.buttonZoomingHTML;DragZoomUtil.style([G.buttonDiv],G.options.buttonStartingStyle);DragZoomUtil.style([G.buttonDiv],G.options.buttonZoomingStyle)}else{G.buttonDiv.innerHTML=G.options.buttonHTML;DragZoomUtil.style([G.buttonDiv],G.options.buttonStartingStyle);DragZoomUtil.style([G.buttonDiv],G.options.buttonStyle)}};
|
||||
DragZoomControl.prototype.initialize=function(a){var G=this.globals;var b=this;var c=a.getContainer();var d=document.createElement("div");DragZoomUtil.style([d],{cursor:'pointer',zIndex:150});var f=this.initButton_(d);var g=this.initBackButton_(d);c.appendChild(d);var h=document.createElement("div");h.id='gzoom-map-cover';h.innerHTML='<div id="gzoom-outline" style="position:absolute;display:none;"></div><div id="gzoom-cornerTopDiv" style="position:absolute;display:none;"></div><div id="gzoom-cornerLeftDiv" style="position:absolute;display:none;"></div><div id="gzoom-cornerRightDiv" style="position:absolute;display:none;"></div><div id="gzoom-cornerBottomDiv" style="position:absolute;display:none;"></div>';DragZoomUtil.style([h],{position:'absolute',display:'none',overflow:'hidden',cursor:'crosshair',zIndex:101});c.appendChild(h);GEvent.addDomListener(f,'click',function(e){b.buttonclick_(e)});GEvent.addDomListener(g,'click',function(e){b.backbuttonclick_(e)});GEvent.addDomListener(h,'mousedown',function(e){b.coverMousedown_(e)});GEvent.addDomListener(document,'mousemove',function(e){b.drag_(e)});GEvent.addDomListener(document,'mouseup',function(e){b.mouseup_(e)});G.mapPosition=DragZoomUtil.getElementPosition(c);G.outlineDiv=DragZoomUtil.gE("gzoom-outline");G.buttonDiv=DragZoomUtil.gE("gzoom-control");G.backButtonDiv=DragZoomUtil.gE("gzoom-back");G.mapCover=DragZoomUtil.gE("gzoom-map-cover");G.cornerTopDiv=DragZoomUtil.gE("gzoom-cornerTopDiv");G.cornerRightDiv=DragZoomUtil.gE("gzoom-cornerRightDiv");G.cornerBottomDiv=DragZoomUtil.gE("gzoom-cornerBottomDiv");G.cornerLeftDiv=DragZoomUtil.gE("gzoom-cornerLeftDiv");G.map=a;G.borderCorrection=G.style.outlineWidth*2;this.setDimensions_();this.initStyles_();G.mapCover.onselectstart=function(){return false};return d};
|
||||
DragZoomControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(3,120))};
|
||||
DragZoomControl.prototype.coverMousedown_=function(e){var G=this.globals;var a=this.getRelPos_(e);G.startX=a.left;G.startY=a.top;DragZoomUtil.style([G.mapCover],{background:'transparent',opacity:1,filter:'alpha(opacity=100)'});DragZoomUtil.style([G.outlineDiv],{left:G.startX+'px',top:G.startY+'px',display:'block',width:'1px',height:'1px'});G.draggingOn=true;G.cornerTopDiv.style.top=(G.startY-G.mapHeight)+'px';G.cornerTopDiv.style.display='block';G.cornerLeftDiv.style.left=(G.startX-G.mapWidth)+'px';G.cornerLeftDiv.style.top=G.startY+'px';G.cornerLeftDiv.style.display='block';G.cornerRightDiv.style.left=G.startX+'px';G.cornerRightDiv.style.top=G.startY+'px';G.cornerRightDiv.style.display='block';G.cornerBottomDiv.style.left=G.startX+'px';G.cornerBottomDiv.style.top=G.startY+'px';G.cornerBottomDiv.style.width='0px';G.cornerBottomDiv.style.display='block';if(G.callbacks.dragstart!=null){G.callbacks.dragstart(G.startX,G.startY)}return false};
|
||||
DragZoomControl.prototype.drag_=function(e){var G=this.globals;if(G.draggingOn){var a=this.getRelPos_(e);rect=this.getRectangle_(G.startX,G.startY,a,G.mapRatio);if(rect.left){addX=-rect.width}else{addX=0}if(rect.top){addY=-rect.height}else{addY=0}DragZoomUtil.style([G.outlineDiv],{left:G.startX+addX+'px',top:G.startY+addY+'px',display:'block',width:'1px',height:'1px'});G.outlineDiv.style.width=rect.width+"px";G.outlineDiv.style.height=rect.height+"px";G.cornerTopDiv.style.height=((G.startY+addY)-(G.startY-G.mapHeight))+'px';G.cornerLeftDiv.style.top=(G.startY+addY)+'px';G.cornerLeftDiv.style.width=((G.startX+addX)-(G.startX-G.mapWidth))+'px';G.cornerRightDiv.style.top=G.cornerLeftDiv.style.top;G.cornerRightDiv.style.left=(G.startX+addX+rect.width+G.borderCorrection)+'px';G.cornerBottomDiv.style.top=(G.startY+addY+rect.height+G.borderCorrection)+'px';G.cornerBottomDiv.style.left=(G.startX-G.mapWidth+((G.startX+addX)-(G.startX-G.mapWidth)))+'px';G.cornerBottomDiv.style.width=(rect.width+G.borderCorrection)+'px';if(G.callbacks.dragging!=null){G.callbacks.dragging(G.startX,G.startY,rect.endX,rect.endY)}return false}};
|
||||
DragZoomControl.prototype.mouseup_=function(e){var G=this.globals;if(G.draggingOn){var a=this.getRelPos_(e);G.draggingOn=false;var b=this.getRectangle_(G.startX,G.startY,a,G.mapRatio);if(b.left)b.endX=b.startX-b.width;if(b.top)b.endY=b.startY-b.height;this.resetDragZoom_();var c=new GPoint(b.startX,b.startY);var d=new GPoint(b.endX,b.startY);var f=new GPoint(b.endX,b.endY);var g=new GPoint(b.startX,b.endY);var h=G.map.fromContainerPixelToLatLng(c);var i=G.map.fromContainerPixelToLatLng(d);var j=G.map.fromContainerPixelToLatLng(f);var k=G.map.fromContainerPixelToLatLng(g);var l=new GPolyline([h,i,j,k,h],G.style.outlineColor,G.style.outlineWidth+1,.4);try{G.map.addOverlay(l);setTimeout(function(){G.map.removeOverlay(l)},G.options.overlayRemoveTime)}catch(e){}polyBounds=l.getBounds();var i=polyBounds.getNorthEast();var k=polyBounds.getSouthWest();var j=new GLatLng(k.lat(),i.lng());var h=new GLatLng(i.lat(),k.lng());zoomLevel=G.map.getBoundsZoomLevel(polyBounds);center=polyBounds.getCenter();G.map.setCenter(center,zoomLevel);if(G.callbacks.dragend!=null){G.callbacks.dragend(h,i,j,k,c,d,f,g)}if(G.options.stickyZoomEnabled){this.initCover_();if(G.options.backButtonEnabled)this.saveBackContext_(G.options.backButtonHTML,false);G.backButtonDiv.style.display='none'}}};
|
||||
DragZoomControl.prototype.setDimensions_=function(){var G=this.globals;var a=G.map.getSize();G.mapWidth=a.width;G.mapHeight=a.height;G.mapRatio=G.mapHeight/G.mapWidth;DragZoomUtil.style([G.mapCover,G.cornerTopDiv,G.cornerRightDiv,G.cornerBottomDiv,G.cornerLeftDiv],{left:'0px',width:G.mapWidth+'px',height:G.mapHeight+'px'})};
|
||||
DragZoomControl.prototype.initStyles_=function(){var G=this.globals;DragZoomUtil.style([G.mapCover,G.cornerTopDiv,G.cornerRightDiv,G.cornerBottomDiv,G.cornerLeftDiv],{filter:G.style.alphaIE,opacity:G.style.opacity,background:G.style.fillColor});G.outlineDiv.style.border=G.style.border};
|
||||
DragZoomControl.prototype.buttonclick_=function(){var G=this.globals;G.backButtonDiv.style.display='none';if(G.mapCover.style.display=='block'){this.resetDragZoom_();if(G.options.backButtonEnabled){this.restoreBackContext_();if(G.backStack.length==0)G.backButtonDiv.style.display='none'}}else{this.initCover_();if(G.options.backButtonEnabled)this.saveBackContext_(G.options.backButtonHTML,false)}};
|
||||
DragZoomControl.prototype.backbuttonclick_=function(){var G=this.globals;if(G.options.backButtonEnabled&&G.backStack.length>0){this.restoreBackContext_();if(G.callbacks['backbuttonclick']!=null){G.callbacks.backbuttonclick(G.methodCall)}}};
|
||||
DragZoomControl.prototype.saveBackContext_=function(a,b){var G=this.globals;var c={};c["center"]=G.map.getCenter();c["zoom"]=G.map.getZoom();c["maptype"]=G.map.getCurrentMapType();c["text"]=G.backButtonDiv.innerHTML;c["methodCall"]=b;G.backStack.push(c);G.backButtonDiv.innerHTML=a};
|
||||
DragZoomControl.prototype.restoreBackContext_=function(){var G=this.globals;var a=G.backStack.pop();G.map.setCenter(a["center"],a["zoom"],a["maptype"]);G.backButtonDiv.innerHTML=a["text"];G.methodCall=a["methodCall"];if(G.backStack.length==0)G.backButtonDiv.style.display='none'};
|
||||
DragZoomControl.prototype.initCover_=function(){var G=this.globals;G.mapPosition=DragZoomUtil.getElementPosition(G.map.getContainer());this.setDimensions_();this.setButtonMode_('zooming');DragZoomUtil.style([G.mapCover],{display:'block',background:G.style.fillColor});DragZoomUtil.style([G.outlineDiv],{width:'0px',height:'0px'});if(G.callbacks['buttonclick']!=null){G.callbacks.buttonclick()}};
|
||||
DragZoomControl.prototype.getRelPos_=function(e){var a=DragZoomUtil.getMousePosition(e);var G=this.globals;return{top:(a.top-G.mapPosition.top),left:(a.left-G.mapPosition.left)}};
|
||||
DragZoomControl.prototype.getRectangle_=function(a,b,c,d){var e=false;var f=false;var g=c.left-a;var h=c.top-b;if(g<0){g=g*-1;e=true}if(h<0){h=h*-1;f=true}delta=g>h?g:h;return{startX:a,startY:b,endX:a+delta,endY:b+parseInt(delta*d),width:delta,height:parseInt(delta*d),left:e,top:f}};
|
||||
DragZoomControl.prototype.resetDragZoom_=function(){var G=this.globals;DragZoomUtil.style([G.mapCover,G.cornerTopDiv,G.cornerRightDiv,G.cornerBottomDiv,G.cornerLeftDiv],{display:'none',opacity:G.style.opacity,filter:G.style.alphaIE});G.outlineDiv.style.display='none';this.setButtonMode_('normal');if(G.options.backButtonEnabled&&(G.backStack.length>0))G.backButtonDiv.style.display='block'};
|
||||
var DragZoomUtil={};
|
||||
DragZoomUtil.gE=function(a){return document.getElementById(a)}
|
||||
DragZoomUtil.getMousePosition=function(e){var a=0;var b=0;if(!e)var e=window.event;if(e.pageX||e.pageY){a=e.pageX;b=e.pageY}else if(e.clientX||e.clientY){a=e.clientX+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft);b=e.clientY+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)}return{left:a,top:b}};
|
||||
DragZoomUtil.getElementPosition=function(a){var b=a.offsetLeft;var c=a.offsetTop;var d=a.offsetParent;while(d!=null){b+=d.offsetLeft;c+=d.offsetTop;d=d.offsetParent}return{left:b,top:c}};
|
||||
DragZoomUtil.style=function(a,b){if(typeof(a)=='string'){a=DragZoomUtil.getManyElements(a)}for(var i=0;i<a.length;i++){for(var s in b){a[i].style[s]=b[s]}}};
|
||||
DragZoomUtil.getManyElements=function(a){var b=a.split(',');var c=[];for(var i=0;i<b.length;i++){c[c.length]=DragZoomUtil.gE(b[i])};return c};
|
Loading…
Reference in New Issue