event to handle turning the data layer on and off.
function mapInit(){
map = createMap("map");
+ map.dataLayer = new OpenLayers.Layer("Data", { "visibility": false });
+ map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
+ map.addLayer(map.dataLayer);
+
<% if bbox %>
var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
handleResize();
}
+ function toggleData() {
+ if (map.dataLayer.visibility) {
+ <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
+ } else {
+ closeSidebar();
+ }
+ }
+
function getPosition() {
return getMapCenter();
}
}
function createMap(divName, options) {
- if (!options) { options = {} }
+ options = options || {};
+
map = new OpenLayers.Map(divName, {
controls: options.controls || [
new OpenLayers.Control.ArgParser(),
wrapDateLine: true
});
map.addLayer(maplint);
- var data = new OpenLayers.Layer.Data("Data", {'visibility': false});
- map.addLayer(data);
- map.dataLayer = data;
var numZoomLevels = Math.max(mapnik.numZoomLevels, osmarender.numZoomLevels);
markers = new OpenLayers.Layer.Markers("Markers", {
CLASS_NAME: "OpenLayers.Layer.OSM.Maplint"
});
-
-OpenLayers.Layer.Data = OpenLayers.Class(OpenLayers.Layer, {
- setVisibility: function(vis) {
- var oldvis = this.visibility;
- OpenLayers.Layer.prototype.setVisibility.apply(this, arguments);
- if (!this.map) { return; }
- if (vis && !oldvis) {
- new Ajax.Request('/browse/start', {asynchronous:true, evalScripts:true});
- } else {
- if (this.stopBrowse) {
- this.stopBrowse();
- closeSidebar();
- }
- }
- }
-});