Skip to content

Commit

Permalink
Created a frontend app to have the map,
Browse files Browse the repository at this point in the history
added deck.gl to the frontend app,
  • Loading branch information
frasanz committed Oct 4, 2024
1 parent 7880f58 commit c3891c8
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 0 deletions.
Empty file added frontend/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions frontend/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions frontend/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class FrontendConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'frontend'
Empty file added frontend/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions frontend/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
45 changes: 45 additions & 0 deletions frontend/templates/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deck.gl Map</title>
<!-- Include Mapbox and deck.gl CDN -->
<script src="https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
</head>
<body>
<div id="map-container" style="width: 100%; height: 500px;"></div>

<script>
// Mapbox access token
const MAPBOX_ACCESS_TOKEN = "{{mapbox_token}}";

// Initialize the deck.gl map
const deckgl = new deck.DeckGL({
container: 'map-container',
mapboxApiAccessToken: MAPBOX_ACCESS_TOKEN,
mapStyle: 'mapbox://styles/mapbox/light-v9',
initialViewState: {
longitude: -0.88,
latitude: 41.64,
zoom: 12,
pitch: 45,
bearing: 0
},
controller: true,
layers: [
new deck.ScatterplotLayer({
data: [
{position: [-122.4, 37.8], size: 100}
],
getPosition: d => d.position,
getRadius: d => d.size,
getFillColor: [255, 0, 0],
})
]
});
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions frontend/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
6 changes: 6 additions & 0 deletions frontend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('', views.index),
]
10 changes: 10 additions & 0 deletions frontend/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.shortcuts import render
from django.conf import settings

# Create your views here.

def index(request):
context = {
'mapbox_token': settings.MAPBOX_ACCESS_TOKEN
}
return render(request, 'frontend/index.html', context)
5 changes: 5 additions & 0 deletions openred/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
# Custom apps
'devices',
'measures',
'frontend',


]
Expand All @@ -82,6 +83,7 @@
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
Expand Down Expand Up @@ -156,6 +158,9 @@
}
}

# Mapbox
MAPBOX_ACCESS_TOKEN = config('MAPBOX_ACCESS_TOKEN')


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
Expand Down
1 change: 1 addition & 0 deletions openred/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
path('api/', include('measures.urls')),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('', include('frontend.urls')),
]

0 comments on commit c3891c8

Please sign in to comment.