dragpan.js
来自「用来在地图上做操作GIS,在地图上做标记」· JavaScript 代码 · 共 73 行
JS
73 行
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/release-license.txt * for the full text of the license. *//** * @requires OpenLayers/Control.js * @requires OpenLayers/Handler/Drag.js * * Class: OpenLayers.Control.DragPan * DragPan control. * * Inherits from: * - <OpenLayers.Control> */OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { /** * Property: type * {OpenLayers.Control.TYPES} */ type: OpenLayers.Control.TYPE_TOOL, /** * Property: panned * {Boolean} The map moved. */ panned: false, /** * Method: draw * Creates a Drag handler, using <OpenLayers.Control.PanMap.panMap> and * <OpenLayers.Control.PanMap.panMapDone> as callbacks. */ draw: function() { this.handler = new OpenLayers.Handler.Drag(this, {"move": this.panMap, "done": this.panMapDone}); }, /** * Method: panMap * * Parameters: * xy - {<OpenLayers.Pixel>} Pixel of the mouse position */ panMap: function(xy) { this.panned = true; var deltaX = this.handler.last.x - xy.x; var deltaY = this.handler.last.y - xy.y; var size = this.map.getSize(); var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, size.h / 2 + deltaY); var newCenter = this.map.getLonLatFromViewPortPx( newXY ); this.map.setCenter(newCenter, null, this.handler.dragging); }, /** * Method: panMapDone * Finish the panning operation. Only call setCenter (through <panMap>) * if the map has actually been moved. * * Parameters: * xy - {<OpenLayers.Pixel>} Pixel of the mouse position */ panMapDone: function(xy) { if(this.panned) { this.panMap(xy); this.panned = false; } }, CLASS_NAME: "OpenLayers.Control.DragPan"});
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?