-
-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Map] Improve web performances by not calling "createInfoWindow" if unnecessary #2083
base: 2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,13 @@ export default class extends AbstractMapController< | |
}); | ||
|
||
if (infoWindow) { | ||
this.createInfoWindow({ definition: infoWindow, marker }); | ||
if (infoWindow.opened) { | ||
this.createInfoWindow({ definition: infoWindow, marker }); | ||
} else { | ||
marker.addListener('click', () => { | ||
this.createInfoWindow({ definition: infoWindow, marker, onMarkerClick: true }); | ||
}); | ||
} | ||
} | ||
|
||
return marker; | ||
|
@@ -130,12 +136,14 @@ export default class extends AbstractMapController< | |
protected doCreateInfoWindow({ | ||
definition, | ||
marker, | ||
onMarkerClick, | ||
}: { | ||
definition: MarkerDefinition< | ||
google.maps.marker.AdvancedMarkerElementOptions, | ||
google.maps.InfoWindowOptions | ||
>['infoWindow']; | ||
marker: google.maps.marker.AdvancedMarkerElement; | ||
onMarkerClick: boolean; | ||
}): google.maps.InfoWindow { | ||
const { headerContent, content, extra, rawOptions = {}, ...otherOptions } = definition; | ||
|
||
|
@@ -146,24 +154,19 @@ export default class extends AbstractMapController< | |
...rawOptions, | ||
}); | ||
|
||
if (definition.opened) { | ||
if (definition.opened || onMarkerClick) { | ||
infoWindow.open({ | ||
map: this.map, | ||
shouldFocus: false, | ||
anchor: marker, | ||
}); | ||
} | ||
Comment on lines
+157
to
163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confusing to me... this mixes runtime values and definition values |
||
|
||
marker.addListener('click', () => { | ||
if (onMarkerClick) { | ||
if (definition.autoClose) { | ||
this.closeInfoWindowsExcept(infoWindow); | ||
} | ||
|
||
infoWindow.open({ | ||
map: this.map, | ||
anchor: marker, | ||
}); | ||
}); | ||
} | ||
|
||
return infoWindow; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,21 @@ class map_controller extends AbstractMapController { | |
const { position, title, infoWindow, extra, rawOptions = {}, ...otherOptions } = definition; | ||
const marker = L.marker(position, { title, ...otherOptions, ...rawOptions }).addTo(this.map); | ||
if (infoWindow) { | ||
this.createInfoWindow({ definition: infoWindow, marker }); | ||
if (infoWindow.opened) { | ||
this.createInfoWindow({ definition: infoWindow, marker }); | ||
} | ||
else { | ||
marker.on('click', () => { | ||
this.createInfoWindow({ definition: infoWindow, marker, onMarkerClick: true }); | ||
}); | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not seem a good idea to run every time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "createInfoWindow" will be called on every "click" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes you're right. Hum, I may have better ideas to rewrite the PR, but I don't have time right now, let's put it in draft. |
||
} | ||
} | ||
return marker; | ||
} | ||
doCreateInfoWindow({ definition, marker, }) { | ||
doCreateInfoWindow({ definition, marker, onMarkerClick, }) { | ||
const { headerContent, content, extra, rawOptions = {}, ...otherOptions } = definition; | ||
marker.bindPopup([headerContent, content].filter((x) => x).join('<br>'), { ...otherOptions, ...rawOptions }); | ||
if (definition.opened) { | ||
if (definition.opened || onMarkerClick) { | ||
marker.openPopup(); | ||
} | ||
const popup = marker.getPopup(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this should be exposed like this, seems to complexify the contract, while not beeing this "explanatory"