Skip to content

Commit

Permalink
improved for build time
Browse files Browse the repository at this point in the history
Signed-off-by: Aleem Isiaka <[email protected]>
  • Loading branch information
limistah committed Jan 19, 2024
1 parent b7ab90e commit 2d48a61
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/components/Map/objects/BaseMapObject.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect } from 'react';
import { useContext, useEffect } from 'react';
import { MapContext } from '../../../contexts/map';
import { IHMapState } from '../Map';
import { initMapObjectEvents } from '../../libs/initMapObjectEvents';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Map/objects/Marker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const HMapMarker = (props: IHMapMarkerProps) => {
}
const initFn = useCallback(() => {
const { coords, options, icon } = props;
const _options = { ...options };
const _options: H.map.Marker.Options | undefined = { ...options };
if (icon) _options.icon = new H.map.Icon(icon);
return new H.map.Marker(coords, _options);
}, [props.coords]);
Expand Down
41 changes: 18 additions & 23 deletions src/components/Map/objects/Polygon/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useCallback } from 'react';
import { initMapObjectEvents } from '../../../libs/initMapObjectEvents';
import { mapEvents } from '../../../libs/defaults';
import { BaseMapObject } from '../BaseMapObject';
import { IHMapState } from '../../Map';
import React from 'react';

export interface IHMapPolygonProps {
Expand All @@ -18,29 +16,26 @@ export const HMapPolygon = (props: IHMapPolygonProps) => {
'points should be an array of objects containing lat and lng properties'
);
}
const initFn = useCallback(
(mapContext: IHMapState) => {
const { points, options, events } = props;
const initFn = useCallback(() => {
const { points, options } = props;

let lineString: H.geo.LineString;
const firstEl = points[0];
if (typeof firstEl === 'string' && firstEl.split(',').length === 2) {
lineString = new H.geo.LineString();
const p = points as string[];
p.forEach(function(coords: string) {
const c = coords.split(',').map(c => Number(c));
// c has to be lat, lng, alt
lineString.pushLatLngAlt.apply(lineString, [c[0], c[1], c[2]]);
});
} else {
lineString = new H.geo.LineString(points as number[]);
}
let lineString: H.geo.LineString;
const firstEl = points[0];
if (typeof firstEl === 'string' && firstEl.split(',').length === 2) {
lineString = new H.geo.LineString();
const p = points as string[];
p.forEach(function(coords: string) {
const c = coords.split(',').map(c => Number(c));
// c has to be lat, lng, alt
lineString.pushLatLngAlt.apply(lineString, [c[0], c[1], c[2]]);
});
} else {
lineString = new H.geo.LineString(points as number[]);
}

// Initialize a LineString and add all the points to it:
return new H.map.Polygon(lineString, options);
},
[props.points]
);
// Initialize a LineString and add all the points to it:
return new H.map.Polygon(lineString, options);
}, [props.points]);

return (
<BaseMapObject
Expand Down

0 comments on commit 2d48a61

Please sign in to comment.