-
Notifications
You must be signed in to change notification settings - Fork 2
/
mxn-filter-radius.js
60 lines (54 loc) · 1.84 KB
/
mxn-filter-radius.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var mapstraction;
var centerRadius;
function initialize()
{
// hide the right-hand filter handle
$('handle2').hide();
mapstraction = new mxn.Mapstraction('map', 'ovi');
mapstraction.enableScrollWheelZoom();
myPoint = new mxn.LatLonPoint(52.250873, 0.110292);
mapstraction.setCenterAndZoom(myPoint, 12);
centerRadius = new mxn.Radius(myPoint, 20);
addMarkers(50);
addSlider();
sliderChanged(1);
}
function addMarkers(count) {
var bounds = mapstraction.getBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
while (count--) {
var ll = new mxn.LatLonPoint(sw.lat + ((ne.lat - sw.lat) * Math.random()),
sw.lon + ((ne.lon - sw.lon) * Math.random())
);
var marker = new mxn.Marker(ll);
var distance = mxn.util.KMToMiles(marker.location.distance(myPoint));
var el = "<strong>Distance: " + distance.toFixed(2) + " Mile(s)</strong>";
marker.setInfoBubble(el);
marker.setAttribute('distance', distance);
mapstraction.addMarker(marker);
}
}
function addSlider() {
slider = new Control.Slider('handle1', 'track', {
range: $R(0, 5, false),
step: 1,
restricted: true,
sliderValue: 1,
onChange: sliderChanged,
onSlide: sliderChanged
});
}
function sliderChanged(radius) {
var foo = "x";
mapstraction.removeAllPolylines();
mapstraction.removeAllFilters();
var sliderPoly = centerRadius.getPolyline(mxn.util.milesToKM(radius), '#00F');
sliderPoly.setOpacity(0.5);
mapstraction.addPolyline(sliderPoly);
mapstraction.addFilter('distance', 'le', radius);
var selectedCount = mapstraction.doFilter();
var tw = document.getElementById('timeWindow');
tw.innerHTML = 'Radius: ' + radius.toFixed(2) +
' Mile(s)<br/>Selected Markers: ' + selectedCount;
}