Skip to content
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

fix openlayers centre bug #234

Merged
merged 2 commits into from
Sep 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 11 additions & 32 deletions includes/services/OpenLayers/jquery.openlayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

this.map = null;
this.options = options;
this.bounds = null;

OpenLayers._getScriptLocation = function() {
return mw.config.get('wgScriptPath') + '/extensions/Maps/includes/services/OpenLayers/OpenLayers/';
Expand Down Expand Up @@ -60,10 +61,9 @@
}

var locations = options.locations;
var bounds = null;

if (locations.length > 1 && ( options.centre === false || options.zoom === false )) {
bounds = new OpenLayers.Bounds();
this.bounds = new OpenLayers.Bounds();
}

this.groupLayers = new Object();
Expand All @@ -73,7 +73,7 @@
this.addMarker( locations[i] );
}

if (bounds != null) map.zoomToExtent(bounds); // If a bounds object has been created, use it to set the zoom and center.
if (this.bounds != null) map.zoomToExtent(this.bounds); // If a bounds object has been created, use it to set the zoom and center.
};

this.addMarker = function (markerData) {
Expand All @@ -100,6 +100,7 @@
markerData.lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
}

if (this.bounds != null) this.bounds.extend(markerData.lonlat); // Extend the bounds when no center is set.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I'm reading this code is that the bounds will get extended every time a marker is added. Is that incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how I understand it too and it's correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that once the map has been fully loaded, and some event is causing addMarker to be called, the map will re-zoom and re-center?

(I don't really recall how the bounds stuff works, and if this rezoom and re-center happens if something gets added to it or if you need to make another call somewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. I tried to provoke something like this with the SemanticMaps ajax feature (which only loads and adds points that are within current bounds), but it worked fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, going to trust you used the right incantations then

var marker = this.getOLMarker(curLayer, markerData);
this.markers.push({
target:marker,
Expand Down Expand Up @@ -292,7 +293,7 @@
this.text( '' );

/**
* ToDo: That layers being created by 'eval' will deny us the possiblity to
* ToDo: That layers being created by 'eval' will deny us the possibility to
* set certain options. It's possible to set properties of course but they will
* show no effect since they are not passed as options to the constructor.
* With this working we could adjust max/minScale to display overlays independent
Expand Down Expand Up @@ -368,8 +369,7 @@
else if ( options.locations.length == 0 ) {
centre = new OpenLayers.LonLat( 0, 0 );
}
}
else { // When the center is provided, set it.
} else { // When the center is provided, set it.
centre = new OpenLayers.LonLat( options.centre.lon, options.centre.lat );
}

Expand All @@ -379,8 +379,10 @@
new OpenLayers.Projection( "EPSG:4326" ),
new OpenLayers.Projection( "EPSG:900913" )
);
map.setCenter( centre );
} else {
map.zoomToMaxExtent();
}
map.setCenter( centre );
}

if ( options.zoom !== false ) {
Expand Down Expand Up @@ -469,7 +471,7 @@
'strokeOpacity':feature.attributes.strokeOpacity,
'fillColor':feature.attributes.fillColor,
'fillOpacity':feature.attributes.fillOpacity
}
};
_this.polygonLayer.drawFeature(feature, style);
}
},
Expand All @@ -481,7 +483,7 @@
'strokeOpacity':0,
'fillColor':feature.attributes.fillColor,
'fillOpacity':0
}
};
_this.polygonLayer.drawFeature(feature, style);
}
},
Expand Down Expand Up @@ -572,29 +574,6 @@
map.zoomTo(options.zoom);
}

if (options.centre === false) {
if (options.locations.length == 1) {
centre = new OpenLayers.LonLat(options.locations[0].lon, options.locations[0].lat);
}
else if (options.locations.length == 0) {
centre = new OpenLayers.LonLat(0, 0);
}
}
else { // When the center is provided, set it.
centre = new OpenLayers.LonLat(options.centre.lon, options.centre.lat);
}

if (centre !== false) {
if (!hasImageLayer) {
centre.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
map.setCenter(centre);
} else {
map.zoomToMaxExtent();
}
}



if (options.copycoords) {
map.div.oncontextmenu = function () {
return false;
Expand Down