vue-geojson-view-ts 1.3.13 → 1.3.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-geojson-view-ts",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -73,5 +73,6 @@
73
73
  "screenfull": "^6.0.2",
74
74
  "typewriter-effect": "^2.19.0",
75
75
  "vue-router": "^4.2.5"
76
- }
76
+ },
77
+ "packageManager": "yarn@4.5.3+sha512.3003a14012e2987072d244c720506549c1aab73ee728208f1b2580a9fd67b92d61ba6b08fe93f6dce68fd771e3af1e59a0afa28dd242dd0940d73b95fedd4e90"
77
78
  }
@@ -1,18 +1,17 @@
1
1
  <template>
2
2
  <div ref="maps" id="maps"></div>
3
3
  </template>
4
-
5
- <script lang="ts">
6
- import { markerDefault } from '../helpers/imgBase64'
7
4
 
8
- import { defineComponent } from 'vue';
9
- import * as L from 'leaflet';
10
- import 'leaflet/dist/leaflet.css';
11
- import * as turf from '@turf/turf';
12
- import { IconOptions } from 'leaflet';
13
- import 'leaflet.fullscreen/Control.FullScreen.css'
14
- import 'leaflet.fullscreen'
5
+ <script lang="ts">
6
+ import { markerDefault } from "../helpers/imgBase64";
15
7
 
8
+ import { defineComponent } from "vue";
9
+ import * as L from "leaflet";
10
+ import "leaflet/dist/leaflet.css";
11
+ import * as turf from "@turf/turf";
12
+ import { IconOptions } from "leaflet";
13
+ import "leaflet.fullscreen/Control.FullScreen.css";
14
+ import "leaflet.fullscreen";
16
15
 
17
16
  export default defineComponent({
18
17
  name: "CoordinatesVerifyPolygon",
@@ -20,7 +19,7 @@ export default defineComponent({
20
19
  dataPolygon: Object,
21
20
  iconMarker: Object,
22
21
  coordinatesMap: Array,
23
- checkPointInPolygon: Function
22
+ checkPointInPolygon: Function,
24
23
  },
25
24
  data() {
26
25
  return {
@@ -28,40 +27,60 @@ export default defineComponent({
28
27
  iconUrl: markerDefault,
29
28
  iconSize: [25, 41],
30
29
  iconAnchor: [12, 41],
31
- }
32
- }
30
+ },
31
+ };
33
32
  },
34
33
  mounted() {
35
34
  this.verificarPuntoEnPoligono();
36
35
  },
37
36
  methods: {
38
37
  verificarPuntoEnPoligono() {
39
- const iconDefaultMarket = this.iconMarker ? this.iconMarker : this.markerIconDefault
40
- const data = this.dataPolygon?.geometry.coordinates[0].map((e: number[]) => [e[1], e[0]]);
41
- const polygonCoordinates: L.LatLngExpression[] = JSON.parse(JSON.stringify(data))
42
- const pointCoordinates = [this.coordinatesMap ? this.coordinatesMap[0] as number : 0, this.coordinatesMap ? this.coordinatesMap[1] as number : 0];
43
- const map = L.map('maps', { fullscreenControl: true } as any).setView([this.coordinatesMap ? this.coordinatesMap[0] as number : 0, this.coordinatesMap ? this.coordinatesMap[1] as number : 0], this.coordinatesMap ? this.coordinatesMap[2] as number : 0);
44
- L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
38
+ const iconDefaultMarket = this.iconMarker
39
+ ? this.iconMarker
40
+ : this.markerIconDefault;
41
+ const data = this.dataPolygon?.geometry.coordinates[0].map(
42
+ (e: number[]) => [e[1], e[0]]
43
+ );
44
+ const polygonCoordinates: L.LatLngExpression[] = JSON.parse(
45
+ JSON.stringify(data)
46
+ );
47
+ const pointCoordinates = [
48
+ this.coordinatesMap ? (this.coordinatesMap[0] as number) : 0,
49
+ this.coordinatesMap ? (this.coordinatesMap[1] as number) : 0,
50
+ ];
51
+ const map = L.map("maps", { fullscreenControl: true } as any).setView(
52
+ [
53
+ this.coordinatesMap ? (this.coordinatesMap[0] as number) : 0,
54
+ this.coordinatesMap ? (this.coordinatesMap[1] as number) : 0,
55
+ ],
56
+ this.coordinatesMap ? (this.coordinatesMap[2] as number) : 0
57
+ );
58
+ L.tileLayer("https://tile.openstreetmaps.org/{z}/{x}/{y}.png", {
45
59
  maxZoom: 19,
46
- attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
47
- }).addTo(map)
60
+ attribution:
61
+ '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
62
+ }).addTo(map);
48
63
  L.polygon(polygonCoordinates).addTo(map);
49
- const markerCoordinates: L.LatLngExpression = [this.coordinatesMap ? this.coordinatesMap[0] as number : 0, this.coordinatesMap ? this.coordinatesMap[1] as number : 0];
64
+ const markerCoordinates: L.LatLngExpression = [
65
+ this.coordinatesMap ? (this.coordinatesMap[0] as number) : 0,
66
+ this.coordinatesMap ? (this.coordinatesMap[1] as number) : 0,
67
+ ];
50
68
  const markerIcon = L.icon(iconDefaultMarket as IconOptions);
51
69
  L.marker(markerCoordinates, { icon: markerIcon }).addTo(map);
52
70
  const pointGeoJSON = turf.point(pointCoordinates);
53
71
  const polygonGeoJSON = turf.polygon([data]);
54
- const isPointInside = turf.booleanPointInPolygon(pointGeoJSON, polygonGeoJSON);
55
- if (this.checkPointInPolygon)
56
- this.checkPointInPolygon(isPointInside)
57
- }
58
- }
72
+ const isPointInside = turf.booleanPointInPolygon(
73
+ pointGeoJSON,
74
+ polygonGeoJSON
75
+ );
76
+ if (this.checkPointInPolygon) this.checkPointInPolygon(isPointInside);
77
+ },
78
+ },
59
79
  });
60
80
  </script>
61
-
81
+
62
82
  <style>
63
83
  #maps {
64
84
  height: 500px;
65
85
  }
66
86
  </style>
67
-
@@ -233,7 +233,10 @@ export default defineComponent({
233
233
  format: new GeoJSON(),
234
234
  }),
235
235
  style: function (feature) {
236
- style.getText().setText(feature.get("name"));
236
+ const textStyle = style.getText();
237
+ if (textStyle) {
238
+ textStyle.setText(feature.get("name"));
239
+ }
237
240
  return style;
238
241
  },
239
242
  });
@@ -18,6 +18,8 @@ import drawLocales from "leaflet-draw-locales";
18
18
  import axios from "axios";
19
19
  import "leaflet.fullscreen/Control.FullScreen.css";
20
20
  import "leaflet.fullscreen";
21
+ import gpsIcon from "../assets/gps.svg";
22
+ import sateliteIcon from "../assets/satelite.svg";
21
23
 
22
24
  declare global {
23
25
  interface Window {
@@ -69,6 +71,7 @@ export default defineComponent({
69
71
  coordinatesMap: Array,
70
72
  getGeoJSON: Function,
71
73
  getCoodMarker: Function,
74
+ isSatelite: Boolean,
72
75
  },
73
76
  data() {
74
77
  return {
@@ -84,6 +87,8 @@ export default defineComponent({
84
87
  },
85
88
  layersFeatureGroup: null as any,
86
89
  featuresData: null as any,
90
+ currentTileLayer: null as L.TileLayer | null,
91
+ isSatelliteView: false,
87
92
  };
88
93
  },
89
94
  mounted() {
@@ -91,6 +96,79 @@ export default defineComponent({
91
96
  this.renderMap();
92
97
  },
93
98
  methods: {
99
+ createSatelliteControl(): L.Control {
100
+ const SatelliteControl = L.Control.extend({
101
+ onAdd: (map: L.Map) => {
102
+ const container = L.DomUtil.create(
103
+ "div",
104
+ "leaflet-bar leaflet-control leaflet-control-custom"
105
+ );
106
+
107
+ container.style.backgroundColor = "white";
108
+ container.style.width = "30px";
109
+ container.style.height = "30px";
110
+ container.style.cursor = "pointer";
111
+ container.style.marginTop = "10px"; // Margen superior para separar de otros controles
112
+ container.style.backgroundImage = this.isSatelliteView
113
+ ? `url(${gpsIcon})`
114
+ : `url(${sateliteIcon})`;
115
+ container.style.backgroundPosition = "center";
116
+ container.style.backgroundRepeat = "no-repeat";
117
+ container.style.backgroundSize = "20px 20px";
118
+ container.title = this.isSatelliteView
119
+ ? "Vista Normal"
120
+ : "Vista Satélite";
121
+
122
+ L.DomEvent.disableClickPropagation(container);
123
+ L.DomEvent.on(container, "click", this.toggleSatelliteView, this);
124
+
125
+ return container;
126
+ },
127
+ });
128
+
129
+ return new SatelliteControl({ position: "topleft" });
130
+ },
131
+ toggleSatelliteView(): void {
132
+ if (!this.mapRender || !this.currentTileLayer) return;
133
+
134
+ this.isSatelliteView = !this.isSatelliteView;
135
+
136
+ // Remover la capa actual
137
+ this.mapRender.removeLayer(this.currentTileLayer as unknown as L.Layer);
138
+
139
+ // Agregar la nueva capa
140
+ if (this.isSatelliteView) {
141
+ this.currentTileLayer = L.tileLayer(
142
+ "https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=t8mWT2ozs1JWBqMZOnZr",
143
+ {
144
+ attribution:
145
+ '&copy; <a href="https://www.maptiler.com/">MapTiler</a> &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
146
+ }
147
+ );
148
+ } else {
149
+ this.currentTileLayer = L.tileLayer(
150
+ "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
151
+ {
152
+ attribution:
153
+ '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
154
+ }
155
+ );
156
+ }
157
+
158
+ this.currentTileLayer.addTo(this.mapRender as L.Map);
159
+
160
+ // Actualizar el ícono del control
161
+ const controls = document.querySelectorAll(".leaflet-control-custom");
162
+ controls.forEach((control) => {
163
+ const htmlControl = control as HTMLElement;
164
+ htmlControl.style.backgroundImage = this.isSatelliteView
165
+ ? `url(${gpsIcon})`
166
+ : `url(${sateliteIcon})`;
167
+ htmlControl.title = this.isSatelliteView
168
+ ? "Vista Normal"
169
+ : "Vista Satélite";
170
+ });
171
+ },
94
172
  getLayersFeaturesInGeoJson() {
95
173
  const geojson = L.geoJSON().addTo(this.mapRender as any);
96
174
  this.featuresData.eachLayer((layer: any) => {
@@ -147,11 +225,34 @@ export default defineComponent({
147
225
  this.renderCoordinates ? (this.renderCoordinates[2] as number) : 0
148
226
  );
149
227
  this.mapRender = map;
150
- L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
151
- //maxZoom: this.configurationMap?.maxZoom,
152
- attribution:
153
- '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
154
- }).addTo(map);
228
+
229
+ // Inicializar con la vista correcta según el prop
230
+ this.isSatelliteView = this.isSatelite || false;
231
+ if (this.isSatelliteView) {
232
+ this.currentTileLayer = L.tileLayer(
233
+ "https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=t8mWT2ozs1JWBqMZOnZr",
234
+ {
235
+ attribution:
236
+ '&copy; <a href="https://www.maptiler.com/">MapTiler</a> &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
237
+ }
238
+ );
239
+ } else {
240
+ this.currentTileLayer = L.tileLayer(
241
+ "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
242
+ {
243
+ attribution:
244
+ '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
245
+ }
246
+ );
247
+ }
248
+ this.currentTileLayer.addTo(map);
249
+
250
+ // Agregar el control satelital si está habilitado
251
+ if (this.isSatelite !== undefined) {
252
+ const satelliteControl = this.createSatelliteControl();
253
+ map.addControl(satelliteControl);
254
+ }
255
+
155
256
  map.setZoom(this.configurationMap?.maxZoom);
156
257
  if (this.configurationMap.renderMarker) {
157
258
  const marker = L.marker(
@@ -279,10 +380,34 @@ export default defineComponent({
279
380
  this.renderCoordinates ? (this.renderCoordinates[2] as number) : 0
280
381
  );
281
382
  this.mapRender = map;
282
- L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
283
- attribution:
284
- '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
285
- }).addTo(map);
383
+
384
+ // Inicializar con la vista correcta según el prop
385
+ this.isSatelliteView = this.isSatelite || false;
386
+ if (this.isSatelliteView) {
387
+ this.currentTileLayer = L.tileLayer(
388
+ "https://api.maptiler.com/maps/satellite/{z}/{x}/{y}.jpg?key=t8mWT2ozs1JWBqMZOnZr",
389
+ {
390
+ attribution:
391
+ '&copy; <a href="https://www.maptiler.com/">MapTiler</a> &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
392
+ }
393
+ );
394
+ } else {
395
+ this.currentTileLayer = L.tileLayer(
396
+ "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
397
+ {
398
+ attribution:
399
+ '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
400
+ }
401
+ );
402
+ }
403
+ this.currentTileLayer.addTo(map);
404
+
405
+ // Agregar el control satelital si está habilitado
406
+ if (this.isSatelite !== undefined) {
407
+ const satelliteControl = this.createSatelliteControl();
408
+ map.addControl(satelliteControl);
409
+ }
410
+
286
411
  map.setZoom(this.configurationMap?.maxZoom);
287
412
  const featuresData = L.featureGroup();
288
413
  this.featuresData = featuresData;
@@ -1,56 +0,0 @@
1
- import * as L from "leaflet";
2
- declare global {
3
- interface Window {
4
- type: boolean;
5
- }
6
- }
7
- declare const _sfc_main: import("vue").DefineComponent<{
8
- loadPolygon: BooleanConstructor;
9
- reverseCoordinatesPolygon: BooleanConstructor;
10
- dataPolygon: ObjectConstructor;
11
- configurationMap: any;
12
- coordinatesMap: ArrayConstructor;
13
- getGeoJSON: FunctionConstructor;
14
- getCoodMarker: FunctionConstructor;
15
- }, unknown, {
16
- idMap: string;
17
- mapRender: L.Map | null;
18
- markerRender: L.Marker<any> | null;
19
- renderCoordinates: unknown[] | undefined;
20
- renderGeojson: any;
21
- markerIcon: {
22
- iconUrl: string;
23
- iconSize: number[];
24
- iconAnchor: number[];
25
- };
26
- layersFeatureGroup: any;
27
- featuresData: any;
28
- }, {}, {
29
- getLayersFeaturesInGeoJson(): (import("geojson").GeometryCollection<import("geojson").Geometry> | import("geojson").FeatureCollection<import("geojson").Geometry, any> | import("geojson").Feature<import("geojson").MultiPoint, any>)[];
30
- triggerSaveEdit(): void;
31
- makeid(length: number): void;
32
- renderMap(): void;
33
- createMap(): void;
34
- viewMap(): void;
35
- getPointToLayer(feature: any, latlng: any): L.Marker<any>;
36
- searchAddress(query: string): Promise<any>;
37
- setCoordinates({ lat, lng, }: {
38
- lat: number;
39
- lng: number;
40
- moveMarker?: boolean | undefined;
41
- }): void;
42
- getPopupContent(feature: any): string;
43
- }, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
44
- loadPolygon: BooleanConstructor;
45
- reverseCoordinatesPolygon: BooleanConstructor;
46
- dataPolygon: ObjectConstructor;
47
- configurationMap: any;
48
- coordinatesMap: ArrayConstructor;
49
- getGeoJSON: FunctionConstructor;
50
- getCoodMarker: FunctionConstructor;
51
- }>>, {
52
- loadPolygon: boolean;
53
- reverseCoordinatesPolygon: boolean;
54
- configurationMap: any;
55
- }, {}>;
56
- export default _sfc_main;