This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
turf-filter.html
79 lines (65 loc) · 3.57 KB
/
turf-filter.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Turf - filter</title>
<style>
html, body{ font-size: 16px; }
.filter-btn{ font-size: 150%; margin-bottom: 0.5em; }
#mapDiv { width: 600px; height: 600px; }
.map-box{ padding: 10px; }
</style>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/turf.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=drawing"></script>
</head>
<body onload="initMap()">
<button class="filter-btn">Filter</button>
<div id="mapDiv"></div>
<script>
var map, points1, infoWindow = new google.maps.InfoWindow({ content: "" }), dataMap = new google.maps.Data();
google.maps.InfoWindow.prototype.isOpen = function(){
var map = this.getMap();
return (map !== null && typeof map !== "undefined");
}
$('.filter-btn').on('click', function(e){
e.preventDefault();
var key = "point";
var value = "甲";
var filtered = turf.filter(points1, key, value);
// clear
dataMap.setMap(null);
// add new data
dataMap = new google.maps.Data();
dataMap.addGeoJson(filtered);
dataMap.setMap(map);
dataMap.setStyle(function(feature) {
if( feature.getProperty('point') ){
return { icon: new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_spin&chld=1|0|"+ feature.getProperty('color') +"|15|b|" + feature.getProperty('point')) };
}
});
});
function initMap() {
// points1
points1 = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[121.5256694381271,25.053577650613306]},"properties":{"color":"90EE90","point":"甲"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52636817270518,25.055905427214785]},"properties":{"color":"87CEFA","point":"乙"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52112800737866,25.057645373121463]},"properties":{"color":"FFE4E1","point":"丙"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52063982334899,25.05593656466616]},"properties":{"color":"FFA500","point":"丁"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52822524704958,25.05430817578928]},"properties":{"color":"90EE90","point":"甲"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.51697150268838,25.06313056418346]},"properties":{"color":"87CEFA","point":"乙"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52407207884563,25.052244590956573]},"properties":{"color":"FFE4E1","point":"丙"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.51730836376227,25.057391228528445]},"properties":{"color":"FFA500","point":"丁"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52040727358757,25.05383479238944]},"properties":{"color":"90EE90","point":"甲"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[121.52038840696568,25.064035836338217]},"properties":{"color":"87CEFA","point":"乙"}}]};
// 地圖初始設定
var mapOptions = {
center: new google.maps.LatLng(25.06024, 121.52276),
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = document.getElementById("mapDiv");
// Google 地圖初始化
map = new google.maps.Map(mapElement, mapOptions);
// 載入 GeoJSON 資料
dataMap.addGeoJson(points1);
dataMap.setMap(map);
dataMap.setStyle(function(feature) {
if( feature.getProperty('point') ){
return { icon: new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_spin&chld=1|0|"+ feature.getProperty('color') +"|15|b|" + feature.getProperty('point')) };
}
});
}
</script>
</body>
</html>