/
map.php
165 lines (107 loc) · 3.09 KB
/
map.php
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<html>
<head>
<script
src="https://s3-us-west-2.amazonaws.com/nickolanackbucket/mootools/mootools-core.js"
type="text/javascript"></script>
<script
src="https://s3-us-west-2.amazonaws.com/nickolanackbucket/mootools/mootools-more.js"
type="text/javascript"></script>
<script
src="https://s3-us-west-2.amazonaws.com/nickolanackbucket/mootools/mootools_compat.js"
type="text/javascript"></script>
<script type="text/javascript"
src="bower_components/js-simplekml/KmlReader.js">
</script>
<style>
#map {
width: 100%;
height: 100%;
}
body {
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
function initMap(){
var map = new google.maps.Map(document.getElementById('map'), {
disableDefaultUI:true,
center: {
lat:50.50359739949432,
lng:-125.25016503906248
},
zoom: 6,
mapTypeId:google.maps.MapTypeId.ROADMAP,
panControl:true,
zoomControl:true
});
var layer=<?php
if(key_exists('site',$_GET)){
$site=$_GET['site'];
if(key_exists('layer',$_GET)){
include_once __DIR__.'/MapResources.php';
$url='http://apps.gov.bc.ca/pub/dmf-rest-api/resources/sites/';
$server=new MapResources($url);
if(key_exists('cat',$_GET)){
$layer=$_GET['layer'];
$cat=$_GET['cat'];
echo json_encode($server->getResourceArcLayerKml($site, $layer, $cat));
}else{
$layer=$_GET['layer'];
echo json_encode($server->getResourceLayerKml($site, $layer));
}
}
}
?>;
var infowindow = new google.maps.InfoWindow({
});
(new KmlReader(layer)).parsePolygons(function(polygonParams, xmlSnippet){
//console.log(polygonParams);
var polygon= new google.maps.Polygon((function(){
var polygonOpts={
paths:(function(){
var paths=polygonParams.coordinates.map(function(coord){
return {lat:parseFloat(coord[0]), lng:parseFloat(coord[1])};
});
return paths;
})(),
fillColor:'rgba(100, 149, 237, 0.70)', //cornflowerblue;
fillOpacity:0.7,
strokeColor:'#000000',
strokeWeight:1,
strokeOpacity:0.7
};
return polygonOpts;
})());
polygon.setMap(map);
google.maps.event.addListener(polygon, 'click',function(e){
infowindow.setContent(polygonParams.description||'');
infowindow.setPosition(polygon.getPath().getAt(0));
infowindow.open(map);
});
}).parseMarkers(function(markerParams, xmlSnippet){
//console.log(polygonParams);
var marker= new google.maps.Marker((function(){
var markerOpts={
position: {lat:parseFloat(markerParams.coordinates[0]), lng:parseFloat(markerParams.coordinates[1])},
title: markerParams.name||'unnammed'
};
// if(markerParams.icon){
markerOpts.icon='https://storage.googleapis.com/support-kms-prod/SNP_2752125_en_v0';//markerParams.icon;
// }
return markerOpts;
})());
marker.setMap(map);
google.maps.event.addListener(marker, 'click',function(e){
infowindow.setContent(markerParams.description||'');
infowindow.open(map, marker);
});
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBnTJCsJO2piovlyQfpmemfQXVjwkdB7R4&callback=initMap"></script>
</body>
</html>