Commit 0a636999 authored by grisel-davy's avatar grisel-davy
Browse files

Commit finale foure tout

parent 6a23b57d
......@@ -15,4 +15,8 @@ class Mesure(models.Model):
class Meta:
unique_together = ('time', 'point', 'bssid')
def __str__(self):
return 'Mesure en {}'.format(self.point.coords)
return 'Mesure du {}'.format(self.time)
@property
def popupContent(self):
return "<p>{}</p><p>{}</p>".format(self.ssid,self.puissance)
<!DOCTYPE html>
<html>
{% load leaflet_tags %}
{% load geojson_tags %}
{% load static %}
<head>
<meta charset="utf-8" />
<title>Puissance des signaux wifi</title>
{% leaflet_js %}
{% leaflet_css %}
<script src="{% static 'leaflet-heatmap/leaflet-heat.js' %}"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map{
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function geoJson2heat(geojson, intensity) {
return geojson.features.map(function(feature) {
return [
feature.geometry.coordinates[1],
feature.geometry.coordinates[0],
100+feature.properties[intensity],
];
});
}
function map_init(map,options){
var collection = {{ queryset|geojsonfeature:"puissance:point"|safe }};
var geoData = geoJson2heat(collection,"puissance");
L.heatLayer(geoData,{radius:50,max:30}).addTo(map)
}
</script>
{% leaflet_map "map" callback="map_init" %}
</body>
</html>
......@@ -2,6 +2,7 @@
<html>
{% load leaflet_tags %}
{% load geojson_tags %}
{% load static %}
<head>
<meta charset="utf-8" />
......@@ -27,26 +28,21 @@
</head>
<body>
{% leaflet_map "map" callback="main_map_init" %}
<script type="text/javascript">
function main_map_init (map, options) {
var dataurl = "{% url 'maps:data' %}";
var request = new XMLHttpRequest();
request.open('GET', dataurl, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var data = JSON.parse(request.responseText);
var markers = L.markerClusterGroup();
L.geoJson(data).addTo(markers);
map.addLayer(markers);
};
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
};
function onEachFeature(feature,layer){
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
}
var collection = {{ queryset|geojsonfeature:"popupContent:point"|safe }};
function map_init(map,options){
var markers = L.markerClusterGroup();
L.geoJson(collection, {onEachFeature:onEachFeature}).addTo(markers);
map.addLayer(markers);
}
</script>
{% leaflet_map "map" callback="map_init" %}
</body>
</html>
......@@ -23,10 +23,8 @@ from . import models
app_name = 'maps'
urlpatterns = [
path('data',GeoJSONLayerView.as_view(model=models.Mesure,
geometry_field='point',
fields=("puissance","ssid")),
name='data'),
path('',views.IndexView.as_view(), name='index'),
path('heat/<ssid>',views.HeatMapView.as_view(),name="heatmap"),
path('all',views.NetworkView.as_view()),
path('ssid/<ssid>',views.NetworkView.as_view(), name='map'),
path('send/', views.receive, name='POST request'),
]
from django.shortcuts import render, HttpResponse
# Create your views here.
#
from django.views.generic.base import View, TemplateView
from django.http.response import HttpResponse
from .parser import request_parser
from .models import Mesure
class IndexView(TemplateView):
class NetworkView(TemplateView):
template_name = 'maps/index.html'
def get_context_data(self, **kwargs):
return kwargs
ssid = self.kwargs.get("ssid")
if ssid:
queryset = Mesure.objects.filter(ssid=ssid)
else:
queryset = Mesure.objects.all()
return {"queryset":queryset}
pass
class HeatMapView(NetworkView):
template_name = 'maps/heat.html'
pass
def receive(request):
"""Reception des request POST ou GET et utilisation des données"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment