Commit 2d88a24e authored by Elijah Byrd's avatar Elijah Byrd
Browse files

Small performance improvements to accessible_gmaps_getMarkerPos() by...

Small performance improvements to accessible_gmaps_getMarkerPos() by refactoring code into accessible_gmaps_getMapData
parent fdb899d8
Pipeline #16026 skipped
......@@ -75,6 +75,7 @@ function accessible_gmaps_onload(map, mapIdentifier_given, options){
marker = accessible_gmaps_markers[i];
accessible_gmaps_create_marker_div(marker, i);
}
accessible_gmaps_resetAllMarkers();
}, 2000);
}
......@@ -185,9 +186,6 @@ function accessible_gmaps_create_marker_div(marker, markerIndex){
accessible_gmaps_infowindows_openInfoWindow(markerIndex);
});
}
// Reposition marker (requires map bounds to be set)
accessible_gmaps_resetMarker(markerIndex);
}
/**
......@@ -295,7 +293,7 @@ function accessible_gmaps_infowindows_trapTabKey(object,evt, markerIndex) {
*
* TODO: allow offset to be calculated based on marker size data retrieved from user?
*/
function accessible_gmaps_resetMarker(markerIndex){
function accessible_gmaps_resetMarker(markerIndex, mapData){
marker = accessible_gmaps_markers[markerIndex];
var markerID = "mkr-" + markerIndex;
......@@ -305,7 +303,7 @@ function accessible_gmaps_resetMarker(markerIndex){
return;
}
var offset = accessible_gmaps_getMarkerPos(marker);
var offset = accessible_gmaps_getMarkerPos(marker, mapData);
// These values should be adjusted based on your marker size.
offset.x = offset.x - 10;
......@@ -332,8 +330,9 @@ function accessible_gmaps_resetMarker(markerIndex){
* that resets all markers in the markers array.
*/
function accessible_gmaps_resetAllMarkers(){
var mapData = accessible_gmaps_getMapData();
for(var i = 0; i < accessible_gmaps_markers.length; i++){
accessible_gmaps_resetMarker(i);
accessible_gmaps_resetMarker(i, mapData);
}
}
......@@ -367,23 +366,32 @@ function accessible_gmaps_addMarker(marker){
accessible_gmaps_markers.push(marker);
}
function accessible_gmaps_getMapData(){
mapData = {};
mapData.scale = Math.pow(2, accessibilityMap.getZoom());
mapData.nw = new google.maps.LatLng(
accessibilityMap.getBounds().getNorthEast().lat(),
accessibilityMap.getBounds().getSouthWest().lng()
);
mapData.projection = accessibilityMap.getProjection();
mapData.worldCoordinateNW = mapData.projection.fromLatLngToPoint(mapData.nw);
return mapData;
}
/**
* Helper function to calculate the position of a marker overlay.
* Written by Keith and almost entirely unmodified.
*/
function accessible_gmaps_getMarkerPos(marker) {
function accessible_gmaps_getMarkerPos(marker, mapData) {
var gmap = marker.map;
var scale = Math.pow(2, gmap.getZoom());
var nw = new google.maps.LatLng(
gmap.getBounds().getNorthEast().lat(),
gmap.getBounds().getSouthWest().lng()
);
var worldCoordinateNW = gmap.getProjection().fromLatLngToPoint(nw);
var worldCoordinate = gmap.getProjection().fromLatLngToPoint(marker.getPosition());
var worldCoordinate = mapData.projection.fromLatLngToPoint(marker.getPosition());
var pixelOffset = new google.maps.Point(
Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
Math.floor((worldCoordinate.x - mapData.worldCoordinateNW.x) * mapData.scale),
Math.floor((worldCoordinate.y - mapData.worldCoordinateNW.y) * mapData.scale)
);
return pixelOffset;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment