Skip to content

Commit

Permalink
optional props
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew44-mappable committed Apr 25, 2024
1 parent b92d1c5 commit fa54cee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/default-markers/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function main() {
<MMap location={location} ref={(x) => (map = x)}>
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapDefaultMarker name="building" color="bluebell" coordinates={MARKER_LOCATION} />
<MMapDefaultMarker iconName="building" color="bluebell" coordinates={MARKER_LOCATION} />
</MMap>
);
}
Expand Down
6 changes: 5 additions & 1 deletion example/default-markers/vanilla/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ async function main() {
map.addChild(new MMapDefaultSchemeLayer({}));
map.addChild(new MMapDefaultFeaturesLayer({}));

const defaultMarker = new MMapDefaultMarker({name: 'building', color: 'bluebell', coordinates: MARKER_LOCATION});
const defaultMarker = new MMapDefaultMarker({
iconName: 'building',
color: 'bluebell',
coordinates: MARKER_LOCATION
});
map.addChild(defaultMarker);
}
2 changes: 1 addition & 1 deletion example/default-markers/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
<MMap :location="LOCATION" :ref="refMap">
<MMapDefaultSchemeLayer />
<MMapDefaultFeaturesLayer />
<MMapDefaultMarker name="building" color="bluebell" :coordinates="MARKER_LOCATION"/>
<MMapDefaultMarker iconName="building" color="bluebell" :coordinates="MARKER_LOCATION"/>
</MMap>`
});
app.mount('#app');
Expand Down
25 changes: 18 additions & 7 deletions src/MMapDefaultMarker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import './index.css';
import pin from './pin.svg';

export type MMapDefaultMarkerProps = MMapMarkerProps & {
name: IconName;
color: IconColor;
iconName?: IconName;
color?: IconColor;
};

export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMarkerProps> {
const defaultProps = Object.freeze({color: 'darkgray'});
type DefaultProps = typeof defaultProps;

export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMarkerProps, DefaultProps> {
static defaultProps = defaultProps;

private _marker: MMapMarker;
private _markerElement: HTMLElement;
private _pin: HTMLElement;
Expand All @@ -19,6 +24,10 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
super(props);
}

protected __implGetDefaultProps(): DefaultProps {
return MMapDefaultMarker.defaultProps;
}

protected _onAttach(): void {
this._color = iconColors[this._props.color];
this._markerElement = document.createElement('mappable');
Expand All @@ -31,7 +40,9 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
this._pin.innerHTML = pin;

this._icon.classList.add('mappable--icon');
this._icon.innerHTML = icons[this._props.name].normal;
if (this._props.iconName !== undefined) {
this._icon.innerHTML = icons[this._props.iconName].normal;
}

this._pin.appendChild(this._icon);
this._markerElement.appendChild(this._pin);
Expand All @@ -46,9 +57,9 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
this._color = iconColors[this._props.color];
this._updateTheme();
}
if (propsDiff.name !== undefined) {
this._icon.innerHTML = icons[propsDiff.name].normal;
}

this._icon.innerHTML = this._props.iconName !== undefined ? icons[this._props.iconName].normal : '';

this._marker.update(this._props);
}

Expand Down

0 comments on commit fa54cee

Please sign in to comment.