-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
205 lines (203 loc) · 5.8 KB
/
test.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<title>深圳野生动物园测试地图</title>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=device-width, initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="telephone=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<link rel="stylesheet" href="css/ol.css" type="text/css">
<link rel="stylesheet" href="css/css.css?v=11" type="text/css">
<script src="js/axios.min.js"></script>
<script src="js/ol.js"></script>
<!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>-->
<script src="js/fed-transform.js"></script>
<script src="js/mydis.js?v=1asfdasdfasdf2"></script>
</head>
<body>
<div id="map" class="map"></div>
<div id="mouse-position" style="top:10px;left:10px;position:absolute;font-size:30px;"></div>
<span id="myposition"></span>
<div id="tips">建议打开手机wifi,定位更准确^_^</div>
<div id="extentTips">当前定位,您不在<b>深圳野生动物园</b>内!</div>
<script>
window.debug = true;
var extent = undefined//[113.9580, 22.5960, 113.9780, 22.6060];
//分辨率
var resolutions = [
1.40625,
0.703125,
0.3515625,
0.17578125,
0.087890625,
0.0439453125,
0.02197265625,
0.010986328125,
0.0054931640625,
0.00274658203125,
0.001373291015625,
0.0006866455078125,
0.00034332275390625,
0.000171661376953125,
0.0000858306884765625,
0.00004291534423828125,
0.000021457672119140625,
0.000010728836059570312,
0.000005364418029785156,
0.000002682209014892578,
0.000001341104507446289
];
var projection=ol.proj.get('EPSG:4326');//设置坐标系;
var matrixIds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
var projectionExtent =projection.getExtent();
var sourceProj = 'EPSG:4326';
var targetProj = "EPSG:4326";
var view = new ol.View({
enableRotation: false,
projection: projection,
center: [113.96834313869476, 22.598670423030853],
zoom: 18,
minZoom: 11,
maxZoom: 19,
extent: extent
});
var styleHash = {
shop: new ol.style.Style({
image: new ol.style.Icon({
src: 'images/icons/shop.png'
})
}),
wc: new ol.style.Style({
image: new ol.style.Icon({
src: 'images/icons/wc.png'
})
})
};
var flayer = new ol.layer.Vector({
source: new ol.source.Vector(),
style: function (feature) {
return styleHash[feature.get('type')]
}
});
flayer.setVisible(false);
var map = new ol.Map({
loadTilesWhileAnimating: true,
controls: ol.control.defaults({
attributionOptions: {
collapsible: false
}
}),
layers: [
new ol.layer.Tile({
title: "天地图路网",
source: new ol.source.XYZ({
url: "http://t4.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}"
})
}),
new ol.layer.Tile({
title: "天地图文字标注",
source: new ol.source.XYZ({
url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}'
})
}),
new ol.layer.Tile({
opacity: 1,
source: new ol.source.XYZ({
crossOrigin: ol.extent.getTopLeft(projectionExtent),
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
resolutions: resolutions.slice(0, 21),
matrixIds: matrixIds.slice(0, 21)
}),
tileUrlFunction: function (tileCoord) {
return 'map2/' + tileCoord[0] + '/' + (-tileCoord[2]) + '/' + tileCoord[1] + '.png';
},
})
}),
flayer
],
target: 'map',
view: view
});
var mydis = new Mydis({id: 'mydis', map: map});
var isFirst = true;
var info = document.getElementById('mouse-position');
mydis.events.changePosition = function (p) {
if (isFirst) {
if (isInExtent(p)) {
map.getView().setCenter(p);
}
isFirst = false;
}
if (window.debug) {
info.innerHTML = p[0].toFixed(6) + "," + p[1].toFixed(6);
}
};
window.onload = function () {
document.getElementById('myposition').onclick = function (e) {
if (isInExtent(mydis.position)) {
map.getView().animate({
center: mydis.position,
duration: 1000
});
} else {
}
}
};
axios.get('data/features.json').then(function (res) {
var datas = res.data.results;
datas.forEach(function (data) {
var feature = new ol.Feature({
geometry: new ol.geom.Point([data.fields.x, data.fields.y]),
name: data.fields.name
});
feature.set('type', data.fields.categories.name);
flayer.getSource().addFeature(feature)
})
});
checkNum = 9;
setInterval(function () {
if (navigator.connection && navigator.connection.type === 'wifi') {
document.getElementById('tips').className = '';
} else {
if (checkNum >= 10) {
document.getElementById('tips').className = 'active';
checkNum = 0;
}
checkNum += 1;
}
}, 1000);
function isInExtent(p) {
if(!p){
return false;
}
if(p[0]<113.9580||p[0]>113.9780||p[1]<22.5960||p[1]>22.6060){
openExtentTips();
return true;
}else{
return true;
}
}
var extentTimeId=null;
function openExtentTips(){
var node=document.getElementById('extentTips');
node.className='active';
extentTimeId&&clearTimeout(extentTimeId);
extentTimeId=setTimeout(function(){
node.className='';
},2000)
}
map.getView().on("change:resolution",function(){
var zoom=map.getView().getZoom();
if(zoom>=18){
flayer.setVisible(true);
}else{
flayer.setVisible(false);
}
});
</script>
</body>
</html>