Skip to content

Commit

Permalink
Fix map components issues, fixed css for RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Sep 1, 2024
1 parent 38acecd commit 64e426b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/components/AppToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {

<ToolbarSelect wdKey="nav:inspect">
<MdFindInPage />
<label>{t("View")}
<IconText>{t("View")}
<select
className="maputnik-select"
data-wd-key="maputnik-select"
Expand All @@ -254,12 +254,12 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
})}
</optgroup>
</select>
</label>
</IconText>
</ToolbarSelect>

<ToolbarSelect wdKey="nav:language">
<MdLanguage />
<label>Language
<IconText>Language
<select
className="maputnik-select"
data-wd-key="maputnik-lang-select"
Expand All @@ -274,7 +274,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
);
})}
</select>
</label>
</IconText>
</ToolbarSelect>

<ToolbarLink href={"https://github.com/maplibre/maputnik/wiki"}>
Expand Down
24 changes: 19 additions & 5 deletions src/components/MapMaplibreGl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '../libs/maplibre-rtl'
import MaplibreGeocoder, { MaplibreGeocoderApi, MaplibreGeocoderApiConfig } from '@maplibre/maplibre-gl-geocoder';
import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';
import { withTranslation, WithTranslation } from 'react-i18next'
import i18next from 'i18next'

function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement {
ReactDOM.render(popup, mountNode);
Expand Down Expand Up @@ -67,9 +68,11 @@ type MapMaplibreGlInternalProps = {
} & WithTranslation;

type MapMaplibreGlState = {
map: Map | null
inspect: MaplibreInspect | null
zoom?: number
map: Map | null;
inspect: MaplibreInspect | null;
geocoder: MaplibreGeocoder | null;
zoomControl: ZoomControl | null;
zoom?: number;
};

class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> {
Expand All @@ -87,7 +90,12 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.state = {
map: null,
inspect: null,
geocoder: null,
zoomControl: null,
}
i18next.on('languageChanged', () => {
this.forceUpdate();
})
}


Expand Down Expand Up @@ -125,6 +133,7 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.state.inspect!.render();
}, 500);
}

}

componentDidMount() {
Expand Down Expand Up @@ -152,9 +161,9 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
map.showCollisionBoxes = mapOpts.showCollisionBoxes!;
map.showOverdrawInspector = mapOpts.showOverdrawInspector!;

this.initGeocoder(map);
let geocoder = this.initGeocoder(map);

const zoomControl = new ZoomControl(this.props.t("Zoom:"));
const zoomControl = new ZoomControl();
map.addControl(zoomControl, 'top-right');

const nav = new MapLibreGl.NavigationControl({visualizePitch:true});
Expand Down Expand Up @@ -189,6 +198,8 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.setState({
map,
inspect,
geocoder,
zoomControl,
zoom: map.getZoom()
});
})
Expand Down Expand Up @@ -261,10 +272,13 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
maplibregl: MapLibreGl,
});
map.addControl(geocoder, 'top-left');
return geocoder;
}

render() {
const t = this.props.t;
this.state.geocoder?.setPlaceholder(t("Search"));
this.state.zoomControl?.setLabel(t("Zoom:"));
return <div
className="maputnik-map__map"
role="region"
Expand Down
16 changes: 10 additions & 6 deletions src/libs/zoomcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ export default class ZoomControl {
_container: HTMLDivElement | undefined = undefined;
_textEl: HTMLSpanElement | null = null;

constructor(public label: string) {}
constructor() {}

onAdd(map: Map) {
this._map = map;
this._container = document.createElement('div');
this._container.className = 'maplibregl-ctrl maplibregl-ctrl-group maplibregl-ctrl-zoom';
this._container.setAttribute("data-wd-key", "maplibre:ctrl-zoom");
this._container.innerHTML = `
${this.label} <span></span>
`;
this._textEl = this._container.querySelector("span");

this.setLabel("Zoom:");
this.addEventListeners();

return this._container;
Expand All @@ -25,6 +21,14 @@ export default class ZoomControl {
updateZoomLevel() {
this._textEl!.innerHTML = this._map!.getZoom().toFixed(2);
}

setLabel(label: string) {
this._container!.innerHTML = `
${label} <span></span>
`;
this._textEl = this._container!.querySelector("span");
this.updateZoomLevel();
}

addEventListeners (){
this._map!.on('render', () => this.updateZoomLevel());
Expand Down
2 changes: 1 addition & 1 deletion src/styles/_export.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

input.maputnik-string {
margin-left: 5px;
margin: 0 5px;
width: 60%;
display: inline-block;
}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/_filtereditor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

.maputnik-filter-editor-operator {
margin-left: 2%;
margin: 0 2%;
display: inline-block;
width: 17%;

Expand All @@ -30,7 +30,7 @@
.maputnik-filter-editor-args {
display: inline-block;
width: 54%;
margin-left: 2%;
margin: 0 2%;

.maputnik-string,
.maputnik-number {
Expand Down
3 changes: 3 additions & 0 deletions src/styles/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@

height: 24px;
}
[dir="rtl"] .maputnik-select {
background: $color-gray url("#{$icon-down-arrow}") left center no-repeat;
}

// MULTIBUTTON
.maputnik-multibutton {
Expand Down
2 changes: 1 addition & 1 deletion src/styles/_layer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}

&-group-content {
margin-left: $margin-3;
margin: 0 $margin-3;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/styles/_popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

.maputnik-popup-layer-id {
padding-left: $margin-2;
padding-right: 1.6em;
padding-right: $margin-2;
background-color: $color-midgray;
color: $color-white;
}
Expand All @@ -33,6 +33,7 @@
.maputnik-input-block {
margin: 0;
margin-left: $margin-2;
margin-right: $margin-2;
margin-top: $margin-2;
}
}
Expand All @@ -44,4 +45,5 @@
.maputnik-popup-table-cell {
color: $color-lowgray;
padding-left: $margin-2;
padding-right: $margin-2;
}
8 changes: 4 additions & 4 deletions src/styles/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

.maputnik-toolbar-version {
font-size: 10px;
margin-left: 4px;
margin: 0 4px;
white-space: nowrap;
}

Expand All @@ -103,7 +103,7 @@
@extend .maputnik-toolbar-link; /* stylelint-disable-line */

select {
margin-left: 6px;
margin: 0 6px;
border-width: 0;
display: inline;
width: auto;
Expand All @@ -114,12 +114,12 @@
}

.maputnik-icon-text {
padding-left: $margin-1;
padding: 0 $margin-1;
}

.maputnik-icon-action {
display: inline;
margin-left: $margin-1;
margin: 0 $margin-1;
}

.maputnik-toolbar__inner {
Expand Down
3 changes: 1 addition & 2 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@

&:not(:first-child)
{
padding-top: $margin-1;
padding-left: $margin-2;
padding: $margin-1;
}

&:nth-child(1) {
Expand Down

0 comments on commit 64e426b

Please sign in to comment.