Skip to content

Commit 9b309df

Browse files
committed
feat: support google pure map
1 parent fcbb959 commit 9b309df

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

_posts/2021-11-17-picture-gps.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
height:100%;
3131
}
3232

33-
.fullscreen-btn{
33+
.tools{
3434
position: absolute;
3535
z-index: 1;
3636
color: #e6e6e6;
3737
font-weight: 400;
3838
cursor: pointer;
3939
}
40+
.fullscreen-btn{
41+
42+
}
4043

4144
.picker {
4245
display: none;
@@ -98,7 +101,13 @@
98101
<h2>把图片拖进来</h2>
99102
<div class="container">
100103
<div class="map-ctn" id="mapCtn">
101-
<div class="fullscreen-btn">全屏</div>
104+
<div class="tools">
105+
<div class="fullscreen-btn">全屏</div>
106+
<label for="roadBtn">路网</label>
107+
<input type="checkbox" id="roadBtn" />
108+
<label for="googlePioBtn">谷歌标注</label>
109+
<input type="checkbox" checked id="googlePioBtn" />
110+
</div>
102111
</div>
103112
</div>
104113
<div id="makeAndModel" style="height: 30px; "></div>

resource/2021/1117_gps.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ var pageControl = {
1818
const fullBtn = $(".fullscreen-btn");
1919
const btnAmapTile = $("#btnAmapTile");
2020
const btnGoogleTile = $("#btnGoogleTile");
21+
const roadBtn = $("#roadBtn");
22+
const googlePioBtn = $("#googlePioBtn");
23+
var roadNetLayer = new AMap.TileLayer.RoadNet();
2124

2225
fullBtn.addEventListener("click", () => {
2326
$(".container").classList.toggle("fullscreen");
@@ -33,27 +36,54 @@ var pageControl = {
3336
});
3437
});
3538

36-
const googleLayer = new AMap.TileLayer({
39+
roadBtn.addEventListener("click", (e) => {
40+
if (roadBtn.checked) {
41+
map.add(roadNetLayer);
42+
} else {
43+
map.remove(roadNetLayer);
44+
}
45+
});
46+
47+
googlePioBtn.addEventListener("click", (e) => {
48+
if (googlePioBtn.checked) {
49+
map.add(googleLayerWithPio);
50+
map.remove(googleLayerPure);
51+
} else {
52+
map.remove(googleLayerWithPio);
53+
map.add(googleLayerPure);
54+
}
55+
});
56+
57+
const googleLayerPure = new AMap.TileLayer({
58+
tileUrl:
59+
"http://mt2.google.com/vt/lyrs=s&hl=zh-CN&gl=cn&x=[x]&y=[y]&z=[z]&s=Galil",
60+
zIndex: 3,
61+
});
62+
const googleLayerWithPio = new AMap.TileLayer({
3763
tileUrl:
3864
"http://mt2.google.com/vt/lyrs=y&hl=zh-CN&gl=cn&x=[x]&y=[y]&z=[z]&s=Galil",
3965
zIndex: 3,
4066
});
41-
this.googleLayer = googleLayer;
67+
this.googleLayerPure = googleLayerPure;
68+
this.googleLayerWithPio = googleLayerWithPio;
4269

4370
const amapSatelliteLayer = new AMap.TileLayer.Satellite();
4471
const amapRoadNetLayer = new AMap.TileLayer.RoadNet();
4572

4673
const map = new AMap.Map(mapContainer, {
4774
resizeEnable: true,
4875
zoom: 15,
76+
zooms: [2, 30],
4977
center: [116.397428, 39.90923],
78+
layers: [new AMap.TileLayer.Satellite()]
5079
});
5180

5281
const testGoogleImage = new Image();
53-
testGoogleImage.src = `//mt2.google.com/vt/lyrs=y&hl=zh-CN&gl=cn&x=17294&y=15469&z=15&s=Galil?t=${+Math.random()}`;
82+
testGoogleImage.src = `//mt2.google.com/vt/lyrs=s&hl=zh-CN&gl=cn&x=17294&y=15469&z=15&s=Galil`;
5483
testGoogleImage.onload = () => {
55-
map.add([googleLayer]);
84+
map.add([googleLayerWithPio]);
5685
};
86+
//map.add(roadNetLayer);
5787
/* var marker = new AMap.Marker({
5888
position: new AMap.LngLat(116.397428, 39.90923), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
5989
title: "北京",
@@ -334,11 +364,12 @@ var pageControl = {
334364
},
335365
//设置高德瓦片
336366
setAMapTile() {
337-
this.map.remove(this.googleLayer);
367+
this.map.remove(this.googleLayerWithPio);
368+
this.map.remove(this.googleLayerPure);
338369
},
339370
//设置谷歌瓦片
340371
setGoogleTile() {
341-
this.map.add(this.googleLayer);
372+
this.map.add(this.googleLayerWithPio);
342373
},
343374
};
344375
function initializegooglemap() {

0 commit comments

Comments
 (0)