Leaflet/debug/tests/mousemove_on_polygons.html

107 lines
2.8 KiB
HTML
Raw Normal View History

2015-03-14 05:08:50 +08:00
<!DOCTYPE html>
<html>
<head>
2015-05-28 19:16:56 +08:00
<title>Leaflet debug page</title>
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
<link rel="stylesheet" href="../../dist/leaflet.css" />
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
<link rel="stylesheet" href="../css/screen.css" />
<style>
.mybox {
background-color: red;
}
td {
border: transparent solid 2px;
}
td.red {
border: red solid 2px;
}
td.updated {
border: transparent solid 2px;
animation-name: borderfade;
animation-duration: 0.5s;
}
@keyframes borderfade {
from {
border: red solid 2px;
}
to {
border: transparent solid 2px;
}
}
</style>
<script src="../leaflet-include.js"></script>
<table>
<tr><td> </td><td>Enter </td><td>Move </td><td>Exit </td><td>Click </td></tr>
<tr><td>Triangle 1:</td><td id='enter1'></td><td id='move1'></td><td id='exit1'></td><td id='click1'></td></tr>
<tr><td>Triangle 2:</td><td id='enter2'></td><td id='move2'></td><td id='exit2'></td><td id='click2'></td></tr>
<tr><td>Map: </td><td id='enter3'></td><td id='move3'></td><td id='exit3'></td><td id='click3'></td></tr>
</table>
2015-03-14 05:08:50 +08:00
</head>
<body>
2015-05-28 19:16:56 +08:00
<div id="map"></div>
2017-02-04 23:17:51 +08:00
<script>
2015-05-28 19:16:56 +08:00
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
latlng = new L.LatLng(39.05, 8.40);
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
function update(domid) {
return function(){
document.getElementById(domid).innerHTML = Date.now();
document.getElementById(domid).className = 'red';
window.setTimeout(function(){
document.getElementById(domid).className = 'updated';
},1);
}
}
var polygon = (new L.Polygon([
[39, 8.40],
[39.10, 8.50],
[39.05, 8.30]
])).addTo(map).on('mouseover',update('enter1'))
.on('mousemove',update('move1'))
.on('mouseout',update('exit1'))
.on('click',update('click1'))
.bindPopup('Triangle 1');
2015-05-28 19:16:56 +08:00
var polygon2 = (new L.Polygon([
[39.03, 8.30],
[39.10, 8.40],
[39.00, 8.30]
])).addTo(map).on('mouseover',update('enter2'))
.on('mousemove',update('move2'))
.on('mouseout',update('exit2'))
.on('click',update('click2'))
.bindPopup('Triangle 2');
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
var marker = new L.Marker(latlng, {draggable: true})
.bindPopup('Marker');;
2015-05-28 19:16:56 +08:00
map.addLayer(marker);
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
// map.on('mousemove', function (e) {
// marker.setLatLng(e.latlng);
// });
map.on('mouseover',update('enter3'))
.on('mousemove',update('move3'))
.on('mouseout',update('exit3'))
.on('click',update('click3'));
2015-05-28 19:16:56 +08:00
// We should be able to move marker around in a fluid way,
// plus going over the polygon with no issue.
2015-03-14 05:08:50 +08:00
2015-05-28 19:16:56 +08:00
</script>
2015-03-14 05:08:50 +08:00
</body>
</html>