Browse files

add central map control, add control to map, add image for center button

  • Loading branch information...
1 parent 40955dc commit 759b6cbbfbb7c3cd1b2b7dd5b35298d71084b18f @mick mick committed Jul 9, 2012
View
6 app/config.js
@@ -26,7 +26,8 @@ require.config({
mapcontroller: "../assets/js/libs/mapcontroller",
mapmarkerrenderer: "../assets/js/libs/mapcontroller.markerrenderer",
mapcanvasrenderer: "../assets/js/libs/mapcontroller.canvasrenderer",
- dailybriefingcontroller: "../assets/js/libs/dailybriefingcontroller"
+ dailybriefingcontroller: "../assets/js/libs/dailybriefingcontroller",
+ controlcenter: "../assets/js/libs/control.center"
},
shim: {
@@ -53,7 +54,8 @@ require.config({
"filterbarcontroller",
"threeoneoneapi",
"headerbarcontroller",
- "multiselector"],
+ "multiselector",
+ "controlcenter"],
exports: "DailyBriefingController"
},
datetools: {
View
3 app/main.js
@@ -8,7 +8,6 @@ require([
"configbaltimore",
"configbloomington",
"configboston",
-
// modules
"modules/dashboard"
],
@@ -44,9 +43,11 @@ function(app, $, Backbone, Config, ConfigBloomington, ConfigBoston, Dashboard) {
setCityConfig: function(city) {
if (city === 'boston') {
dashboardView.config = ConfigBoston;
+ Config = ConfigBoston;
}
else if (city === 'bloomington') {
dashboardView.config = ConfigBloomington;
+ Config = ConfigBloomington;
} else {
dashboardView.config = Config;
}
View
16 assets/css/map.css
@@ -9,7 +9,7 @@
.leaflet-top {
/* account for the filter bar */
top: 60px;
- left: 5px;
+ left: 20px;
}
.leaflet-popup-close-button {
@@ -40,3 +40,17 @@
font-style:italic;
color:#777777;
}
+
+div.leaflet-control-center{
+ height:46px;
+ width:46px;
+}
+a.leaflet-control-center{
+ height:46px;
+ width:46px;
+ display:block;
+ position:relative;
+ left:-9px;
+ top:5px;
+ background-image: url(/assets/img/center.png);
+}
View
BIN assets/img/center.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
38 assets/js/libs/Control.Center.js
@@ -0,0 +1,38 @@
+L.Control.Center = L.Class.extend({
+ onAdd: function (map) {
+ this._map = map;
+ this._container = L.DomUtil.create('div', 'leaflet-control-center');
+
+ this._centerButton = this._createButton(
+ 'Center', 'leaflet-control-center', this._resetMap, this._map);
+
+ this._container.appendChild(this._centerButton);
+ },
+
+ getContainer: function () {
+ return this._container;
+ },
+
+ getPosition: function () {
+ return L.Control.Position.TOP_LEFT;
+ },
+ _resetMap: function(){
+ this.setView(new L.LatLng(Config.center[0], Config.center[1]),
+ (Config.zoom || 13));
+ },
+
+ _createButton: function (title, className, fn, context) {
+ var link = document.createElement('a');
+ link.href = '#';
+ link.title = title;
+ link.className = className;
+
+ if (!L.Browser.touch) {
+ L.DomEvent.disableClickPropagation(link);
+ }
+ L.DomEvent.addListener(link, 'click', L.DomEvent.preventDefault);
+ L.DomEvent.addListener(link, 'click', fn, context);
+
+ return link;
+ }
+});
View
5 assets/js/libs/mapcontroller.js
@@ -49,12 +49,15 @@ MapController.prototype = {
constructor: MapController,
_initializeMap: function () {
- this.map = new L.Map("map");
+ this.map = new L.Map("map", {zoomControl:false});
var cloudmade = new L.TileLayer("http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.jpg", {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
maxZoom: 18
});
+
this.map.addLayer(cloudmade);
+ this.map.addControl(new L.Control.Center());
+ this.map.addControl(new L.Control.Zoom());
this._initializeMapRenderer();
},

0 comments on commit 759b6cb

Please sign in to comment.