Commit 5dde6bca authored by Hypsug0's avatar Hypsug0
Browse files

Merge branch 'develop' into 'develop'

fix place update form

See merge request !49
parents e940bba7 31291677
......@@ -289,155 +289,7 @@ class PlaceUpdate(PlaceEditAuthMixin, UpdateView):
context[
"js"
] = """
var dataurl = '/api/place.geojson';
var metaplace_dataurl = '/api/metaplaces.geojson';
window.addEventListener("map:init", function (event) {
var markers = L.markerClusterGroup({chunkedLoading: true, spiderfyDistanceMultiplier: 3, maxClusterRadius: 14});
var style_data = {
radius: 6,
fillColor: "#ff4c41",
color: "#ddd",
weight: 2,
opacity: 1,
fillOpacity: 0.8
};
var style_data_metasite = {
radius: 6,
fillColor: "#8A2BE2",
color: "#ddd",
weight: 2,
opacity: 1,
fillOpacity: 0.8
};
var polygon_style = {
color: "#8A2BE2",
fillColor: "#9370DB",
weight: 2,
opacity: 0.8,
fillOpacity: 0.2
};
var map = event.detail.map;
map.spin(true);
// Fonction plein écran
map.addControl(new L.Control.Fullscreen());
// Géolocalisation de l'utilisateur
var locateOptions = {
flyTo: true,
title: 'Ma position',
icon: 'fa fa-location-arrow',
};
L.control.locate(locateOptions).addTo(map);
// Recherche par adresse
map.addControl(new L.Control.Search({
url: 'https://nominatim.openstreetmap.org/search?format=json&accept-language=fr-FR&q={s}',
jsonpParam: 'json_callback',
propertyName: 'display_name',
propertyLoc: ['lat', 'lon'],
markerLocation: true,
autoType: true,
autoCollapse: true,
minLength: 2,
zoom: 13,
text: 'Suchen...',
textCancel: 'Annuler',
textErr: 'Erreur'
}));
// Add legend
let legend = L.control({ position: "topright" });
legend.onAdd = function(map) {
let div = L.DomUtil.create("div", "legend");
div.innerHTML += '<i style="background: #ff4c41"></i><span>Localisation simple</span><br>';
div.innerHTML += '<i style="background: #8A2BE2"></i><span>Localisation sur un métasite</span><br>';
div.innerHTML += '<i style="background: #9370DB; border-radius: 0%;"></i><span>Emprise du métasite</span><br>';
return div;
};
legend.addTo(map);
// Download GeoJSON data with Ajax
fetch(dataurl, {
credentials: "include"
})
.then(function (resp) {
return resp.json();
})
.then(function (data) {
markers.addLayer(L.geoJson(data, {
onEachFeature: function onEachFeature(feature, layer) {
var props = feature.properties;
var content = `<a class="btn btn-primary btn-sm btn-block" align="center" style="color:white;" href="/place/${props.pk}/detail" target="_blank" style="font-color:white"><strong>${props.name}</strong></a>`;
layer.bindPopup(content);
}
,
pointToLayer: function (feature, latlng) {
// Set a different color if location is in a metaplace
if (feature.properties.metaplace) {
return L.circleMarker(latlng, style_data_metasite);
}
return L.circleMarker(latlng, style_data);
}
})).addTo(map).bringToFront();
})
.then(function () {
map.spin(false);
});
// Download GeoJSON data with Ajax
fetch(metaplace_dataurl, {credentials: "include"})
.then(function (resp) {
return resp.json();
})
.then(function (data) {
L.geoJSON(data, {
style: polygon_style,
onEachFeature: function onEachFeature(feature, layer) {
var props = feature.properties;
var content = `<a class="btn btn-primary btn-sm btn-block" align="center" style="color:white;" href="/metaplace/${props.pk}/detail" target="_blank" style="font-color:white"><strong>${props.name}</strong></a>`;
layer.bindPopup(content);
}
}).addTo(map).bringToBack();
})
.then(function () {
map.spin(false);
})
.catch(function (error) {
console.log(error);
});
// Trigger zoom on coordinate with manual filling
$('#id_x,#id_y').on('change', function() {
let x = $('#id_x').val();
let y = $('#id_y').val();
if ( x && y) {
for (k in map._layers) {
if (map._layers[k].dragging) {
console.log(map._layers[k])
var newLatLng = new L.LatLng(y, x);
map._layers[k].setLatLng(newLatLng);
map.flyTo([y, x], 16);
}
};
}
});
// Reset fields if users draw/edit the leaflet marker
map.on('draw:created draw:edited', function (e) {
$('#id_x').val('') && $('#id_y').val('');
});
});
"""
return context
......
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