vue-geojson-view-ts 1.3.14 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -9,9 +9,11 @@ import * as L from "leaflet";
|
|
|
9
9
|
import "leaflet/dist/leaflet.css";
|
|
10
10
|
import { onMounted, ref } from "vue";
|
|
11
11
|
import { markerDefault } from "../helpers/imgBase64";
|
|
12
|
-
import
|
|
13
|
-
import
|
|
12
|
+
import "leaflet.fullscreen/Control.FullScreen.css";
|
|
13
|
+
import "leaflet.fullscreen";
|
|
14
14
|
import axios from "axios";
|
|
15
|
+
import gpsIcon from "../assets/gps.svg";
|
|
16
|
+
import sateliteIcon from "../assets/satelite.svg";
|
|
15
17
|
|
|
16
18
|
export type TIconMaker = {
|
|
17
19
|
iconUrl: string;
|
|
@@ -37,6 +39,7 @@ export interface ICoords {
|
|
|
37
39
|
export interface IMapSearchAddressProps {
|
|
38
40
|
configurationMap?: IConfigurationMap;
|
|
39
41
|
coordinatesMap?: ICoords;
|
|
42
|
+
isSatelite?: boolean;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
const props = withDefaults(defineProps<IMapSearchAddressProps>(), {
|
|
@@ -69,6 +72,8 @@ const idMap = ref();
|
|
|
69
72
|
const coords = ref(props.coordinatesMap);
|
|
70
73
|
const mapRender = ref();
|
|
71
74
|
const markerRender = ref();
|
|
75
|
+
const currentTileLayer = ref<L.TileLayer | null>(null);
|
|
76
|
+
const isSatelliteView = ref(false);
|
|
72
77
|
|
|
73
78
|
onMounted(async () => {
|
|
74
79
|
await makeid(10);
|
|
@@ -93,17 +98,40 @@ const renderMap = async () => {
|
|
|
93
98
|
|
|
94
99
|
const createMap = async () => {
|
|
95
100
|
const iconMarker = props.configurationMap?.iconMarker;
|
|
96
|
-
const map = L.map(idMap.value,{fullscreenControl:true} as any).setView(
|
|
101
|
+
const map = L.map(idMap.value, { fullscreenControl: true } as any).setView(
|
|
97
102
|
[coords.value.lat, coords.value.lng],
|
|
98
103
|
coords.value.zoom
|
|
99
104
|
);
|
|
100
105
|
map.invalidateSize();
|
|
101
106
|
mapRender.value = map;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
|
|
108
|
+
// Inicializar con la vista correcta según el prop
|
|
109
|
+
isSatelliteView.value = props.isSatelite || false;
|
|
110
|
+
if (isSatelliteView.value) {
|
|
111
|
+
currentTileLayer.value = L.tileLayer(
|
|
112
|
+
"https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=t8mWT2ozs1JWBqMZOnZr",
|
|
113
|
+
{
|
|
114
|
+
attribution:
|
|
115
|
+
'© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
currentTileLayer.value = L.tileLayer(
|
|
120
|
+
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
|
121
|
+
{
|
|
122
|
+
maxZoom: props.configurationMap?.maxZoom,
|
|
123
|
+
attribution:
|
|
124
|
+
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
currentTileLayer.value.addTo(map);
|
|
129
|
+
|
|
130
|
+
// Agregar el control satelital si está habilitado
|
|
131
|
+
if (props.isSatelite !== undefined) {
|
|
132
|
+
const satelliteControl = createSatelliteControl();
|
|
133
|
+
map.addControl(satelliteControl);
|
|
134
|
+
}
|
|
107
135
|
|
|
108
136
|
if (iconMarker.type === "image") {
|
|
109
137
|
const marker = L.marker([coords.value.lat, coords.value.lng], {
|
|
@@ -148,6 +176,87 @@ const createMap = async () => {
|
|
|
148
176
|
}
|
|
149
177
|
};
|
|
150
178
|
|
|
179
|
+
const createSatelliteControl = (): L.Control => {
|
|
180
|
+
const SatelliteControl = L.Control.extend({
|
|
181
|
+
onAdd: (map: L.Map) => {
|
|
182
|
+
const container = L.DomUtil.create(
|
|
183
|
+
"div",
|
|
184
|
+
"leaflet-control-draw leaflet-bar leaflet-control"
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const satelliteButton = L.DomUtil.create(
|
|
188
|
+
"a",
|
|
189
|
+
"leaflet-draw-draw-satellite",
|
|
190
|
+
container
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
satelliteButton.href = "#";
|
|
194
|
+
satelliteButton.title = isSatelliteView.value
|
|
195
|
+
? "Vista Normal"
|
|
196
|
+
: "Vista Satélite";
|
|
197
|
+
|
|
198
|
+
// Usar el mismo estilo que los otros botones de draw
|
|
199
|
+
satelliteButton.style.backgroundImage = isSatelliteView.value
|
|
200
|
+
? `url(${gpsIcon})`
|
|
201
|
+
: `url(${sateliteIcon})`;
|
|
202
|
+
satelliteButton.style.backgroundPosition = "center";
|
|
203
|
+
satelliteButton.style.backgroundRepeat = "no-repeat";
|
|
204
|
+
satelliteButton.style.backgroundSize = "20px 20px";
|
|
205
|
+
|
|
206
|
+
L.DomEvent.disableClickPropagation(satelliteButton);
|
|
207
|
+
L.DomEvent.on(satelliteButton, "click", toggleSatelliteView);
|
|
208
|
+
|
|
209
|
+
return container;
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return new SatelliteControl({ position: "topleft" });
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const toggleSatelliteView = (): void => {
|
|
217
|
+
if (!mapRender.value || !currentTileLayer.value) return;
|
|
218
|
+
|
|
219
|
+
isSatelliteView.value = !isSatelliteView.value;
|
|
220
|
+
|
|
221
|
+
// Remover la capa actual
|
|
222
|
+
mapRender.value.removeLayer(currentTileLayer.value as unknown as L.Layer);
|
|
223
|
+
|
|
224
|
+
// Agregar la nueva capa
|
|
225
|
+
if (isSatelliteView.value) {
|
|
226
|
+
currentTileLayer.value = L.tileLayer(
|
|
227
|
+
"https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=t8mWT2ozs1JWBqMZOnZr",
|
|
228
|
+
{
|
|
229
|
+
attribution:
|
|
230
|
+
'© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
} else {
|
|
234
|
+
currentTileLayer.value = L.tileLayer(
|
|
235
|
+
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
|
236
|
+
{
|
|
237
|
+
attribution:
|
|
238
|
+
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
currentTileLayer.value.addTo(mapRender.value as L.Map);
|
|
244
|
+
|
|
245
|
+
// Actualizar el ícono del control satelital
|
|
246
|
+
const satelliteButtons = document.querySelectorAll(
|
|
247
|
+
".leaflet-draw-draw-satellite"
|
|
248
|
+
);
|
|
249
|
+
satelliteButtons.forEach((button) => {
|
|
250
|
+
const htmlButton = button as HTMLElement;
|
|
251
|
+
htmlButton.style.backgroundImage = isSatelliteView.value
|
|
252
|
+
? `url(${gpsIcon})`
|
|
253
|
+
: `url(${sateliteIcon})`;
|
|
254
|
+
htmlButton.title = isSatelliteView.value
|
|
255
|
+
? "Vista Normal"
|
|
256
|
+
: "Vista Satélite";
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
151
260
|
const searchAddress = async (query: string) => {
|
|
152
261
|
const address = await axios.get(
|
|
153
262
|
location.protocol + "//nominatim.openstreetmap.org/search?",
|
|
@@ -101,26 +101,35 @@ export default defineComponent({
|
|
|
101
101
|
onAdd: (map: L.Map) => {
|
|
102
102
|
const container = L.DomUtil.create(
|
|
103
103
|
"div",
|
|
104
|
-
"leaflet-
|
|
104
|
+
"leaflet-control-draw leaflet-bar leaflet-control"
|
|
105
105
|
);
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
container.style.backgroundPosition = "center";
|
|
116
|
-
container.style.backgroundRepeat = "no-repeat";
|
|
117
|
-
container.style.backgroundSize = "20px 20px";
|
|
118
|
-
container.title = this.isSatelliteView
|
|
107
|
+
const satelliteButton = L.DomUtil.create(
|
|
108
|
+
"a",
|
|
109
|
+
"leaflet-draw-draw-satellite",
|
|
110
|
+
container
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
satelliteButton.href = "#";
|
|
114
|
+
satelliteButton.title = this.isSatelliteView
|
|
119
115
|
? "Vista Normal"
|
|
120
116
|
: "Vista Satélite";
|
|
121
117
|
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
// Usar el mismo estilo que los otros botones de draw
|
|
119
|
+
satelliteButton.style.backgroundImage = this.isSatelliteView
|
|
120
|
+
? `url(${gpsIcon})`
|
|
121
|
+
: `url(${sateliteIcon})`;
|
|
122
|
+
satelliteButton.style.backgroundPosition = "center";
|
|
123
|
+
satelliteButton.style.backgroundRepeat = "no-repeat";
|
|
124
|
+
satelliteButton.style.backgroundSize = "20px 20px";
|
|
125
|
+
|
|
126
|
+
L.DomEvent.disableClickPropagation(satelliteButton);
|
|
127
|
+
L.DomEvent.on(
|
|
128
|
+
satelliteButton,
|
|
129
|
+
"click",
|
|
130
|
+
this.toggleSatelliteView,
|
|
131
|
+
this
|
|
132
|
+
);
|
|
124
133
|
|
|
125
134
|
return container;
|
|
126
135
|
},
|
|
@@ -157,14 +166,16 @@ export default defineComponent({
|
|
|
157
166
|
|
|
158
167
|
this.currentTileLayer.addTo(this.mapRender as L.Map);
|
|
159
168
|
|
|
160
|
-
// Actualizar el ícono del control
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
// Actualizar el ícono del control satelital
|
|
170
|
+
const satelliteButtons = document.querySelectorAll(
|
|
171
|
+
".leaflet-draw-draw-satellite"
|
|
172
|
+
);
|
|
173
|
+
satelliteButtons.forEach((button) => {
|
|
174
|
+
const htmlButton = button as HTMLElement;
|
|
175
|
+
htmlButton.style.backgroundImage = this.isSatelliteView
|
|
165
176
|
? `url(${gpsIcon})`
|
|
166
177
|
: `url(${sateliteIcon})`;
|
|
167
|
-
|
|
178
|
+
htmlButton.title = this.isSatelliteView
|
|
168
179
|
? "Vista Normal"
|
|
169
180
|
: "Vista Satélite";
|
|
170
181
|
});
|