diff options
author | Silvio <silvio@socioambiental.org> | 2013-04-08 19:45:28 -0300 |
---|---|---|
committer | Silvio <silvio@socioambiental.org> | 2013-04-08 19:45:28 -0300 |
commit | 030f80018bb8d904cbe871209bc26e6f341a1c70 (patch) | |
tree | a0d8f0ecd067902d4821d0cc610d76f0ba4313d1 | |
parent | 65a99e2f5773d58724ef210b0195af2ef235e7b8 (diff) | |
download | gmap_arcgis_js-030f80018bb8d904cbe871209bc26e6f341a1c70.tar.gz gmap_arcgis_js-030f80018bb8d904cbe871209bc26e6f341a1c70.tar.bz2 |
Minor fixes and getZoomByBounds method
-rw-r--r-- | gmap_arcgis.js | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/gmap_arcgis.js b/gmap_arcgis.js index 9a9b4db..a2c8b53 100644 --- a/gmap_arcgis.js +++ b/gmap_arcgis.js @@ -4,7 +4,7 @@ function gmapArcgis(config) { return { // Storable properties config: config, - map: config.map, + map: (config.map != undefined) ? config.map : null, // UI unblocker wrapper unblockUI: function() { @@ -219,21 +219,21 @@ function gmapArcgis(config) { var fs = fset.features; var title; for (var i = 0, c = fs.length; i < c; i++) { - fset = fs[i]; + var feature = fs[i]; if (self.config['markers'][element].title != undefined) { - title = fset.attributes[self.config['markers'][element].title]; + title = feature.attributes[self.config['markers'][element].title]; } else { - title = fset.attributes.nome; + title = feature.attributes.nome; } self.config['markers'][element].overlay[i] = {}; self.config['markers'][element].overlay[i].marker = new google.maps.Marker({ title: title, icon: self.config['markers'][element].icon, - position: fset.geometry[0].getPosition(), - map: map, + position: feature.geometry[0].getPosition(), + map: self.map, }); // Use a closure so marker data remains available to the listeners @@ -241,7 +241,7 @@ function gmapArcgis(config) { var marker = self.config['markers'][element].overlay[i].marker; var infowindow = self.config['markers'][element].infowindow; var content = self.config['markers'][element].content; - var attributes = fset.attributes; + var attributes = feature.attributes; google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(content(attributes)); @@ -375,5 +375,35 @@ function gmapArcgis(config) { }); }, + /** + * Returns the zoom level at which the given rectangular region fits in the map view. + * The zoom level is computed for the currently selected map type. + * + * @param {google.maps.Map} map + * @param {google.maps.LatLngBounds} bounds + * @return {Number} zoom level + * @see http://stackoverflow.com/questions/9837017/equivalent-of-getboundszoomlevel-in-gmaps-api-3 + */ + getZoomByBounds: function(bounds) { + var map = this.map(); + var MAX_ZOOM = map.mapTypes.get(map.getMapTypeId()).maxZoom || 21; + var MIN_ZOOM = map.mapTypes.get(map.getMapTypeId()).minZoom || 0; + var ne = map.getProjection().fromLatLngToPoint(bounds.getNorthEast()); + var sw = map.getProjection().fromLatLngToPoint(bounds.getSouthWest()); + var worldCoordWidth = Math.abs(ne.x-sw.x); + var worldCoordHeight = Math.abs(ne.y-sw.y); + + // Fit padding in pixels + var FIT_PAD = 40; + + for (var zoom = MAX_ZOOM; zoom >= MIN_ZOOM; --zoom) { + if (worldCoordWidth*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).width() && + worldCoordHeight*(1<<zoom)+2*FIT_PAD < $(map.getDiv()).height()) { + return zoom; + } + } + + return 0; + } } }; |