Skip to content

Commit b19aab0

Browse files
authored
Merge pull request #47 from BuildFire/fix/markers-shifting
fix(map): handle map markers shifting - CS-2984
2 parents 2e4339b + c7fbbce commit b19aab0

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

src/widget/css/main.css

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,20 +791,17 @@ body section#home {
791791
.custom-marker {
792792
position: absolute;
793793
cursor: pointer;
794+
width: 45px;
795+
height: 45px;
794796
}
795797
.custom-marker__container{
796798
box-sizing: border-box;
797-
cursor: pointer;
798-
width: 48px;
799-
height: 48px;
800799
border-radius: 4px;
801800
padding: 4px;
802801
background-color: #fff;
803802
box-shadow: 0 11px 16px -9px rgb(0 0 0 / 70%), 0 2px 16px rgb(150 150 150 / 70%);
804-
position: relative;
805803
border: 1px solid rgba(150,150,150,.8);
806-
margin-left: -24px;
807-
margin-top: -48px;
804+
transform: translate(-50%, -100%);
808805
}
809806
.custom-marker__container::after {
810807
content: '';
@@ -835,6 +832,7 @@ body section#home {
835832
}
836833
.custom-marker__circle {
837834
overflow: visible;
835+
transform: translate(-50%, -50%);
838836
}
839837
.custom-marker__circle svg {
840838
width: 100%;

src/widget/js/map/CustomMarker.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,27 @@ export default (function () {
6363
this.onClick(this.location);
6464
});
6565
}
66+
const point = this.getProjection().fromLatLngToDivPixel(this.position);
67+
if (point) {
68+
const southWest = this.map.getBounds().getSouthWest();
69+
const northEast = this.map.getBounds().getNorthEast();
70+
const sw = this.getProjection().fromLatLngToDivPixel(southWest);
71+
const ne = this.getProjection().fromLatLngToDivPixel(northEast);
72+
73+
const mapWidth = ne.x - sw.x;
74+
const mapHeight = sw.y - ne.y;
75+
// factor depends on the marker size
76+
const widthRatio = 45 / mapWidth;
77+
const heightRatio = 45 / mapHeight;
78+
div.style.width = `${mapWidth * widthRatio}px`;
79+
div.style.height = `${mapHeight * heightRatio}px`;
80+
81+
div.style.left = point.x + 'px';
82+
div.style.top = point.y + 'px';
83+
}
6684

6785
this.getPanes().overlayMouseTarget.appendChild(div);
6886

69-
const changeBound = () => {
70-
// Position the overlay
71-
if (!this.getProjection()) {
72-
return;
73-
}
74-
const point = this.getProjection().fromLatLngToDivPixel(this.position);
75-
const sw = this.getProjection().fromLatLngToDivPixel(
76-
this.map.getBounds().getSouthWest()
77-
);
78-
const ne = this.getProjection().fromLatLngToDivPixel(
79-
this.map.getBounds().getNorthEast()
80-
);
81-
if (point) {
82-
div.style.left = `${point.x}px`;
83-
div.style.top = `${point.y}px`;
84-
let width = ne.x - sw.x;
85-
let height = sw.y - ne.y;
86-
// factor depends on the marker size, circle has its own width
87-
const ratio1 = 45 / width;
88-
const ratio2 = 45 / height;
89-
height *= ratio2; // Reset height to match scaled image
90-
width *= ratio1;
91-
div.style.width = `${width}px`;
92-
div.style.height = `${height}px`;
93-
}
94-
};
95-
changeBound();
96-
google.maps.event.addListener(this.map, 'idle', changeBound);
9787
};
9888

9989
CustomMarker.prototype.remove = function () {

src/widget/widget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,8 @@ const findViewPortLocations = () => {
10761076
mapView.clearMapViewList();
10771077
}
10781078

1079-
searchLocations().then((result) => {
1080-
result.forEach((location) => state.maps.map.addMarker(location, handleMarkerClick));
1079+
searchLocations().then(() => {
1080+
state.listLocations.forEach((location) => state.maps.map.addMarker(location, handleMarkerClick));
10811081
});
10821082
}, 300);
10831083

0 commit comments

Comments
 (0)