Number of markers to plot:
A maximum of 999 markers can be plotted.
var map;
var arrMarkers=new Array(0);
var bounds;
var map;
var messagediv=document.getElementById('messagediv');
var tileProviderURL="tile.openstreetmap.org";
var tileProviderAttribution='© <a href="//www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
var mapDivID = "map_canvas";
var latlng=[54.6228,-5.8955];
var zoom = 12;
var routePoints=new Array(0);
function initialize()
{
document.getElementById(mapDivID).style.cursor = "crosshair";
map = L.map(mapDivID,{
fullscreenControl: true,
fullscreenControlOptions: {
position: 'topleft'
}
}).setView(latlng, zoom);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?', {
maxZoom: 18,
attribution: 'Map data © <a href="//openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="//creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
id: 'mapbox.streets'
}).addTo(map);
var openstreetmap = L.tileLayer('https://{s}.'+tileProviderURL+'/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: tileProviderAttribution
});
openstreetmap.addTo(map);
}
function ftn_button_clicked()
{
clearmarkers();
var num=document.getElementById("nm").value;
if (num<1000)
{
plotrandom(num);
}
}
function ftn_button_clearmap()
{
clearmarkers();
}
function clearmarkers()
{
if (arrMarkers)
{
for (i in arrMarkers)
{
arrMarkers[i].removeFrom(map);
}
}
arrMarkers=new Array(0);
}
function plotrandom(number)
{
bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng - southWest.lng;
var latSpan = northEast.lat - southWest.lat;
pointsrand=[];
for(var i=0;i<number;++i)
{
var point = [southWest.lat + latSpan * Math.random(),southWest.lng + lngSpan * Math.random()];
pointsrand.push(point);
}
for(var i=0;i<number;++i)
{
var str_text=i+" : "+pointsrand[i];
var marker=placeMarker(pointsrand[i],str_text);
marker.addTo(map);
arrMarkers.push(marker);
}
}
function placeMarker(location,text)
{
var marker = L.marker(location,{title:text});
return marker;
}
It'd be nice to have a clear marker button.
On 30th November 2019Thanks!
On 11th March 2016Hi, the markers now display the location latitude and longitude. In terms of restricting the area, this is not possible.
By Daft Logic on 14th March 2015How do you get the exact coordinates of a randomly generated point? And is there any way to restrict this to a set area (say, to not place any points in the ocean)?
On 6th March 2015Doesn't work
On 3rd October 2011i find this VERY usefull.
Means i can plot GPS stuff
i dont think there is a point!!!
By a person on 23rd September 2008what is the point of this example?!?
By BoyHowdy on 23rd September 2008with broadband speeds ever increasing the number of pointless plots should be increased to the three digit mark at least!
By physco219 on 1st January 2008There's no need to create an account or provide unnecessary details. Just your comment.