Yahoo! UI Library

CHZERO  1.0.0

Yahoo! UI Library > CHZERO > ZeroMapZoomBox.js (source view)
Search:
 
Filters
/**
 * CHZERO.Control.ZeroMapZoomBox<br/>
 * 드래그하여 지도를 확대하는 control
 * @class ZeroMapZoomBox
 * @extends OpenLayers.Control.ZoomBox
 * @constructor
 * @namespace CHZERO.Control
 * @param {Object} options control 옵션 hashtable
 */
CHZERO.Control.ZeroMapZoomBox = OpenLayers.Class(OpenLayers.Control.ZoomBox, {
	CLASS_NAME: 'CHZERO.Control.ZeroMapZoomBox',
	zoomBox: function(position) {
		if (position instanceof OpenLayers.Bounds) {
			var bounds;
			if (!this.out) {
				var minXY = this.map.getLonLatFromPixel(
                            new OpenLayers.Pixel(position.left, position.bottom));
				var maxXY = this.map.getLonLatFromPixel(
                            new OpenLayers.Pixel(position.right, position.top));
				bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat,
                                               maxXY.lon, maxXY.lat);
			} else {
				var pixWidth = Math.abs(position.right - position.left);
				var pixHeight = Math.abs(position.top - position.bottom);
				var zoomFactor = Math.min((this.map.size.h / pixHeight),
                    (this.map.size.w / pixWidth));
				var extent = this.map.getExtent();
				var center = this.map.getLonLatFromPixel(
                    position.getCenterPixel());
				var xmin = center.lon - (extent.getWidth() / 2) * zoomFactor;
				var xmax = center.lon + (extent.getWidth() / 2) * zoomFactor;
				var ymin = center.lat - (extent.getHeight() / 2) * zoomFactor;
				var ymax = center.lat + (extent.getHeight() / 2) * zoomFactor;
				bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax);
			}
			/* always zoom in/out */
			var lastZoom = this.map.getZoom();
			this.map.zoomToExtent(bounds);
			if (lastZoom == this.map.getZoom() && this.alwaysZoom == true) {
				this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
			}
		} else { /* it's a pixel*/
			if (!this.out) {
				this.map.setCenter(this.map.getLonLatFromPixel(position),
                               this.map.getZoom() + 1);
			} else {
				this.map.setCenter(this.map.getLonLatFromPixel(position),
                               this.map.getZoom() - 1);
			}
		}
		this.deactivate();
	}
});

Copyright © 2012 Yahoo! Inc. All rights reserved.