seisobs-webapp/mapkey.js

88 lines
2.9 KiB
JavaScript

/*
* JavaScript code to generate maps used by the
* Seismological Observatory of the Ruhr-University Bochum
*
* Copyright 2012 Kasper D. Fischer <kasper.fischer@rub.de>
*
* License
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
* $Id: station_map.js 321 2012-02-13 14:52:11Z kasper $
*/
/* Global variables */
var mapkey;
/* Main function to create the map */
function initKey(showMag, showAge, showStation) {
/* Creating map */
wgs84 = new OpenLayers.Projection("EPSG:4326");
mapkey = new OpenLayers.Map(
'mapkey',
{
projection: wgs84,
displayProjection: wgs84,
controls: []
}
);
// Show Magnitudes
mag_layer = new OpenLayers.Layer.Vector(
'Magnitude Scale',
{
projection: wgs84,
isBaseLayer: true
}
);
// Adding custom style for Magnitudes
var mag_style_default = new OpenLayers.Style({
fillColor: '#ff0000', fillOpacity: 0.2,
strokeColor: '#ff0000', strokeWidth: 2,
pointRadius: "${pntsize}",
label: "${text}", labelXOffset: "${offset}",
graphicName: 'circle'
});
var mag_style_map = new OpenLayers.StyleMap({
'default': mag_style_default
});
mag_layer.styleMap = mag_style_map;
// Adding points as map key, size: mag*3.5+2.0
var pointt = new OpenLayers.Geometry.Point(-10, 0);
var mag_pointt = new OpenLayers.Feature.Vector(pointt, {pntsize: 0, text: 'Magnitude', offset: 2});
var point0 = new OpenLayers.Geometry.Point(0, 0);
var mag_point0 = new OpenLayers.Feature.Vector(point0, {pntsize: 0.5*3.5+2.0, text: '0.5', offset: 17});
var point1 = new OpenLayers.Geometry.Point(10, 0);
var mag_point1 = new OpenLayers.Feature.Vector(point1, {pntsize: 1.5*3.5+2.0, text: '1.5', offset: 20.5});
var point2 = new OpenLayers.Geometry.Point(20, 0);
var mag_point2 = new OpenLayers.Feature.Vector(point2, {pntsize: 2.5*3.5+2.0, text: '2.5', offset: 24.0});
var point3 = new OpenLayers.Geometry.Point(30, 0);
var mag_point3 = new OpenLayers.Feature.Vector(point3, {pntsize: 3.5*3.5+2.0, text: '3.5', offset: 27.5});
mag_layer.addFeatures([mag_pointt, mag_point0, mag_point1, mag_point2, mag_point3]);
mapkey.addLayer(mag_layer);
mag_layer.setVisibility(true);
// Set initial view
if (!mapkey.getCenter()) {
mapkey.setCenter(0,0);
mapkey.zoomToExtent(mag_layer.getDataExtent());
}
}