i need help i am trying to show the map of tunisia at the map there is nothing shown , this my code of javascript :
`
<script>
$(function () {
var polygon = null;
var draggable = true;
initialize();
function initialize() {
// Create map for polygon drawing
var map = L.map("map").setView([34, 9], 6);
polygon = new MultiPolygon(map, $("#polygon-name").val());
// Create tunisiaMap as background
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution:
'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',
}).addTo(map);
var totalLatLng =
"(24.99539, 121.51033)|(25.02277, 121.53368)|(25.05295, 121.49935)|(25.01624, 121.44579)|(24.99508, 121.48252)";
// Ajoutez ici les autres valeurs de totalLatLng
var coords = new Array();
// Add markers for polygon coordinates
var splitLatLng = totalLatLng.split("|");
for (var i = 0; i < splitLatLng.length; i++) {
var latlng = splitLatLng[i]
.trim()
.substring(1, splitLatLng[i].length - 1)
.split(",");
if (latlng.length > 1) {
coords.push(L.latLng(latlng[0], latlng[1]));
}
}
polygon.addPolygon(coords, true);
polygon.setCreatePolygonsCallback(updateDetails);
polygon.setAllowDragging(draggable);
polygon.setEditable(true);
// Update coordinates displayed on 'C' press
updateCoords();
$(window).keyup(function (e) {
if (e.keyCode == 67) {
updateCoords();
}
});
$("#allow-dragging").click(function () {
draggable = !draggable;
polygon.setAllowDragging(draggable);
if (draggable) {
$(this).html("Disable Dragging");
} else {
$(this).html("Enable Dragging");
}
});
$("#new-polygon").click(function () {
polygon.createNewPolygon();
});
$("#clear-all").click(function () {
polygon.deleteAllPolygons();
});
$("#update-polygon").click(function () {
polygon.setName($("#polygon-name").val());
polygon.panToPolygon();
});
}
function updateDetails(p) {
updateCoords();
}
function updateCoords(e) {
var polys = polygon.getPolygons();
var multi_coords = polygon.getPolygonCoordinates();
$(".coords").empty();
for (var j in multi_coords) {
var name = $("<h3>" + polys[j].name + "</h3>").addClass(
polys[j].name,
);
if (polys[j].selfIntersects()) {
name.css("color", "red");
}
$(".coords").append(name);
var coords = multi_coords[j];
for (var i in coords) {
var c = $("<li>").html(
coords[i].lat + ", " + coords[i].lng,
);
$(".coords").append(c);
}
$(".coords").append("<hr/>");
}
}
});
</script>
trying to show the map of tunisia , expect to show the map of tunisia and the polygon both , i have trying multiple solutions but no way , i am using leaflet
2
Answers
hi i think you should add this code in your
initialize
function:you didn`t define any source for your map.
sorry, my last answer is for
open layer
library! for leaflet, just you should add this:i think you can check your network to find more data about error! good look!