vue-geojson-view-ts 1.3.1 → 1.3.2
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/dist/components/MapHeatComponent.vue.d.ts +118 -0
- package/dist/index.d.ts +4 -2
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/vue-geojson-view-ts.js +3192 -2935
- package/dist/vue-geojson-view-ts.umd.cjs +10 -8
- package/package.json +4 -2
- package/src/components/MapHeatComponent.vue +217 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-geojson-view-ts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -58,14 +58,16 @@
|
|
|
58
58
|
"@types/crypto-js": "^4.1.1",
|
|
59
59
|
"@types/leaflet": "^1.9.3",
|
|
60
60
|
"@types/leaflet-draw": "^1.0.6",
|
|
61
|
+
"@types/leaflet.heat": "^0.2.2",
|
|
61
62
|
"@vue-leaflet/vue-leaflet": "^0.9.0",
|
|
62
63
|
"axios": "^1.4.0",
|
|
63
64
|
"copy-webpack-plugin": "^11.0.0",
|
|
64
65
|
"crypto-js": "^4.1.1",
|
|
65
|
-
"leaflet": "1.9.
|
|
66
|
+
"leaflet": "^1.9.4",
|
|
66
67
|
"leaflet-draw": "^1.0.4",
|
|
67
68
|
"leaflet-draw-locales": "^1.2.2",
|
|
68
69
|
"leaflet.fullscreen": "^2.4.0",
|
|
70
|
+
"leaflet.heat": "^0.2.0",
|
|
69
71
|
"screenfull": "^6.0.2",
|
|
70
72
|
"typewriter-effect": "^2.19.0"
|
|
71
73
|
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="map-container" :style="`height:${configurationMap?.height}`">
|
|
3
|
+
<div :id="idMap" style="height: 100%"></div>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import * as L from "leaflet";
|
|
9
|
+
import "leaflet/dist/leaflet.css";
|
|
10
|
+
import { onMounted, ref } from "vue";
|
|
11
|
+
import { markerDefault } from "../helpers/imgBase64";
|
|
12
|
+
import "leaflet.fullscreen/Control.FullScreen.css";
|
|
13
|
+
import "leaflet.fullscreen";
|
|
14
|
+
import "leaflet.heat";
|
|
15
|
+
|
|
16
|
+
export type TIconMaker = {
|
|
17
|
+
iconUrl: string;
|
|
18
|
+
iconSize: [number, number];
|
|
19
|
+
iconAnchor: [number, number];
|
|
20
|
+
class?: string;
|
|
21
|
+
type: "image" | "svg";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export interface IConfigurationMap {
|
|
25
|
+
height: string;
|
|
26
|
+
maxZoom: number;
|
|
27
|
+
iconMarker: TIconMaker;
|
|
28
|
+
dragMarker: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ICoords {
|
|
32
|
+
lat: number;
|
|
33
|
+
lng: number;
|
|
34
|
+
zoom: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IHeat {
|
|
38
|
+
lat: number;
|
|
39
|
+
lng: number;
|
|
40
|
+
intensidad: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface IMapSearchAddressProps {
|
|
44
|
+
configurationMap?: IConfigurationMap;
|
|
45
|
+
coordinatesMap?: ICoords;
|
|
46
|
+
coordinatesMapHeat?: IHeat[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const props = withDefaults(defineProps<IMapSearchAddressProps>(), {
|
|
50
|
+
configurationMap: () => {
|
|
51
|
+
return {
|
|
52
|
+
height: "250px",
|
|
53
|
+
maxZoom: 20,
|
|
54
|
+
iconMarker: {
|
|
55
|
+
iconUrl: markerDefault,
|
|
56
|
+
iconSize: [25, 41],
|
|
57
|
+
iconAnchor: [12, 41],
|
|
58
|
+
class: "",
|
|
59
|
+
type: "image",
|
|
60
|
+
},
|
|
61
|
+
dragMarker: true,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
coordinatesMap: () => {
|
|
65
|
+
return {
|
|
66
|
+
lat: -19.0429,
|
|
67
|
+
lng: -65.2554,
|
|
68
|
+
zoom: 12,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
coordinatesMapHeat: () => {
|
|
72
|
+
return [];
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const emit = defineEmits(["updated:coordsMarker"]);
|
|
77
|
+
|
|
78
|
+
const idMap = ref();
|
|
79
|
+
const coords = ref(props.coordinatesMap);
|
|
80
|
+
const mapRender = ref();
|
|
81
|
+
const markerRender = ref();
|
|
82
|
+
|
|
83
|
+
onMounted(async () => {
|
|
84
|
+
await makeid(10);
|
|
85
|
+
await renderMap();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const makeid = async (length: number) => {
|
|
89
|
+
let result = "";
|
|
90
|
+
const characters = "abcdefghijklmnopqrstuvwxyz";
|
|
91
|
+
const charactersLength = characters.length;
|
|
92
|
+
let counter = 0;
|
|
93
|
+
while (counter < length) {
|
|
94
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
95
|
+
counter += 1;
|
|
96
|
+
}
|
|
97
|
+
idMap.value = result;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const renderMap = async () => {
|
|
101
|
+
await createMap();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const createMap = async () => {
|
|
105
|
+
const iconMarker = props.configurationMap?.iconMarker;
|
|
106
|
+
const map = L.map(idMap.value, { fullscreenControl: true } as any).setView(
|
|
107
|
+
[coords.value.lat, coords.value.lng],
|
|
108
|
+
coords.value.zoom
|
|
109
|
+
);
|
|
110
|
+
map.invalidateSize();
|
|
111
|
+
mapRender.value = map;
|
|
112
|
+
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
|
113
|
+
maxZoom: props.configurationMap?.maxZoom,
|
|
114
|
+
attribution:
|
|
115
|
+
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
|
116
|
+
}).addTo(map);
|
|
117
|
+
|
|
118
|
+
const heatMap: any[] = props.coordinatesMapHeat.map((item: any) => [
|
|
119
|
+
item.lat,
|
|
120
|
+
item.lng,
|
|
121
|
+
item.intensidad,
|
|
122
|
+
]);
|
|
123
|
+
L.heatLayer(heatMap, { radius: 25 }).addTo(map);
|
|
124
|
+
|
|
125
|
+
if (iconMarker.type === "image") {
|
|
126
|
+
const marker = L.marker([coords.value.lat, coords.value.lng], {
|
|
127
|
+
icon: L.icon({
|
|
128
|
+
iconUrl: iconMarker.iconUrl,
|
|
129
|
+
iconAnchor: iconMarker.iconAnchor,
|
|
130
|
+
iconSize: iconMarker.iconSize,
|
|
131
|
+
className: iconMarker.class,
|
|
132
|
+
}),
|
|
133
|
+
draggable: props.configurationMap.dragMarker,
|
|
134
|
+
}).addTo(map);
|
|
135
|
+
markerRender.value = marker;
|
|
136
|
+
marker.on("dragend", (event) => {
|
|
137
|
+
const updatedCoordinates = event.target.getLatLng();
|
|
138
|
+
const lat = updatedCoordinates.lat;
|
|
139
|
+
const lng = updatedCoordinates.lng;
|
|
140
|
+
setCoordinates({
|
|
141
|
+
lat,
|
|
142
|
+
lng,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
} else if (iconMarker.type === "svg") {
|
|
146
|
+
const marker = L.marker([coords.value.lat, coords.value.lng], {
|
|
147
|
+
icon: L.divIcon({
|
|
148
|
+
html: iconMarker.iconUrl,
|
|
149
|
+
iconAnchor: iconMarker.iconAnchor,
|
|
150
|
+
iconSize: iconMarker.iconSize,
|
|
151
|
+
className: iconMarker.class,
|
|
152
|
+
}),
|
|
153
|
+
draggable: props.configurationMap.dragMarker,
|
|
154
|
+
}).addTo(map);
|
|
155
|
+
markerRender.value = marker;
|
|
156
|
+
marker.on("dragend", (event) => {
|
|
157
|
+
const updatedCoordinates = event.target.getLatLng();
|
|
158
|
+
const lat = updatedCoordinates.lat;
|
|
159
|
+
const lng = updatedCoordinates.lng;
|
|
160
|
+
setCoordinates({
|
|
161
|
+
lat,
|
|
162
|
+
lng,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const searchAddress = async (query: string) => {
|
|
169
|
+
// const address = await axios.get(
|
|
170
|
+
// location.protocol + "//nominatim.openstreetmap.org/search?",
|
|
171
|
+
// {
|
|
172
|
+
// params: {
|
|
173
|
+
// //query
|
|
174
|
+
// q: query,
|
|
175
|
+
// limit: 1,
|
|
176
|
+
// format: "json",
|
|
177
|
+
// },
|
|
178
|
+
// }
|
|
179
|
+
// );
|
|
180
|
+
// if (address.data.length === 1) {
|
|
181
|
+
// const lat = parseFloat(address.data[0].lat);
|
|
182
|
+
// const lng = parseFloat(address.data[0].lon);
|
|
183
|
+
// const coord = { lng, lat };
|
|
184
|
+
// setCoordinates({ ...coord, moveMarker: true });
|
|
185
|
+
// return address.data[0];
|
|
186
|
+
// }
|
|
187
|
+
// return address.data;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const setCoordinates = ({
|
|
191
|
+
lat,
|
|
192
|
+
lng,
|
|
193
|
+
moveMarker = false,
|
|
194
|
+
}: {
|
|
195
|
+
lat: number;
|
|
196
|
+
lng: number;
|
|
197
|
+
moveMarker?: boolean;
|
|
198
|
+
}) => {
|
|
199
|
+
emit("updated:coordsMarker", {
|
|
200
|
+
lat,
|
|
201
|
+
lng,
|
|
202
|
+
});
|
|
203
|
+
if (moveMarker) markerRender.value?.setLatLng({ lat, lng });
|
|
204
|
+
moveCenterTo({ lat, lng });
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const moveCenterTo = ({ lat, lng }: { lat: number; lng: number }) => {
|
|
208
|
+
const newCenter = L.latLng(lat, lng);
|
|
209
|
+
mapRender.value.panTo(newCenter, { animate: true, duration: 0.5 });
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
defineExpose({
|
|
213
|
+
searchAddress,
|
|
214
|
+
});
|
|
215
|
+
</script>
|
|
216
|
+
|
|
217
|
+
<style lang="scss"></style>
|