Skip to content

Commit

Permalink
minor performance tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
razorness committed Feb 12, 2024
1 parent e5e190d commit d5d55f7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-maplibre-gl",
"version": "3.1.2",
"version": "3.1.3",
"description": "Vue 3 plugin for maplibre-gl",
"keywords": [
"vue",
Expand Down
6 changes: 1 addition & 5 deletions src/lib/components/sources/canvas.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ export default /*#__PURE__*/ defineComponent({
useSource<CanvasSourceSpecification>(source, props, 'canvas', sourceOpts, registry);

watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => {
if (isRef(v) && v.value) {
source.value?.setCoordinates(v.value as Coordinates);
} else if (v) {
source.value?.setCoordinates(v as Coordinates);
}
source.value?.setCoordinates(v as Coordinates);
}, { immediate: true });

return () => [
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/sources/geojson.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const sourceOpts = AllSourceOptions<GeoJSONSourceSpecification>({
filter : undefined,
});

type DataType = GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry> | string;


export default /*#__PURE__*/ defineComponent({
name : 'MglGeoJsonSource',
Expand All @@ -31,7 +33,7 @@ export default /*#__PURE__*/ defineComponent({
type : String as PropType<string>,
required: true
},
data : [ Object, String ] as PropType<GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry> | string>,
data : [ Object, String ] as PropType<DataType>,
maxzoom : Number as PropType<number>,
attribution : String as PropType<string>,
buffer : Number as PropType<number>,
Expand Down Expand Up @@ -59,9 +61,7 @@ export default /*#__PURE__*/ defineComponent({
useSource<GeoJSONSourceOptions>(source, props, 'geojson', sourceOpts, registry);

watch(isRef(props.data) ? props.data : () => props.data, v => {
source.value?.setData(isRef(v) ? (v.value || { type: 'FeatureCollection', features: [] }) : (v as any || {
type: 'FeatureCollection', features: []
}));
source.value?.setData(v as DataType || { type: 'FeatureCollection', features: [] });
}, { immediate: true });

return () => [
Expand Down
6 changes: 1 addition & 5 deletions src/lib/components/sources/image.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export default /*#__PURE__*/ defineComponent({
useSource<ImageSourceSpecification>(source, props, 'image', sourceOpts, registry);

watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => {
if (isRef(v) && v.value) {
source.value?.setCoordinates(v.value as Coordinates);
} else if (v) {
source.value?.setCoordinates(v as Coordinates);
}
source.value?.setCoordinates(v as Coordinates);
}, { immediate: true });

return () => [
Expand Down
12 changes: 2 additions & 10 deletions src/lib/components/sources/vector.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,10 @@ export default /*#__PURE__*/ defineComponent({
useSource<VectorSourceSpecification>(source, props, 'vector', sourceOpts, registry);

watch(isRef(props.tiles) ? props.tiles : () => props.tiles, v => {
if (isRef(v)) {
source.value?.setTiles(v.value as string[] || [])
} else {
source.value?.setTiles(v as string[] || [])
}
source.value?.setTiles(v as string[] || [])
}, { immediate: true });
watch(isRef(props.url) ? props.url: () => props.url, v => {
if (isRef(v)) {
source.value?.setUrl(v.value as string || '')
} else {
source.value?.setUrl(v as string || '')
}
source.value?.setUrl(v as string || '')
}, { immediate: true });

return () => [
Expand Down
6 changes: 1 addition & 5 deletions src/lib/components/sources/video.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export default /*#__PURE__*/ defineComponent({
useSource<VideoSourceSpecification>(source, props, 'video', sourceOpts, registry);

watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => {
if (isRef(v) && v.value) {
source.value?.setCoordinates(v.value as Coordinates);
} else if (v) {
source.value?.setCoordinates(v as Coordinates);
}
source.value?.setCoordinates(v as Coordinates);
}, { immediate: true });

return () => [
Expand Down

0 comments on commit d5d55f7

Please sign in to comment.