-
Notifications
You must be signed in to change notification settings - Fork 12
/
measurement-center.html
93 lines (83 loc) · 2.8 KB
/
measurement-center.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
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<link rel="stylesheet" href="assets/css/styles.css" type="text/css">
<script src="//cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<script src="https://rawcdn.githack.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="assets/js/es6-promise.min.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,fetch"></script>
<script src="assets/js/helpers.js"></script>
<title>Turf and OpenLayers 3 - Center</title>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
// Declare a source for points and drawing
var vectorSourceCenter = new ol.source.Vector();
var vectorSourcePoints = new ol.source.Vector();
var pointsStyle = [new ol.style.Style({
image: new ol.style.Circle({
stroke: new ol.style.Stroke({
color: 'white'
}),
fill: new ol.style.Fill({
color: '#1f6b75'
}),
radius: 4
})
})];
var centerStyle = [new ol.style.Style({
image: new ol.style.Circle({
stroke: new ol.style.Stroke({
color: 'white'
}),
fill: new ol.style.Fill({
color: 'black'
}),
radius: 5
})
})];
var vectorLayerCenter = new ol.layer.Vector({
source: vectorSourceCenter,
style: centerStyle
});
var vectorLayerPoints = new ol.layer.Vector({
source: vectorSourcePoints,
style: pointsStyle
});
// Instanciate a map and add layers
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayerPoints,
vectorLayerCenter
],
view: new ol.View({
center: ol.proj.transform(
[-1.5603, 47.2383],
'EPSG:4326',
'EPSG:3857'
),
zoom: 11
})
});
fetch('assets/data/key_shop_with_name_nantes_area.geojson').then(function(response) {
return response.json().then(function(points_fc) {
console.log(points_fc);
var centerPoint = turf.center(points_fc);
console.log(centerPoint);
vectorSourceCenter.addFeatures(geojsonToFeatures(centerPoint, {
featureProjection: 'EPSG:3857'
}));
vectorSourcePoints.addFeatures(geojsonToFeatures(points_fc, {
featureProjection: 'EPSG:3857'
}));
});
});
</script>
</body>
</html>