-
Notifications
You must be signed in to change notification settings - Fork 632
/
Copy path0124-basic-geojson-non-nested-example.html
83 lines (77 loc) · 3.01 KB
/
0124-basic-geojson-non-nested-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
<!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/index.js"></script>
<script src="../dist/angular-leaflet-directive_dev_mapped.js"></script>
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller("GeoJSONNonNestedController", [ '$scope', '$http', 'leafletData', function($scope, $http, leafletData) {
var getColor = function(id){
return id == 'USA'? 'blue' : 'green';
};
var getStyle = function(feature){
return {
fillColor: getColor(feature.id),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
};
var createGeoJsonObject = function (data){
return {
data: data,
style: getStyle
};
};
angular.extend($scope, {
japan: {
lat: 27.26,
lng: 78.86,
zoom: 2
},
defaults: {
scrollWheelZoom: false
},
});
$scope.centerJSON = function(index) {
leafletData.getMap().then(function(map) {
var latlngs = [];
for (var i in $scope.geojson.data.features[index].geometry.coordinates) {
var coord = $scope.geojson.data.features[index].geometry.coordinates[i];
for (var j in coord) {
var points = coord[j];
for (var k in points) {
latlngs.push(L.GeoJSON.coordsToLatLng(points[k]));
}
}
}
map.fitBounds(latlngs);
});
};
// Get the countries geojson data from a JSON
$http.get("json/JPN.geo.json").success(function(data, status) {
if(!$scope.geojson){
$scope.geojson = createGeoJsonObject(data);
}
});
$http.get("json/USA.geo.json").success(function(data, status) {
var features = $scope.geojson.data.features.concat(data.features);
var copy = angular.extend({}, $scope.geojson.data);
copy.features = features;
$scope.geojson.data = copy;
});
} ]);
</script>
</head>
<body ng-controller="GeoJSONNonNestedController">
<leaflet center="japan" geojson="geojson" width="100%" height="480px"></leaflet>
<h1>GeoJSON non nested example</h1>
<input type="button" value="center usa" ng-click="centerJSON(1)" />
<input type="button" value="center jpn" ng-click="centerJSON(0)" />
</body>
</html>