diff --git a/.gitignore b/.gitignore index f1a9e6853f959ad648f5e0c3db59a96d659fa651..786c7e92d6706e20537119c603f65133c27b4aa8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ _scratch crap eb-virt +accounts blocmaps.zip processed_tile.json *.pyc diff --git a/README.md b/README.md index 6911dfba941f91eeb13188c6888acb0344055cf9..159dce0268dab8b301d243206bcd5cafe0ecc634 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ We recommend setting up [virtualenv](https://virtualenv.pypa.io) on your machine ## Running Locally - python manage.py runserver + - Note: Running locally will not insert google analytics. - rest calls: http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=LandUse=5%20AND%20Borough=%27SI%27&outFields=*&outSR=4326&f=geojson diff --git a/ebdjango/custom_processors.py b/ebdjango/custom_processors.py new file mode 100644 index 0000000000000000000000000000000000000000..96c0ee1fae586bc6f7cc459f206949c877b2ce49 --- /dev/null +++ b/ebdjango/custom_processors.py @@ -0,0 +1,13 @@ +from django.conf import settings + +def google_analytics(request): + ga_show = getattr(settings, 'GOOGLE_ANALYTICS', False) + ga_prop_id = getattr(settings, 'GOOGLE_ANALYTICS_KEY', False) + ga_domain = getattr(settings, 'GOOGLE_ANALYTICS_DOMAIN', False) + if ga_prop_id and ga_domain: + return { + 'GOOGLE_ANALYTICS': ga_show, + 'GOOGLE_ANALYTICS_KEY': ga_prop_id, + 'GOOGLE_ANALYTICS_DOMAIN': ga_domain, + } + return {} \ No newline at end of file diff --git a/ebdjango/settings.py b/ebdjango/settings.py index 1fa97795ce00e3c98373a02320ef12f3f8aeb47f..7d9d45cb5f73ae32d467468402b9fe0b57824243 100644 --- a/ebdjango/settings.py +++ b/ebdjango/settings.py @@ -25,12 +25,15 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = os.environ['SECRET_KEY'] # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False +GOOGLE_ANALYTICS = True if os.environ['ENVIRONMENT'] == 'local': DEBUG = True + GOOGLE_ANALYTICS = False -ALLOWED_HOSTS = [] + +ALLOWED_HOSTS = ['*'] # Application definition @@ -67,6 +70,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'ebdjango.custom_processors.google_analytics', ], }, }, @@ -118,7 +122,11 @@ USE_TZ = True STATIC_ROOT = '' STATIC_URL = '/static/' -STATICFILES_DIRS = ( os.path.join('static'), ) +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ] + +# Google Analytics +GOOGLE_ANALYTICS_KEY = 'UA-67611405-2' +GOOGLE_ANALYTICS_DOMAIN = 'auto' # AWS # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html diff --git a/ebdjango/urls.py b/ebdjango/urls.py index ffe5376da57cfe39de68c702882e62f20f0ba924..4781e2349633810962b44f166b42759f49f36479 100644 --- a/ebdjango/urls.py +++ b/ebdjango/urls.py @@ -19,7 +19,8 @@ from maps import views urlpatterns = [ url(r'^$', views.index, name='index'), - url(r'^tile/15/(?P[0-9]+)/(?P[0-9]+)/$', views.tile, name='tile'), - url(r'^nyc/', include('maps.urls')), + url(r'^(?P[\w-]+)/$', views.index, name='index'), + url(r'^(?P[\w-]+)/building_detail/', views.building_detail, name='building_detail'), + url(r'^tile/15/(?P[0-9]+)/(?P[0-9]+)/$', views.tile, name='tile') # url(r'^admin/', admin.site.urls), ] diff --git a/maps/urls.py b/maps/urls.py deleted file mode 100644 index 68c82f27b1b963adedb948ccc591c7d702f82920..0000000000000000000000000000000000000000 --- a/maps/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.conf.urls import url -from . import views - -urlpatterns = [ - url(r'^$', views.index, name='index'), - url(r'^building_detail/', views.building_detail, name='building_detail') -] \ No newline at end of file diff --git a/maps/views.py b/maps/views.py index b2f2ce680c6c064cf8180abf77e30f129d5478c4..d4360f5d2fa38d5a2fd39e08b9cfcaea735fd97f 100644 --- a/maps/views.py +++ b/maps/views.py @@ -1,5 +1,5 @@ from django.shortcuts import render -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.template import loader from django.conf import settings from django.core.files.storage import default_storage @@ -10,8 +10,11 @@ import pymongo from pymongo import MongoClient from django.http import JsonResponse -def arcgis(building_id): - url = 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=1=1&objectIds=%s&outFields=*&outSR=4326&f=geojson' % building_id +def arcgis(building_id, city): + if city == 'roc': + url = 'http://maps.cityofrochester.gov/arcgis/rest/services/App_PropertyInformation/ROC_Parcel_Query_SDE/MapServer/0/query??where=1=1&objectIds=%s&outFields=*&f=pjson' % building_id + else: + url = 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/MAPPLUTO/FeatureServer/0/query?where=1=1&objectIds=%s&outFields=*&outSR=4326&f=geojson' % building_id response = urlopen(url) reader = codecs.getreader("utf-8") return json.load(reader(response)) @@ -20,11 +23,20 @@ def openMongo(): client = MongoClient(settings.MONGO_DB_URI) return client['blocmaps'] -def index(request): - template = loader.get_template('nyc.html') - context = { - 'City': 'NYC', - } +def index(request, city = 'nyc'): + if city == 'nyc': + template = loader.get_template('nyc.html') + context = { + 'City': 'NYC', + } + elif city == 'roc': + template = loader.get_template('rochester.html') + context = { + 'City': 'Rochester', + } + else: + return HttpResponseRedirect('/nyc/') + return HttpResponse(template.render(context, request)) def tile(request, tile_x, tile_y): @@ -36,20 +48,39 @@ def tile(request, tile_x, tile_y): else: return HttpResponse('') -def building_detail(request): +def building_detail(request, city = 'nyc'): bld_id = request.POST['id'] db = openMongo() - cursor = db.nyc.find({"_id": int(bld_id)}) - data = arcgis(bld_id) - for document in cursor: - if 'prediction' in document['properties']: - data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] - - if 'ped_energy' in document['properties']: - data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] - - if 'ecm' in document['properties']: - data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] - - return JsonResponse(data['features'][0]['properties']) + data = arcgis(bld_id, city) + + if city == 'roc': + cursor = db.roc.find({"_id": int(bld_id)}) + for document in cursor: + data['features'][0]['attributes'][u'sqft'] = document['properties']['sqft'] + data['features'][0]['attributes'][u'age'] = document['properties']['age'] + data['features'][0]['attributes'][u'NumFloors'] = document['properties']['NumFloors'] + if 'prediction' in document['properties']: + data['features'][0]['attributes'][u'prediction'] = document['properties']['prediction'] + + if 'ped_energy' in document['properties']: + data['features'][0]['attributes'][u'ped_energy'] = document['properties']['ped_energy'] + + if 'ecm' in document['properties']: + data['features'][0]['attributes'][u'ecm'] = document['properties']['ecm'] + + return JsonResponse(data['features'][0]['attributes']) + + else: + cursor = db.nyc.find({"_id": int(bld_id)}) + for document in cursor: + if 'prediction' in document['properties']: + data['features'][0]['properties'][u'prediction'] = document['properties']['prediction'] + + if 'ped_energy' in document['properties']: + data['features'][0]['properties'][u'ped_energy'] = document['properties']['ped_energy'] + + if 'ecm' in document['properties']: + data['features'][0]['properties'][u'ecm'] = document['properties']['ecm'] + + return JsonResponse(data['features'][0]['properties']) diff --git a/static/src/blocmaps.js b/static/src/blocmaps.js index adebbb1c91e58a25b59338030a92bfd6f3404b67..1544a3353976567fd7e2b58a72beb20970f5d0fb 100644 --- a/static/src/blocmaps.js +++ b/static/src/blocmaps.js @@ -69,6 +69,31 @@ function startOSMB(position, bounds) { $('.close_details').on('click', function(e){ closeDetails(); }); + + var controlButtons = document.querySelectorAll('.control button'); + + for (var i = 0, il = controlButtons.length; i < il; i++) { + controlButtons[i].addEventListener('click', function(e) { + var button = this, + parentClassList = button.parentNode.classList, + direction = button.classList.contains('inc') ? 1 : -1, + increment, + property; + + + if (parentClassList.contains('rotation')) { + property = 'Rotation'; + increment = direction*10; + } + if (parentClassList.contains('zoom')) { + property = 'Zoom'; + increment = direction*1; + } + if (property) { + osmb['set'+ property](osmb['get'+ property]()+increment); + } + }); + } } function closeDetails(){ @@ -113,6 +138,8 @@ function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }; + + /* * ## Key codes for object positioning ## * Cursor keys: move diff --git a/static/styles/RotateLeft.png b/static/styles/RotateLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..268e0aacf43fe41eaa2542a9341bffb91db4bc08 Binary files /dev/null and b/static/styles/RotateLeft.png differ diff --git a/static/styles/RotateRight.png b/static/styles/RotateRight.png new file mode 100644 index 0000000000000000000000000000000000000000..81d7a51f71003d0f72837312217392243de05cb9 Binary files /dev/null and b/static/styles/RotateRight.png differ diff --git a/static/styles/ZoomIn.png b/static/styles/ZoomIn.png new file mode 100644 index 0000000000000000000000000000000000000000..f6b9f6b9e83cdaf1416d1ffc97bd4e8edfc5f7fc Binary files /dev/null and b/static/styles/ZoomIn.png differ diff --git a/static/styles/ZoomOut.png b/static/styles/ZoomOut.png new file mode 100644 index 0000000000000000000000000000000000000000..beae87e1b3e16809b7e13e7dfb4dfc38d75adf28 Binary files /dev/null and b/static/styles/ZoomOut.png differ diff --git a/static/styles/blocmaps.css b/static/styles/blocmaps.css index aeeee72b7626ed7e0c720ad9ab213ff99fe548d2..a4d442f8ac1ac76a26b71890a150ee8b92a0f430 100644 --- a/static/styles/blocmaps.css +++ b/static/styles/blocmaps.css @@ -4,7 +4,9 @@ url("MuseoSansRounded-500.otf") format('opentype'); font-weight: normal; } - +* { + outline: none; +} html, body { margin: 0; padding: 0; @@ -35,7 +37,6 @@ header > div{ width: 1140px; margin: auto; position: relative; - overflow: hidden; } #logo{ width:200px; @@ -71,7 +72,7 @@ header > div{ margin-left: 0; } .top-menu a { - color: #585858; + color: #2f9c79; display: block; font-size: 16px; } @@ -82,6 +83,7 @@ header > div{ .selectType{ float: left; padding: 0 30px; + margin-top: -20px; } .selectType label{ display: block; @@ -90,6 +92,8 @@ header > div{ } #selectType{ font-size: 16px; + padding: 8px; + border-radius: 4px; } #map { width: 100%; @@ -298,4 +302,74 @@ header > div{ } #detail_list{ display: none; +} + +.map_controls{ + position: absolute; + width: 70px; + height: 136px; + bottom: 40px; + left: 40px; +} +.map_controls button{ + background: none; + border: none; + float: left; + cursor: pointer; +} +.zoom{ + width: 40px; + margin: 0 auto; + overflow: hidden; +} +.zoom button{ + width: 40px; + height: 30px; +} +.zoom .inc{ + background: url('ZoomIn.png'); +} +.zoom .dec{ + background: url('ZoomOut.png'); +} +.rotation{ + width: 70px; + height: 76px; +} +.rotation button{ + width: 35px; + height: 76px; +} +.rotation .inc{ + background: url('RotateLeft.png'); +} +.rotation .dec{ + background: url('RotateRight.png'); +} + +/* Media Querys */ +@media screen and (max-width:479px){ + #main-menu, + .selectType, + .map_controls, + .map_legend{ + display: none; + } + header{ + height: 75px; + } + .wrapper{ + width: 320px; + } + #logo{ + height: auto; + } + #map, + #details{ + top: 75px; + } + #details{ + width: 100%; + right: -100%; + } } \ No newline at end of file diff --git a/templates/nyc.html b/templates/nyc.html index 48bba436d2f9ba50e9e25a450a2b93768d7754c8..0d5e14501fe204deb6b6122f7303569deff777a4 100644 --- a/templates/nyc.html +++ b/templates/nyc.html @@ -18,23 +18,23 @@ Blocpower
- +
@@ -49,6 +49,17 @@
Very Effiencient
+
+
+ + +
+
+ + +
+
+

@@ -187,7 +198,17 @@ // START OSMB - in blocmaps.js // startOSMB(position, bounds, pointerdown); - + +{% if GOOGLE_ANALYTICS %} + +{% endif %} \ No newline at end of file diff --git a/templates/rochester.html b/templates/rochester.html index 8939f1dbc8cef9bb0b8cf5a55b766b76c8b5d8b4..b2ecfe2e10db77ee96dd693d51b85b6ac8895b08 100644 --- a/templates/rochester.html +++ b/templates/rochester.html @@ -10,18 +10,18 @@ - -
+
@@ -36,7 +36,49 @@
Very Effiencient
+
+
+ + +
+
+ + +
+
+
+
+

+ +
+
+

+

+
+
+

Projected Energy Consumption

+

20,000kwh

+

Type 33% less efficient than similar buildings in this area.

+
+
+

Energy Conservation Measures

+

ECM's are the recommended energy saving measures this building can take in order to dramatically conserve energy.

+
+
    +

    We can help retrofit this building, just drop us a line!

    + Contact Blocpower +
    +
    +

    We haven't generated any ECM's for this building yet, but we can. if you're the owner or manager of this building email us at info@blocpower.org +

    +
    +
    +

    Building Details

    +
    +
    +

    Do you manage or own this building?

    +
    @@ -44,66 +86,84 @@ - + } + + // START OSMB - in blocmaps.js // + startOSMB(position, bounds, pointerdown); + + +{% if GOOGLE_ANALYTICS %} + +{% endif %}