-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_cadaster.html
221 lines (196 loc) · 6.43 KB
/
google_cadaster.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!-- Coded by Pol Clota, 2021 -->
<!-- http://www.catastro.meh.es/servicios/wms/wms.htm -->
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/5.9.55/css/materialdesignicons.min.css"
integrity="sha512-vIgFb4o1CL8iMGoIF7cYiEVFrel13k/BkTGvs0hGfVnlbV6XjAA0M0oEHdWqGdAVRTDID3vIZPOHmKdrMAUChA=="
crossorigin="anonymous" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous">
</script>
<head>
<title>Google-Cadastre</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
width: 80%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div>
<h4 class="bg-dark text-white text-center pt-2 pb-1">
<span class="mdi mdi-google-maps"></span> Google Maps Cadastre layer example
</h4>
</div>
<section class="mx-auto w-75 card py-2 my-2">
<div class="row w-75 mx-auto pb-2">
<label for="layers">Choose a layer</label>
<select class="form-control" id="layers" onchange="change()">
<span class="mdi mdi-layers-minus"></span>
</select>
</div>
<div class="row mx-auto">
<button class="btn btn-primary mr-2" onclick="show()">
<span class="mdi mdi-layers-plus"></span>
Show layer
</button>
<button class="btn btn-secondary" onclick="hide()">
<span class="mdi mdi-layers-minus"></span>
Hide layer
</button>
</div>
<div class="row w-75 mx-auto">
<label for="customRange1">Opacity</label>
<input type="range" min="0" max="100" class="custom-range" id="opacity" onchange="show($(this).val()/100)">
</div>
<div class="w-75 mx-auto">
<h5 class="text-center" id="opacity_val"></h5>
</div>
</section>
<div>
<div class="input-group w-75 mx-auto pt-1 pb-1">
<input id="autocomplete" type="search" class="form-control" placeholder='Write the address to search...'>
<input id="refCad" type="search" class="form-control" minlength="14" maxlength="20"
placeholder='{% trans "clica el botó esquerre per tornar a la cerca per adreça" %}...' style="display:none;">
</div>
<div class="mx-auto w-75" style="height: 500px;" id="map"></div>
</div>
<script>
layers = [
"Catastro",
"CONSTRU",
"TXTCONSTRU",
"SUBPARCE",
"TXTSUBPARCE",
"PARCELA",
"TXTPARCELA",
"MASA",
"TXTMASA",
"EJES",
"LIMITES",
"TEXTOS",
"ELEMLIN"
]
var EXTENT = [-Math.PI * 6378137, Math.PI * 6378137];
function xyzToBounds(x, y, z) {
var tileSize = (EXTENT[1] * 2) / Math.pow(2, z);
var minx = EXTENT[0] + x * tileSize;
var maxx = EXTENT[0] + (x + 1) * tileSize;
// remember y origin starts at top
var miny = EXTENT[1] - (y + 1) * tileSize;
var maxy = EXTENT[1] - y * tileSize;
return [minx, miny, maxx, maxy];
}
var getTileUrl = function (coordinates, zoom) {
// console.log(coordinates.x, coordinates.y, zoom)
return (
"https://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?" +
"&REQUEST=GetMap&" +
// "&REQUEST=GETFEATUREINFO&"+
"SERVICE=WMS&VERSION=1.1.1" +
"&LAYERS=" + $("#layers").val() +
"&FORMAT=image%2Fpng" +
"&SRS=EPSG:3857&" +
// "TIME=2017-10-23&"+
"WIDTH=256&HEIGHT=256" +
"&BBOX=" +
xyzToBounds(coordinates.x, coordinates.y, zoom).join(",")
);
};
var map
var landcover
function change() {
hide()
show()
}
var getgetfeatureinfourl = function (coordinates, zoom) {
console.log(coordinates, zoom)
return (
"https://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?" +
// "&REQUEST=GETFEATUREINFO&"+
"SERVICE=WMS&VERSION=1.1.1" +
"&SRS=EPSG:3857&" +
// "TIME=2017-10-23&"+
"&BBOX=" +
xyzToBounds(coordinates.x, coordinates.y, zoom).join(",")
);
};
function show() {
$('#opacity_val').html($('#opacity').val() + "%")
if (map.overlayMapTypes.length == 0)
map.overlayMapTypes.push(landcover)
landcover.setOptions({
opacity: $('#opacity').val() / 100,
getTileUrl: getTileUrl,
})
}
function hide() {
if (map.overlayMapTypes.length > 0)
map.overlayMapTypes.clear()
else
console.warn("No overlay!")
}
function googleMapsCustomError() {
alert('Google Maps custom error triggered')
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
zoom: 18,
center: {
// lat: 42.034232,
// lng: 2.804443
lat: 41.983280,
lng: 2.814689
}
});
landcover = new google.maps.ImageMapType({
getTileUrl: getTileUrl,
name: "CATASTRO",
alt: "DIRECCION GENERAL DEL CATASTRO",
minZoom: 0,
maxZoom: 19,
opacity: 0.6,
});
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
(
document.getElementById('autocomplete')), {
componentRestrictions: {
country: 'es'
}
})
places = new google.maps.places.PlacesService(map)
autocomplete.addListener('place_changed', place_changed)
function place_changed() {
var place = autocomplete.getPlace()
map.panTo(place.geometry.location)
map.setZoom(20)
}
}
layers.forEach(e => {
$("#layers").append('<option value="' + e + '">' + e + '</option>')
})
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap&libraries=places&key=AIzaSyDixnAHIZiOX6-XmTkA_7DGAIC2Rn43URo">
</script>
<script>
</script>
</body>
</html>