diff --git a/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_dem.tif b/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_dem.tif new file mode 100644 index 0000000..4375e00 Binary files /dev/null and b/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_dem.tif differ diff --git a/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_num.tif b/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_num.tif new file mode 100644 index 0000000..0713266 Binary files /dev/null and b/myproject/ASTGTM2_N29E079/ASTGTM2_N29E079_num.tif differ diff --git a/myproject/ASTGTM2_N29E079/README.pdf b/myproject/ASTGTM2_N29E079/README.pdf new file mode 100644 index 0000000..d4dc873 Binary files /dev/null and b/myproject/ASTGTM2_N29E079/README.pdf differ diff --git a/myproject/__pycache__/datacube.cpython-36.pyc b/myproject/__pycache__/datacube.cpython-36.pyc new file mode 100644 index 0000000..4b97947 Binary files /dev/null and b/myproject/__pycache__/datacube.cpython-36.pyc differ diff --git a/myproject/db.sqlite3 b/myproject/db.sqlite3 index b7b7f02..cecbe2a 100644 Binary files a/myproject/db.sqlite3 and b/myproject/db.sqlite3 differ diff --git a/myproject/myapp/__pycache__/datacube.cpython-36.pyc b/myproject/myapp/__pycache__/datacube.cpython-36.pyc new file mode 100644 index 0000000..3a466f1 Binary files /dev/null and b/myproject/myapp/__pycache__/datacube.cpython-36.pyc differ diff --git a/myproject/myapp/__pycache__/urls.cpython-36.pyc b/myproject/myapp/__pycache__/urls.cpython-36.pyc index 7a91465..7aecddd 100644 Binary files a/myproject/myapp/__pycache__/urls.cpython-36.pyc and b/myproject/myapp/__pycache__/urls.cpython-36.pyc differ diff --git a/myproject/myapp/__pycache__/views.cpython-36.pyc b/myproject/myapp/__pycache__/views.cpython-36.pyc index fe900e3..c83b1cb 100644 Binary files a/myproject/myapp/__pycache__/views.cpython-36.pyc and b/myproject/myapp/__pycache__/views.cpython-36.pyc differ diff --git a/myproject/myapp/datacube.py b/myproject/myapp/datacube.py index 30f7c89..dd7cc5f 100644 --- a/myproject/myapp/datacube.py +++ b/myproject/myapp/datacube.py @@ -1,109 +1,23 @@ -import gdal -import affine -import numpy as np -import rasterio -import utm - -urls = [ - './19971001/19971001_B1.TIF', - './19971017/19971017_B1.TIF', - './19971102/19971102_B1.TIF', - './19971118/19971118_B1.TIF', - './19981004/19981004_B1.TIF', - './19981020/19981020_B1.TIF', - './19981105/19981105_B1.TIF', - './19981121/19981121_B1.TIF', - './19981207/19981207_B1.TIF', - './19981223/19981223_B1.TIF', - './19991124/19991124_B1.TIF', - './19991226/19991226_B1.TIF', - './20081015/20081015_B1.TIF', - './20081031/20081031_B1.TIF', - './20081116/20081116_B1.TIF', - './20081202/20081202_B1.TIF', - './20081218/20081218_B1.TIF', - './20091102/20091103_B1.TIF', - './20091119/20091119_B1.TIF', - './20091205/20091205_B1.TIF', - './20101021/20101021_B1.TIF', - './20101106/20101106_B1.TIF', - './20101208/20101208_B1.TIF', - './20101224/20101224_B1.TIF', - './20111024/20111024_B1.TIF', - './20111109/20111109_B1.TIF', - './20171016/20171016_B1.TIF', - './20171101/20171101_B1.TIF', - './20171117/20171117_B1.TIF', - './20171203/20171203_B1.TIF', - './20171219/20171219_B1.TIF', - './20181003/20181003_B1.TIF', - './20181010/20181010_B1.TIF', - './20181019/20181019_B1.TIF', - './20181026/20181026_B1.TIF', - './20181104/20181104_B1.TIF', - './20181127/20181127_B1.TIF', - './20181222/20181222_B1.TIF' - ] - -def pixel2coord(col, row, a): - """Returns global coordinates to pixel center using base-0 raster index""" - xp = a[1] * col + a[2] * row + a[1]* 0.5 + a[2] * 0.5 + a[0] - yp = a[4]* col + a[5] * row + a[4]* 0.5 + a[5]* 0.5 + a[3] - return(xp, yp) - - -# latitudes and longitude values of the rectangular region -lat1=29+(23/60)+(29/3600) -lng1=79+(27/60)+(58/3600) -lat2=29+(23/60)+(28/3600) -lng2=79+(27/60)+(9/3600) - -lat3=29+(22/60)+(45/3600) -lng3=79+(27/60)+(9/3600) -lat4=29+(22/60)+(44/3600) -lng4=79+(27/60)+(59/3600) - -[easting1,northing1,zoneNumber1,zoneLetter1] = utm.from_latlon(lat1, lng1) -[easting2,northing2,zoneNumber2,zoneLetter2] = utm.from_latlon(lat2, lng2) -[easting3,northing3,zoneNumber3,zoneLetter3] = utm.from_latlon(lat3, lng3) -[easting4,northing4,zoneNumber4,zoneLetter4] = utm.from_latlon(lat4, lng4) - -e=easting1-easting2 -n=northing2-northing3 - -imgNum = 3 -bandnum = [1,2,3,4,5,6,7] -year= 1 - - - -cube=np.full((1350,1350,20,7),None) - -for x in range(0,imgNum): - - img = gdal.Open(urls[x]) - imgGeoTransf = img.GetGeoTransform() - - row = img.RasterYSize - col = img.RasterXSize - - bandNo = int(urls[x][-5]) - - for i in range(0,row): - for j in range(0,col): - utm=pixel2coord(j,i,imgGeoTransf) - utmX=int(utm[0]) - utmY=int(utm[1]) - if((utmY>easting1 and utmYnorthing1 and utmX + - +
-
-
-
-
-
-
-
-
-
-
- Loading.... Please wait -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+ Loading.... Please wait +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+ Slide Out +
+
diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py
index 9508ccc..ba5e486 100644
--- a/myproject/myapp/urls.py
+++ b/myproject/myapp/urls.py
@@ -11,4 +11,5 @@
      url(r'^register/$',views.register,name='register'),
      url(r'^user_login/$',views.user_login,name='user_login'),
      url(r'^getElevations/',myapp.views.getElevations, name = 'getElevations'),
+     url(r'^loadCube/$',myapp.views.loadCube,name='loadCube'),
 ]
\ No newline at end of file
diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py
index d165f75..abb5839 100644
--- a/myproject/myapp/views.py
+++ b/myproject/myapp/views.py
@@ -5,6 +5,7 @@
 import xarray
 import pandas as pd
 import geopy.distance
+from osgeo import gdal,ogr
 
 from django.http import HttpResponse, JsonResponse
 from django.shortcuts import render,redirect
@@ -100,41 +101,56 @@ def home(request):
 def login(request):
 	return render(request,'login.html')
 
+dc = 0
+measurements = 0
+products = 0
+
+@login_required
+def loadCube(request):
+	global dc
+	global measurements
+	global products
+	dc = datacube.Datacube()
+	products = ['ls7_level1_usgs', 'ls5_level1_usgs']
+	measurements = set(dc.index.products.get_by_name(products[0]).measurements.keys())
+	for prod in products[1:]:
+		measurements.intersection(dc.index.products.get_by_name(products[0]).measurements.keys())
+	res = {}
+	return JsonResponse(res)
+
 @login_required
 def getUTM(request):
-	 res = {}
-	 if request.method == 'POST':
-			latlng = json.loads( request.body.decode('utf-8') )
-			lat = latlng['lat']
-			lng = latlng['lng']
-			dc = datacube.Datacube()
-			query = {
-				'time': ('1995-01-01', '2219-12-12'),
-				'lat': (lat,lat),
-				'lon': (lng,lng)
-			}
-			products = ['ls7_level1_usgs', 'ls5_level1_usgs']
+	global dc
+	global measurements
+	global products
+	res = {}
+	if request.method == 'POST':
+		latlng = json.loads( request.body.decode('utf-8') )
+		lat = latlng['lat']
+		lng = latlng['lng']
+		query = {
+			'time': ('1995-01-01', '2219-12-12'),
+			'lat': (lat,lat),
+			'lon': (lng,lng)
+		}
 
 			# find similarly named measurements
-			measurements = set(dc.index.products.get_by_name(products[0]).measurements.keys())
-			for prod in products[1:]:
-				measurements.intersection(dc.index.products.get_by_name(products[0]).measurements.keys())
 
-			datasets = []
-			for prod in products:
-				ds = dc.load(product=prod,output_crs="EPSG:3577", resolution=(-15, 15), measurements=measurements, **query)
+		datasets = []
+		notEmptyDataset = 0
+		for prod in products:
+			ds = dc.load(product=prod,output_crs="EPSG:3577", resolution=(-15, 15), measurements=measurements, **query)
+			if (not ds.variables):
+				continue
+			else:
+				notEmptyDataset = 1
+				# print(ds)
 				ds['product'] = ('time', np.repeat(prod, ds.time.size))
 				datasets.append(ds)
-
+		if notEmptyDataset:
 			combined = xarray.concat(datasets, dim='time')
 			ds = combined.sortby('time')  # sort along time dim
-
-
-			# print(ds.isnull())
-			# print(ds.dims)
 			[red,green,blue,nir,swir1,swir2,dates] = [ds.red.values,ds.green.values,ds.blue.values,ds.nir.values,ds.swir1.values,ds.swir2.values,ds.red.time.values]
-			# print([red,green,blue,nir])
-
 			res['message'] = 'Data recieved Successfully'
 			res['error'] = 'No Error'
 			res['red'] = red.tolist()
@@ -147,12 +163,13 @@ def getUTM(request):
 			for d in dates:
 					ts = pd.to_datetime(d)
 					res['time'].append(ts.strftime('%Y-%m-%d'))
-			
-	 else:
-			res['error'] = 'Not recieved a post request'
+		else:
+			res['error'] = 'Empty Dataset'
+	else:
+		res['error'] = 'Not recieved a post request'
 	 
 	#  print(res)
-	 return JsonResponse(res)
+	return JsonResponse(res)
 
 @login_required
 def getIndexFormula(request):    	 
@@ -242,9 +259,30 @@ def getElevations(request):
 		reqObj = json.loads( request.body.decode('utf-8') )
 		latLngs = reqObj['latLngArray']
 		hgt_file = 'N29E079.hgt'
+		aster_file = 'ASTGTM2_N29E079\ASTGTM2_N29E079_dem.tif'
 		elevArr = []
-		prevlat = 0
-		prevlng = 0
+		coords1 = (latLngs[0]['lat'],latLngs[0]['lng'])
+		elevationDataFound = 0
+		
+		latLowerBound = int(hgt_file[1:3])
+		latUpperBound = latLowerBound + 1
+
+		lngLowerBound = int(hgt_file[4:7])
+		lngUpperBound = lngLowerBound + 1
+
+		res = {}
+		for i in latLngs:
+			lat = i['lat']
+			lon = i['lng']
+			if (lat < latLowerBound or lat > latUpperBound or lon < lngLowerBound or lon > lngUpperBound):
+				res['error'] = 'Empty Dataset'
+				return JsonResponse(res)
+
+		src_filename = aster_file
+		src_ds=gdal.Open(src_filename) 
+		gt=src_ds.GetGeoTransform()
+		rb=src_ds.GetRasterBand(1)
+
 		with open(hgt_file, 'rb') as hgt_data:
 		# Each data is 16bit signed integer(i2) - big endian(>)
 			elevations = np.fromfile(hgt_data, np.dtype('>i2'), SAMPLES*SAMPLES).reshape((SAMPLES, SAMPLES))
@@ -253,23 +291,27 @@ def getElevations(request):
 				lon = i['lng']
 				lat_row = int(round((lat - int(lat)) * (SAMPLES - 1), 0))
 				lon_row = int(round((lon - int(lon)) * (SAMPLES - 1), 0))
+				px,py=map2pixel(lon,lat,gt)
+				val = float(rb.ReadAsArray(px,py,1,1))
 				ans =  elevations[SAMPLES - 1 - lat_row, lon_row].astype(int)
 
-				coords1 = (prevlat,prevlng)
 				coords2 = (lat,lon)
-				dist = 0
-				if(prevlat == 0 and prevlng == 0):
-					print('huh initial one')
-					dist = 0
-				else:
-					dist = geopy.distance.vincenty(coords1,coords2).km
-				elevArr.append({'elevation':int(ans),'distance':dist})
+				dist = geopy.distance.vincenty(coords1,coords2).km
+				elevArr.append({'elevation':{'srtm':float(ans),'aster':val},'distance':dist})
 				print(ans)
 				print(dist)
-				prevlat = i['lat']
-				prevlng = i['lng']
-			res = {}
 			res['error'] = 'no error'
 			res['elevationProfile'] = elevArr
-			return JsonResponse(res)
 
+		return JsonResponse(res)
+
+def map2pixel(mx,my,gt):
+	"""
+	Convert from map to pixel coordinates.
+	Only works for geotransforms with no rotation.
+	"""
+
+	px = int((mx - gt[0]) / gt[1]) #x pixel
+	py = int((my - gt[3]) / gt[5]) #y pixel
+
+	return px,py
\ No newline at end of file
diff --git a/myproject/static/css/calc.css b/myproject/static/css/calc.css
index b22099b..2eaf57b 100644
--- a/myproject/static/css/calc.css
+++ b/myproject/static/css/calc.css
@@ -1,11 +1,11 @@
 * {
-  padding: 0;
-  margin: 5px;
+  /* padding: 0; */
+  /* margin: 5px; */
   text-align: center;
 }
-body {
+/* body {
   background-color:black;
-}
+} */
 .calculator {
   width: 350px;
   height: 320px;
diff --git a/myproject/static/css/style.css b/myproject/static/css/style.css
index 74e3f3f..717c2bd 100644
--- a/myproject/static/css/style.css
+++ b/myproject/static/css/style.css
@@ -15,22 +15,44 @@ body{
     opacity: .5;
 }
 #tester{
-    width: 45vw;
-    height: 60vh;
+    width: 100vw;
+    height: 55vh;
     z-index: 10;
     position: absolute;
     top: 30vh;
-    left: 50vw;
+    left: 0vw;
+    transition: all 1s ease;
+    /* display: 'none'; */
 }
 #map{
-    width: 45vw;
-    height: 60vh;
+    width: 100vw;
+    height: 85vh;
     z-index: 10;
     position: absolute;
-    top: 30vh;
-    left: 2vw;
-    outline: none;
+    top: 6vh;
+    left: 0;
+    transition: all .75s ease;
+}
+    
+.svg-container{
+    transition: all .75s ease;
+}
+
+#mapNGraphContainer{
+    position: absolute;
+    top: 15vh;
+    left: 0;
 }
+
+#mapNGraphContainer>a{
+        text-decoration: none;
+        background: #eee;
+        padding: .5em;
+        margin-bottom: 1em;
+        display: inline-block;
+}
+
+
 #indexDiv{
     top: 0;
     right: 5vw;
@@ -128,4 +150,11 @@ body{
      background-image: url( 'https://dh3vbjnk0bnfa.cloudfront.net/static/centralauth/images/btn-login.png' );
      background-position: 65px 5px;
      text-indent: 15px;  
-   }
\ No newline at end of file
+   }
+
+.show{
+    display: block !important;
+}
+.hide{
+    display: none !important;
+}
\ No newline at end of file
diff --git a/myproject/static/js/index.js b/myproject/static/js/index.js
index 2abb143..e69de29 100644
--- a/myproject/static/js/index.js
+++ b/myproject/static/js/index.js
@@ -1,2364 +0,0 @@
-
-
-
-
-
-
-
-
-  
-    
-  
-  
-  
-  
-  
-  
-  
-
-
-
-  
-  
-    
-    
-    
-    
-    
-
-  
-  
-  leaflet-bing-layer/index.js at gh-pages · digidem/leaflet-bing-layer
-    
-    
-  
-  
-
-    
-    
-
-  
-  
-  
-  
-  
-
-
-  
-
-  
-
-      
-    
-    
-
-  
-
-
-
-
-    
-
-  
-
-
-
-
-
-  
-
-      
-    
-
-      
-    
-
-    
-
-  
-
-  
-  
-
-      
-
-  
-
-  
-
-
-    
-
-
-  
-
-  
-
-  
-  
-
-
-
-
-  
-
-
-
-  
-
-  
-
-  
-    
-
-  
- Skip to content -
- - - - - - - - - - -
- -
- - -
- -
- - - -
-
-
- - - - - - - - - - - - -
-
- -
    - - - -
  • - - - - -
  • - -
  • - -
    - -
    - - - Watch - - -
    - Notifications -
    -
    - - - - - - - -
    -
    -
    - -
    -
  • - -
  • -
    -
    - - -
    -
    - - -
    - -
  • - -
  • -
    - - Fork - -
    - -

    Fork leaflet-bing-layer

    -
    -
    - -
    -

    If this dialog fails to load, you can visit the fork page directly.

    -
    -
    -
    -
    - - -
  • -
- -

- - /leaflet-bing-layer - - -

- -
- - - - - - -
-
-
- - - - - - - Permalink - - - - -
- - -
- - Branch: - gh-pages - - - - - - - -
- -
- - Find file - - - Copy path - -
-
- - -
- - Find file - - - Copy path - -
-
- - - - -
-
- - @gmaclennan - gmaclennan - - Merge pull request #27 from aparajita/patch-2 - - - - 1d5a153 - Mar 14, 2018 - -
- -
-
- - 3 contributors - - -
- -

- Users who have contributed to this file -

-
- -
-
- - - @gmaclennan - - @ChrisGrohHS - - @aparajita - - - -
-
- - - - - -
- -
- -
- 277 lines (250 sloc) - - 9.01 KB -
- -
- -
- Raw - Blame - History -
- - -
- - - - -
- -
-
- -
-
-
- - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var L = require('leaflet')
var fetchJsonp = require('fetch-jsonp')
var bboxIntersect = require('bbox-intersect')
-
/**
* Converts tile xyz coordinates to Quadkey
* @param {Number} x
* @param {Number} y
* @param {Number} z
* @return {Number} Quadkey
*/
function toQuadKey (x, y, z) {
var index = ''
for (var i = z; i > 0; i--) {
var b = 0
var mask = 1 << (i - 1)
if ((x & mask) !== 0) b++
if ((y & mask) !== 0) b += 2
index += b.toString()
}
return index
}
-
/**
* Converts Leaflet BBoxString to Bing BBox
* @param {String} bboxString 'southwest_lng,southwest_lat,northeast_lng,northeast_lat'
* @return {Array} [south_lat, west_lng, north_lat, east_lng]
*/
function toBingBBox (bboxString) {
var bbox = bboxString.split(',')
return [bbox[1], bbox[0], bbox[3], bbox[2]]
}
-
var VALID_IMAGERY_SETS = [
'Aerial',
'AerialWithLabels',
'AerialWithLabelsOnDemand',
'Road',
'RoadOnDemand',
'CanvasLight',
'CanvasDark',
'CanvasGray',
'OrdnanceSurvey'
]
-
var DYNAMIC_IMAGERY_SETS = [
'AerialWithLabelsOnDemand',
'RoadOnDemand'
]
-
/**
* Create a new Bing Maps layer.
* @param {string|object} options Either a [Bing Maps Key](https://msdn.microsoft.com/en-us/library/ff428642.aspx) or an options object
* @param {string} options.BingMapsKey A valid Bing Maps Key (required)
* @param {string} [options.imagerySet=Aerial] Type of imagery, see https://msdn.microsoft.com/en-us/library/ff701716.aspx
* @param {string} [options.culture='en-US'] Language for labels, see https://msdn.microsoft.com/en-us/library/hh441729.aspx
* @return {L.TileLayer} A Leaflet TileLayer to add to your map
*
* Create a basic map
* @example
* var map = L.map('map').setView([51.505, -0.09], 13)
* L.TileLayer.Bing(MyBingMapsKey).addTo(map)
*/
L.TileLayer.Bing = L.TileLayer.extend({
options: {
bingMapsKey: null, // Required
imagerySet: 'Aerial',
culture: 'en-US',
minZoom: 1,
minNativeZoom: 1,
maxNativeZoom: 19
},
-
statics: {
METADATA_URL: 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/{imagerySet}?key={bingMapsKey}&include=ImageryProviders&uriScheme=https&c={culture}',
POINT_METADATA_URL: 'https://dev.virtualearth.net/REST/v1/Imagery/Metadata/{imagerySet}/{lat},{lng}?zl={z}&key={bingMapsKey}&uriScheme=https&c={culture}'
},
-
initialize: function (options) {
if (typeof options === 'string') {
options = { bingMapsKey: options }
}
if (options && options.BingMapsKey) {
options.bingMapsKey = options.BingMapsKey
console.warn('use options.bingMapsKey instead of options.BingMapsKey')
}
if (!options || !options.bingMapsKey) {
throw new Error('Must supply options.BingMapsKey')
}
options = L.setOptions(this, options)
if (VALID_IMAGERY_SETS.indexOf(options.imagerySet) < 0) {
throw new Error("'" + options.imagerySet + "' is an invalid imagerySet, see https://github.com/digidem/leaflet-bing-layer#parameters")
}
if (options && options.style && DYNAMIC_IMAGERY_SETS.indexOf(options.imagerySet) < 0) {
console.warn('Dynamic styles will only work with these imagerySet choices: ' + DYNAMIC_IMAGERY_SETS.join(', '))
}
-
var metaDataUrl = L.Util.template(L.TileLayer.Bing.METADATA_URL, {
bingMapsKey: this.options.bingMapsKey,
imagerySet: this.options.imagerySet,
culture: this.options.culture
})
-
this._imageryProviders = []
this._attributions = []
-
// Keep a reference to the promise so we can use it later
this._fetch = fetchJsonp(metaDataUrl, {jsonpCallback: 'jsonp'})
.then(function (response) {
return response.json()
})
.then(this._metaDataOnLoad.bind(this))
.catch(console.error.bind(console))
-
// for https://github.com/Leaflet/Leaflet/issues/137
if (!L.Browser.android) {
this.on('tileunload', this._onTileRemove)
}
},
-
createTile: function (coords, done) {
var tile = document.createElement('img')
-
L.DomEvent.on(tile, 'load', L.bind(this._tileOnLoad, this, done, tile))
L.DomEvent.on(tile, 'error', L.bind(this._tileOnError, this, done, tile))
-
if (this.options.crossOrigin) {
tile.crossOrigin = ''
}
-
/*
Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons
http://www.w3.org/TR/WCAG20-TECHS/H67
*/
tile.alt = ''
-
// Don't create closure if we don't have to
if (this._url) {
tile.src = this.getTileUrl(coords)
} else {
this._fetch.then(function () {
tile.src = this.getTileUrl(coords)
}.bind(this)).catch(function (e) {
console.error(e)
done(e)
})
}
-
return tile
},
-
getTileUrl: function (coords) {
var quadkey = toQuadKey(coords.x, coords.y, coords.z)
var url = L.Util.template(this._url, {
quadkey: quadkey,
subdomain: this._getSubdomain(coords),
culture: this.options.culture
})
if (typeof this.options.style === 'string') {
url += '&st=' + this.options.style
}
return url
},
-
// Update the attribution control every time the map is moved
onAdd: function (map) {
map.on('moveend', this._updateAttribution, this)
L.TileLayer.prototype.onAdd.call(this, map)
this._attributions.forEach(function (attribution) {
map.attributionControl.addAttribution(attribution)
})
},
-
// Clean up events and remove attributions from attribution control
onRemove: function (map) {
map.off('moveend', this._updateAttribution, this)
this._attributions.forEach(function (attribution) {
map.attributionControl.removeAttribution(attribution)
})
L.TileLayer.prototype.onRemove.call(this, map)
},
-
/**
* Get the [Bing Imagery metadata](https://msdn.microsoft.com/en-us/library/ff701712.aspx)
* for a specific [`LatLng`](http://leafletjs.com/reference.html#latlng)
* and zoom level. If either `latlng` or `zoom` is omitted and the layer is attached
* to a map, the map center and current map zoom are used.
* @param {L.LatLng} latlng
* @param {Number} zoom
* @return {Promise} Resolves to the JSON metadata
*/
getMetaData: function (latlng, zoom) {
if (!this._map && (!latlng || !zoom)) {
return Promise.reject(new Error('If layer is not attached to map, you must provide LatLng and zoom'))
}
latlng = latlng || this._map.getCenter()
zoom = zoom || this._map.getZoom()
var PointMetaDataUrl = L.Util.template(L.TileLayer.Bing.POINT_METADATA_URL, {
bingMapsKey: this.options.bingMapsKey,
imagerySet: this.options.imagerySet,
z: zoom,
lat: latlng.lat,
lng: latlng.lng
})
return fetchJsonp(PointMetaDataUrl, {jsonpCallback: 'jsonp'})
.then(function (response) {
return response.json()
})
.catch(console.error.bind(console))
},
-
_metaDataOnLoad: function (metaData) {
if (metaData.statusCode !== 200) {
throw new Error('Bing Imagery Metadata error: \n' + JSON.stringify(metaData, null, ' '))
}
var resource = metaData.resourceSets[0].resources[0]
this._url = resource.imageUrl
this._imageryProviders = resource.imageryProviders || []
this.options.subdomains = resource.imageUrlSubdomains
this._updateAttribution()
return Promise.resolve()
},
-
/**
* Update the attribution control of the map with the provider attributions
* within the current map bounds
*/
_updateAttribution: function () {
var map = this._map
if (!map || !map.attributionControl) return
var zoom = map.getZoom()
var bbox = toBingBBox(map.getBounds().toBBoxString())
this._fetch.then(function () {
var newAttributions = this._getAttributions(bbox, zoom)
var prevAttributions = this._attributions
// Add any new provider attributions in the current area to the attribution control
newAttributions.forEach(function (attr) {
if (prevAttributions.indexOf(attr) > -1) return
map.attributionControl.addAttribution(attr)
})
// Remove any attributions that are no longer in the current area from the attribution control
prevAttributions.filter(function (attr) {
if (newAttributions.indexOf(attr) > -1) return
map.attributionControl.removeAttribution(attr)
})
this._attributions = newAttributions
}.bind(this))
},
-
/**
* Returns an array of attributions for given bbox and zoom
* @private
* @param {Array} bbox [west, south, east, north]
* @param {Number} zoom
* @return {Array} Array of attribution strings for each provider
*/
_getAttributions: function (bbox, zoom) {
return this._imageryProviders.reduce(function (attributions, provider) {
for (var i = 0; i < provider.coverageAreas.length; i++) {
if (bboxIntersect(bbox, provider.coverageAreas[i].bbox) &&
zoom >= provider.coverageAreas[i].zoomMin &&
zoom <= provider.coverageAreas[i].zoomMax) {
attributions.push(provider.attribution)
return attributions
}
}
return attributions
}, [])
}
})
-
L.tileLayer.bing = function (options) {
return new L.TileLayer.Bing(options)
}
-
module.exports = L.TileLayer.Bing
- - - -
- -
- - - -
- - -
- - -
-
- - - - - -
- -
- -
-
- - -
- - - - - - -
- - - You can’t perform that action at this time. -
- - - - - - - - - - - - - - -
- - - - diff --git a/myproject/static/js/script.js b/myproject/static/js/script.js index 03f4dd6..3e61600 100644 --- a/myproject/static/js/script.js +++ b/myproject/static/js/script.js @@ -217,18 +217,29 @@ map.on("pm:drawend", (e) => { console.log(currentShapeLatLngs); if(document.getElementById("selectIndex").value === "terrainProfile"){ document.getElementById("loader").style.display="block"; - sendRequest("/myapp/getElevations/","POST",{"latLngArray":currentShapeLatLngs}).then((e)=>{ - distElevationArray = JSON.parse(e).elevationProfile; - yArr = []; + sendRequest("/myapp/getElevations/","POST",{"latLngArray":currentShapeLatLngs}).then((res)=>{ + res = JSON.parse(res); + if(res['error'] == 'Empty Dataset'){ + // console.log('oyeeeeeeeeee'); + document.getElementById("loader").style.display="none"; + swal("Error", "Data not available for these ranges! Try some other region..", "error"); + return; + } + distElevationArray = res.elevationProfile; + y1Arr = []; + y2Arr = []; xArr = []; for(let i of distElevationArray){ console.log(i); xArr.push(i.distance); - yArr.push(i.elevation); + y1Arr.push(i.elevation.srtm); + y2Arr.push(i.elevation.aster) } console.log(xArr); - console.log(yArr); - plotGraph('Elevation Profile','Distance (in Kms)','Height(in meters)',xArr,yArr,''); + console.log(y1Arr); + console.log(y2Arr); + plotGraph('Elevation Profile','Distance (in Kms)','Height(in meters)',xArr,y1Arr,'srtm',false); + plotGraph('Elevation Profile','Distance (in Kms)','Height(in meters)',xArr,y2Arr,'aster',true); // console.log(distElevationArray); document.getElementById("loader").style.display="none"; swal("Success", "Elevation Profile is drawn... Click Slide Out to see the graph", "success");