Permalink
Browse files

Added mapByCenterZoom() and mapByExtent() convenience functions

  • Loading branch information...
1 parent f12c513 commit e28f141dba9dc7c8f2f8a4f7b2fa7756a59d0c87 @migurski migurski committed Feb 20, 2012
Showing with 100 additions and 1 deletion.
  1. +1 −0 Makefile
  2. +49 −0 modestmaps.js
  3. +1 −1 modestmaps.min.js
  4. +49 −0 src/convenience.js
View
@@ -15,6 +15,7 @@ JS_FILES = \
src/requests.js \
src/layer.js \
src/map.js \
+ src/convenience.js \
src/end.js
all: modestmaps.js modestmaps.min.js
View
@@ -2890,6 +2890,55 @@ var MM = com.modestmaps = {
}
}
};
+
+ // Instance of a map intended for drawing to a div.
+ //
+ // * `parent` (required DOM element)
+ // Can also be an ID of a DOM element
+ // * `provider` (required MM.MapProvider or URL template)
+ // * `location` (required MM.Location)
+ // Location for map to show
+ // * `zoom` (required number)
+ MM.mapByCenterZoom = function(parent, provider, location, zoom)
+ {
+ if (typeof provider == 'string')
+ {
+ provider = new MM.TemplatedMapProvider(provider);
+ }
+
+ var layer = new MM.Layer(provider, null),
+ map = new MM.Map(parent, layer, false);
+
+ map.setCenterZoom(location, zoom);
+ map.draw();
+
+ return map;
+ };
+
+ // Instance of a map intended for drawing to a div.
+ //
+ // * `parent` (required DOM element)
+ // Can also be an ID of a DOM element
+ // * `provider` (required MM.MapProvider or URL template)
+ // * `locationA` (required MM.Location)
+ // Location of one map corner
+ // * `locationB` (required MM.Location)
+ // Location of other map corner
+ MM.mapByExtent = function(parent, provider, locationA, locationB)
+ {
+ if (typeof provider == 'string')
+ {
+ provider = new MM.TemplatedMapProvider(provider);
+ }
+
+ var layer = new MM.Layer(provider, null),
+ map = new MM.Map(parent, layer, false);
+
+ map.setExtent([locationA, locationB]);
+ map.draw();
+
+ return map;
+ };
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
Point: MM.Point,
View
View
@@ -0,0 +1,49 @@
+
+ // Instance of a map intended for drawing to a div.
+ //
+ // * `parent` (required DOM element)
+ // Can also be an ID of a DOM element
+ // * `provider` (required MM.MapProvider or URL template)
+ // * `location` (required MM.Location)
+ // Location for map to show
+ // * `zoom` (required number)
+ MM.mapByCenterZoom = function(parent, provider, location, zoom)
+ {
+ if (typeof provider == 'string')
+ {
+ provider = new MM.TemplatedMapProvider(provider);
+ }
+
+ var layer = new MM.Layer(provider, null),
+ map = new MM.Map(parent, layer, false);
+
+ map.setCenterZoom(location, zoom);
+ map.draw();
+
+ return map;
+ };
+
+ // Instance of a map intended for drawing to a div.
+ //
+ // * `parent` (required DOM element)
+ // Can also be an ID of a DOM element
+ // * `provider` (required MM.MapProvider or URL template)
+ // * `locationA` (required MM.Location)
+ // Location of one map corner
+ // * `locationB` (required MM.Location)
+ // Location of other map corner
+ MM.mapByExtent = function(parent, provider, locationA, locationB)
+ {
+ if (typeof provider == 'string')
+ {
+ provider = new MM.TemplatedMapProvider(provider);
+ }
+
+ var layer = new MM.Layer(provider, null),
+ map = new MM.Map(parent, layer, false);
+
+ map.setExtent([locationA, locationB]);
+ map.draw();
+
+ return map;
+ };

0 comments on commit e28f141

Please sign in to comment.