Last active
February 23, 2022 17:24
-
-
Save fortunto2/2dc837faa4e3549ecd440878382fb9bb to your computer and use it in GitHub Desktop.
map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load static %} | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>Markers Map</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" type="text/css" href="{% static 'map.css' %}"> | |
<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/leaflet.css"> | |
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> | |
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> | |
<script src="{% static 'L.ArrowCircle.js' %}"></script> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="{% static 'map.js' %}"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, body { | |
height: 100%; | |
margin: 0; | |
} | |
#map { | |
width: 100%; | |
height: 100%; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
var map = L.map('map').setView([53.62, 55.91], 11); | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: attribution}).addTo(map); | |
// const markers = JSON.parse(document.getElementById('markers-data').textContent); | |
// let feature = L.geoJSON(markers).bindPopup(function (layer) { return layer.feature.properties.name; }).addTo(map); | |
function onEachFeature(feature, layer) { | |
// does this feature have a property named popupContent? | |
console.log(feature) | |
console.log(layer) | |
if (feature.properties && feature.properties.name) { | |
layer.bindPopup(feature.properties.name); | |
} | |
if (feature.geometry && feature.geometry.type === "MultiPolygon" ) { | |
console.log('завод') | |
} | |
if (feature.geometry && feature.geometry.type === "Point" ) { | |
} | |
} | |
var geojsonMarkerOptions = { | |
radius: 8, | |
fillColor: "#ff7800", | |
color: "#000", | |
weight: 1, | |
opacity: 1, | |
fillOpacity: 0.8 | |
}; | |
function callback(response) { | |
console.log(response); | |
// L.geoJSON(response, { | |
// onEachFeature: onEachFeature | |
// }).addTo(map); | |
L.geoJSON(response, { | |
style: function(feature) { | |
console.log(feature) | |
if (feature.geometry && feature.geometry.type === "Point" ) { | |
switch (feature.properties.aqi_category) { | |
case "Good": return {color: "#82ff53"}; | |
case 'Moderate': return {color: "#ffd500"}; | |
case 'Unhealthy for Sensitive Groups': return {color: "#ff6f6f"}; | |
case 'Unhealthy': return {color: "#c7005a"}; | |
case 'Very Unhealthy': return {color: "#5e0029"}; | |
case 'Hazardous': return {color: "#340000"}; | |
} | |
} | |
}, | |
pointToLayer: function (feature, latlng) { | |
// console.log(feature) | |
return L.marker | |
.arrowCircle(latlng, { | |
iconOptions: { rotation: feature.properties.wind.deg}, | |
}) | |
} | |
}).addTo(map); | |
}; | |
$.ajax({ | |
// url: "https://api-dev.bashair.ru/geo", | |
url: "http://localhost:8001/geo", | |
dataType: "json", | |
success: function (response) { | |
callback(response) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment