climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1501561 - /incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js
Date Tue, 09 Jul 2013 21:21:04 GMT
Author: joyce
Date: Tue Jul  9 21:21:04 2013
New Revision: 1501561

URL: http://svn.apache.org/r1501561
Log:
CLIMATE-184 progress - Add $observe on template id

- Any attribute that contains {{}} interpolation will be set to null in
  the attrs parameter during the link function since the first $digest
  since the compilation has yet to run to evaluate it! We can't run a
  $digest in the middle of compilation, so using an $observe (or $watch)
  is the best way to get the values. Before we were basically just lucky
  that it wasn't breaking when we ran it.

Modified:
    incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js

Modified: incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js?rev=1501561&r1=1501560&r2=1501561&view=diff
==============================================================================
--- incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js (original)
+++ incubator/climate/trunk/rcmet/src/main/ui/app/js/directives/PreviewMap.js Tue Jul  9 21:21:04
2013
@@ -4,39 +4,47 @@ App.Directives.directive('previewMap', f
 		replace: true,
 		scope: {dataset: '=previewMap'},
 		template: '<div id="{{dataset.name}}" class="preview-map"></div>',
+		replace: true,
 		link: function(scope, element, attrs) {
-			var map = L.map(attrs.id, {
-				//center: [40, 0],
-				zoom: 0,
-				scrollWheelZoom: false,
-				zoomControl: false,
-				attributionControl: false,
-			});
 
-			//create a CloudMade tile layer and add it to the map
-			L.tileLayer('http://{s}.tile.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/997/256/{z}/{x}/{y}.png',
{}).addTo(map);
+			// Any attribute that contains {{}} interpolation will be set to null in the attrs
+			// parameter during the link function since the first $digest since the compilation
+			// has yet to run to evaluate it! We can't run a $digest in the middle of compilation,
+			// so using an $observe (or $watch) is the best way to get the values.
+			attrs.$observe('id', function(newId) {
+				//var map = L.map(scope.dataset.name, {
+				var map = L.map(attrs.id, {
+					zoom: 0,
+					scrollWheelZoom: false,
+					zoomControl: false,
+					attributionControl: false,
+				});
+
+				//create a CloudMade tile layer and add it to the map
+				L.tileLayer('http://{s}.tile.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/997/256/{z}/{x}/{y}.png',
{}).addTo(map);
+
+				// Zoom the map to the dataset bound regions (or at least try our best to do so)
+				var datasetBounds = [[scope.dataset.latlonVals.latMax, scope.dataset.latlonVals.lonMin],

+									 [scope.dataset.latlonVals.latMin, scope.dataset.latlonVals.lonMax]];
+				map.fitBounds(datasetBounds, {});
+
+				// Draw a colored overlay on the region of the map
+				var maplatlon = scope.dataset.latlonVals;
+				var bounds = [[maplatlon.latMax, maplatlon.lonMin], [maplatlon.latMin, maplatlon.lonMax]];
+
+				var polygon = L.rectangle(bounds,{
+					stroke: false,
+					fillColor: $rootScope.fillColors[i],
+					fillOpacity: 0.6
+				});
+
+				// Add layer to Group
+				var rectangleGroup = L.layerGroup();
+				rectangleGroup.addLayer(polygon);
 
-			// Zoom the map to the dataset bound regions (or at least try our best to do so)
-			var datasetBounds = [[scope.dataset.latlonVals.latMax, scope.dataset.latlonVals.lonMin],

-								 [scope.dataset.latlonVals.latMin, scope.dataset.latlonVals.lonMax]];
-			map.fitBounds(datasetBounds, {});
-
-			// Draw a colored overlay on the region of the map
-			var maplatlon = scope.dataset.latlonVals;
-			var bounds = [[maplatlon.latMax, maplatlon.lonMin], [maplatlon.latMin, maplatlon.lonMax]];
-
-			var polygon = L.rectangle(bounds,{
-				stroke: false,
-				fillColor: $rootScope.fillColors[i],
-				fillOpacity: 0.6
+				// Add the overlay to the map
+				rectangleGroup.addTo(map);
 			});
-
-			// Add layer to Group
-			var rectangleGroup = L.layerGroup();
-			rectangleGroup.addLayer(polygon);
-
-			// Add the overlay to the map
-			rectangleGroup.addTo(map);
 		}
 	};
 });



Mime
View raw message