forked from tombatossals/angular-leaflet-directive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0303-paths-3000-items-example.html
147 lines (138 loc) · 6.12 KB
/
0303-paths-3000-items-example.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html ng-app="demoapp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/leaflet/dist/leaflet.js"></script>
<script src="../bower_components/angular-simple-logger/dist/angular-simple-logger.js"></script>
<script src="../bower_components/Leaflet.label/dist/leaflet.label.js"></script>
<script src="../dist/angular-leaflet-directive.js"></script>
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<link rel="stylesheet" href="../bower_components/Leaflet.label/dist/leaflet.label.css" />
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller('Paths3000ItemsController', ['$scope', 'leafletData', 'LocationDataService', function ($scope, leafletData, LocationDataService) {
//map properties
angular.extend($scope, {
defaults: {
scrollWheelZoom: false
},
//restrict map panning for this region
maxbounds: {
northEast: {
lat: 90,
lng: -180
},
southWest: {
lat: -90,
lng: 180
}
},
centroid: {
lat: 50,
lng: 10,
zoom: 3
},
layers: {
baselayers: {
stamen: {
name: 'StamenWatercolor',
url: 'http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.png',
type: 'xyz',
}
}
}
});
// set up circle rendering
//namespace leaflet path
$scope.paths = {};
//bind locationGrid to zoom level
$scope.$watch("centroid.zoom", function (zoom) {
if (zoom <= 3) {
//clear path object
$scope.paths = {};
//get location data and initialize leaflet circles
LocationDataService.getLocationsTenGrid().then(function (res) {
angular.forEach(res.data, function (value, key) {
if (value.lat !== null && value.lon !== null) {
$scope.paths['circle' + key] = {
type: 'circle',
className: 'testClass',
fillColor: 'DarkSlateGray',
color: '#000000',
weight: 0,
opacity: 1,
fillOpacity: 0.8,
stroke: false,
clickable: false,
latlngs: [parseFloat(value.lat), parseFloat(value.lon)],
radius: Math.sqrt(value.location_count) * 5000
};
}
});
}, function (error) {
console.log('An error occured!', error);
});
}
if (zoom >= 4) {
//clear path object
$scope.paths = {};
//get location data and initialize leaflet circles
LocationDataService.getLocationsZeroOneGrid().then(function (res) {
angular.forEach(res.data, function (value, key) {
if (value.lat !== null && value.lon !== null) {
$scope.paths['circle' + key] = {
type: 'circle',
className: 'testClass',
fillColor: 'DarkSlateGray',
color: '#000000',
weight: 0,
opacity: 1,
fillOpacity: 0.8,
stroke: false,
clickable: false,
latlngs: [parseFloat(value.lat), parseFloat(value.lon)],
radius: Math.sqrt(value.location_count) * 2000
};
}
});
}, function (error) {
console.log('An error occured!', error);
});
}
});
}]);
// getting data with a factory
app.factory('LocationDataService', LocationDataService);
/* @ngInject */
function LocationDataService($http) {
var srv = {};
// Service implementation for gridsize = 10
srv.getLocationsTenGrid = function () {
return $http.get('json/mockupTenGrid.json', {
cache: true
});
};
// Service implementation for gridsize = 0.1
srv.getLocationsZeroOneGrid = function () {
return $http.get('json/mockupZeroOneGrid.json', {
cache: true
});
};
// Public API
return {
getLocationsTenGrid: function () {
return srv.getLocationsTenGrid();
},
getLocationsZeroOneGrid: function () {
return srv.getLocationsZeroOneGrid();
}
};
};
</script>
</head>
<body ng-controller="Paths3000ItemsController">
<leaflet watch-paths="false" lf-center="centroid" maxbounds="maxbounds" layers="layers" paths="paths" defaults="defaults" width="100%" height="480px"></leaflet>
<h1>3000 items in a map performance</h1>
</body>
</html>