working MPV
This commit is contained in:
@@ -66,7 +66,7 @@ from rowers.courses import (
|
||||
)
|
||||
|
||||
from rowers import mytypes
|
||||
from rowers.models import course_spline
|
||||
from rowers.models import course_spline,VirtualRaceResult
|
||||
|
||||
import datetime
|
||||
import math
|
||||
@@ -2419,47 +2419,185 @@ def course_map(course):
|
||||
|
||||
return script,div
|
||||
|
||||
def leaflet_chart(lat,lon,name=""):
|
||||
if lat.empty or lon.empty: # pragma: no cover
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
def get_map_script_course(
|
||||
latmean,
|
||||
lonmean,
|
||||
latbegin,
|
||||
latend,
|
||||
longbegin,
|
||||
longend,
|
||||
scoordinates,
|
||||
course,
|
||||
):
|
||||
latmean,lonmean,coordinates = course_coord_center(course)
|
||||
lat_min, lat_max, long_min, long_max = course_coord_maxmin(course)
|
||||
|
||||
# Throw out 0,0
|
||||
df = pd.DataFrame({
|
||||
'lat':lat,
|
||||
'lon':lon
|
||||
})
|
||||
|
||||
df = df.replace(0,np.nan)
|
||||
df = df.loc[(df!=0).any(axis=1)]
|
||||
df.fillna(method='bfill',axis=0,inplace=True)
|
||||
df.fillna(method='ffill',axis=0,inplace=True)
|
||||
lat = df['lat']
|
||||
lon = df['lon']
|
||||
if lat.empty or lon.empty: # pragma: no cover
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
latmean = lat.mean()
|
||||
lonmean = lon.mean()
|
||||
|
||||
latbegin = lat[lat.index[0]]
|
||||
longbegin = lon[lon.index[0]]
|
||||
latend = lat[lat.index[-1]]
|
||||
longend = lon[lon.index[-1]]
|
||||
|
||||
coordinates = zip(lat,lon)
|
||||
coordinates = course_spline(coordinates)
|
||||
|
||||
scoordinates = "["
|
||||
|
||||
for x,y in coordinates:
|
||||
for index,row in coordinates.iterrows():
|
||||
scoordinates += """[{x},{y}],
|
||||
""".format(
|
||||
x=x,
|
||||
y=y
|
||||
x=row['latitude'],
|
||||
y=row['longitude']
|
||||
)
|
||||
|
||||
scoordinates +="]"
|
||||
|
||||
polygons = GeoPolygon.objects.filter(course=course).order_by("order_in_course")
|
||||
|
||||
plabels = ''
|
||||
|
||||
for p in polygons:
|
||||
coords = polygon_coord_center(p)
|
||||
|
||||
plabels += """
|
||||
var marker = L.marker([{latbegin}, {longbegin}]).addTo(mymap);
|
||||
marker.bindPopup("<b>{name}</b>");
|
||||
|
||||
""".format(
|
||||
latbegin = coords[0],
|
||||
longbegin = coords[1],
|
||||
name = p.name
|
||||
)
|
||||
|
||||
scoordinates += "]"
|
||||
pcoordinates = """[
|
||||
"""
|
||||
|
||||
for p in polygons:
|
||||
pcoordinates += """[
|
||||
["""
|
||||
|
||||
points = GeoPoint.objects.filter(polygon=p).order_by("order_in_poly")
|
||||
|
||||
for pt in points:
|
||||
pcoordinates += "[{x},{y}],".format(
|
||||
x = pt.latitude,
|
||||
y = pt.longitude
|
||||
)
|
||||
|
||||
# remove last comma
|
||||
pcoordinates = pcoordinates[:-1]
|
||||
pcoordinates += """]
|
||||
],
|
||||
"""
|
||||
|
||||
pcoordinates += """
|
||||
]"""
|
||||
|
||||
script = """
|
||||
<script>
|
||||
|
||||
|
||||
var streets = L.tileLayer(
|
||||
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
|
||||
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
|
||||
tileSize: 512,
|
||||
maxZoom: 18,
|
||||
zoomOffset: -1,
|
||||
id: 'mapbox/streets-v11',
|
||||
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
|
||||
}}
|
||||
),
|
||||
|
||||
satellite = L.tileLayer(
|
||||
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
|
||||
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
|
||||
tileSize: 512,
|
||||
maxZoom: 18,
|
||||
zoomOffset: -1,
|
||||
id: 'mapbox/satellite-v9',
|
||||
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
|
||||
}}
|
||||
),
|
||||
|
||||
outdoors = L.tileLayer(
|
||||
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
|
||||
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
|
||||
tileSize: 512,
|
||||
maxZoom: 18,
|
||||
zoomOffset: -1,
|
||||
id: 'mapbox/outdoors-v11',
|
||||
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
|
||||
}}
|
||||
);
|
||||
|
||||
|
||||
|
||||
var mymap = L.map('map_canvas', {{
|
||||
center: [{latmean}, {lonmean}],
|
||||
zoom: 13,
|
||||
layers: [streets, satellite]
|
||||
}}).setView([{latmean},{lonmean}], 13);
|
||||
|
||||
var navionics = new JNC.Leaflet.NavionicsOverlay({{
|
||||
navKey: 'Navionics_webapi_03205',
|
||||
chartType: JNC.NAVIONICS_CHARTS.NAUTICAL,
|
||||
isTransparent: true,
|
||||
zIndex: 1
|
||||
}});
|
||||
|
||||
|
||||
var osmUrl2='http://tiles.openseamap.org/seamark/{{z}}/{{x}}/{{y}}.png';
|
||||
var osmUrl='http://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png';
|
||||
|
||||
|
||||
//create two TileLayer
|
||||
var nautical=new L.TileLayer(osmUrl,{{
|
||||
maxZoom:18}});
|
||||
|
||||
|
||||
L.control.layers({{
|
||||
"Streets": streets,
|
||||
"Satellite": satellite,
|
||||
"Outdoors": outdoors,
|
||||
"Nautical": nautical,
|
||||
}},{{
|
||||
"Navionics":navionics,
|
||||
}}).addTo(mymap);
|
||||
|
||||
var latlongs = {scoordinates}
|
||||
var polyline = L.polyline(latlongs, {{color:'red'}}).addTo(mymap)
|
||||
mymap.fitBounds(polyline.getBounds())
|
||||
|
||||
var platlongs = {pcoordinates}
|
||||
var polygons = L.polygon(platlongs, {{color:'blue'}}).addTo(mymap)
|
||||
|
||||
{plabels}
|
||||
|
||||
|
||||
|
||||
var latlongs = {scoordinates}
|
||||
var polyline = L.polyline(latlongs, {{color:'red'}}).addTo(mymap)
|
||||
mymap.fitBounds(polyline.getBounds())
|
||||
|
||||
</script>
|
||||
""".format(
|
||||
latmean=latmean,
|
||||
lonmean=lonmean,
|
||||
latbegin = latbegin,
|
||||
latend=latend,
|
||||
longbegin=longbegin,
|
||||
longend=longend,
|
||||
scoordinates=scoordinates,
|
||||
pcoordinates=pcoordinates,
|
||||
plabels=plabels
|
||||
)
|
||||
|
||||
return script
|
||||
|
||||
|
||||
def get_map_script(
|
||||
latmean,
|
||||
lonmean,
|
||||
latbegin,
|
||||
latend,
|
||||
longbegin,
|
||||
longend,
|
||||
scoordinates,
|
||||
):
|
||||
script = """
|
||||
<script>
|
||||
|
||||
@@ -2551,6 +2689,73 @@ def leaflet_chart(lat,lon,name=""):
|
||||
scoordinates=scoordinates,
|
||||
)
|
||||
|
||||
return script
|
||||
|
||||
def leaflet_chart(lat,lon,name="",raceresult=0):
|
||||
if lat.empty or lon.empty: # pragma: no cover
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
|
||||
# Throw out 0,0
|
||||
df = pd.DataFrame({
|
||||
'lat':lat,
|
||||
'lon':lon
|
||||
})
|
||||
|
||||
df = df.replace(0,np.nan)
|
||||
df = df.loc[(df!=0).any(axis=1)]
|
||||
df.fillna(method='bfill',axis=0,inplace=True)
|
||||
df.fillna(method='ffill',axis=0,inplace=True)
|
||||
lat = df['lat']
|
||||
lon = df['lon']
|
||||
if lat.empty or lon.empty: # pragma: no cover
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
latmean = lat.mean()
|
||||
lonmean = lon.mean()
|
||||
|
||||
latbegin = lat[lat.index[0]]
|
||||
longbegin = lon[lon.index[0]]
|
||||
latend = lat[lat.index[-1]]
|
||||
longend = lon[lon.index[-1]]
|
||||
|
||||
coordinates = zip(lat,lon)
|
||||
|
||||
scoordinates = "["
|
||||
|
||||
for x,y in coordinates:
|
||||
scoordinates += """[{x},{y}],
|
||||
""".format(
|
||||
x=x,
|
||||
y=y
|
||||
)
|
||||
|
||||
scoordinates += "]"
|
||||
|
||||
if raceresult == 0:
|
||||
script = get_map_script(
|
||||
latmean,
|
||||
lonmean,
|
||||
latbegin,
|
||||
latend,
|
||||
longbegin,
|
||||
longend,
|
||||
scoordinates,
|
||||
)
|
||||
else:
|
||||
record = VirtualRaceResult.objects.get(id=raceresult)
|
||||
course = record.course
|
||||
script = get_map_script_course(
|
||||
latmean,
|
||||
lonmean,
|
||||
latbegin,
|
||||
latend,
|
||||
longbegin,
|
||||
longend,
|
||||
scoordinates,
|
||||
course,
|
||||
)
|
||||
|
||||
div = """
|
||||
<div id="map_canvas" style="width: 100%; height: 400px;"><p> </p></div>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user