/* * JavaScript code to generate maps used by the * Seismological Observatory of the Ruhr-University Bochum * * Copyright 2013 Kasper D. Fischer * * 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$ */ /* Global variables */ var map; /* Main function to create the map */ function init(showGoogle, showStations, showQuakes, noFrils) { /* Creating map */ if ( !noFrils ) { map = new OpenLayers.Map( 'map', { projection: new OpenLayers.Projection('EPSG:900913'), displayProjection: new OpenLayers.Projection('EPSG:4326'), controls: [ new OpenLayers.Control.Attribution(), new OpenLayers.Control.KeyboardDefaults(), new OpenLayers.Control.LayerSwitcher({}), new OpenLayers.Control.MousePosition(), new OpenLayers.Control.Navigation(), new OpenLayers.Control.OverviewMap(), new OpenLayers.Control.PanZoomBar({zoomWorldIcon: true}), new OpenLayers.Control.Permalink(), new OpenLayers.Control.ScaleLine({geodesic: true}) ] } ); } else { map = new OpenLayers.Map( 'map', { projection: new OpenLayers.Projection('EPSG:900913'), displayProjection: new OpenLayers.Projection('EPSG:4326'), controls: [ new OpenLayers.Control.Attribution(), new OpenLayers.Control.KeyboardDefaults(), new OpenLayers.Control.Navigation(), new OpenLayers.Control.Permalink({anchor: true}), new OpenLayers.Control.ScaleLine({geodesic: true}) ] } ); }; /* Base Layers */ // OpenStreetMap var osmde_map_layer = new OpenLayers.Layer.OSM( 'OpenStreetMap (DE)', [ "https://a.tile.openstreetmap.de/tiles/osmde/${z}/${x}/${y}.png", "https://b.tile.openstreetmap.de/tiles/osmde/${z}/${x}/${y}.png", "https://c.tile.openstreetmap.de/tiles/osmde/${z}/${x}/${y}.png" ], { attribution: 'Geobasisdaten: Copyright © 2013 OpenStreetMap und Mitwirkende;' + 'Lizenz: Creative Commons BY-SA 2.0.' } ); var osm_map_layer = new OpenLayers.Layer.OSM('OpenStreetMap (Standard)'); map.addLayers([ osm_map_layer, osmde_map_layer ]); // Google Maps if (showGoogle) { var googleT_map_layer = new OpenLayers.Layer.Google( OpenLayers.i18n('Google Maps (Terrain)'), {type: google.maps.MapTypeId.TERRAIN,transitionEffect: "resize"} ); var googleS_map_layer = new OpenLayers.Layer.Google( OpenLayers.i18n("Google Maps (Satellite)"), {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22,transitionEffect: "resize"} ); var googleH_map_layer = new OpenLayers.Layer.Google( 'Google Maps (Hybrid)', {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20,transitionEffect: "resize"} ); var googleM_map_layer = new OpenLayers.Layer.Google( OpenLayers.i18n("Google Maps (Streets)"), {numZoomLevels: 20,transitionEffect: "resize"} ); map.addLayers([ googleT_map_layer, googleS_map_layer, googleH_map_layer, googleM_map_layer ]); }; // ESRI var esri_map_layer = new OpenLayers.Layer.XYZ( 'ESRI', "https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/${z}/${y}/${x}", { sphericalMercator: true, attribution: 'Copyright © 2013 by ESRI. ' + 'This work is licensed under the Web Services and API Terms of Use.' } ); map.addLayers([esri_map_layer]); // Show quakes quakes_layer = loadKML(OpenLayers.i18n("Events"), 'quakes.kml', false, true); quakes_layer.events.on({'visibilitychanged': toggleQuakesMapkey}); map.addLayer(quakes_layer); quakes_layer.setVisibility(showQuakes); // Adding custom style to quakes var quake_style_default = new OpenLayers.Style({ fillColor: '${pntcolor}', fillOpacity: 0.2, strokeColor: '${pntcolor}', strokeWidth: 2, pointRadius: '${pntsize}' }, { context: { pntcolor: function(feature){ return feature.data.pntcolor.value; }, pntsize: function(feature){ return feature.data.pntsize.value; } } }); var quake_style_select = quake_style_default.clone(); quake_style_select.defaultStyle.fillOpacity = 0.8; var quake_style_map = new OpenLayers.StyleMap({ 'default': quake_style_default, 'select': quake_style_select }); quakes_layer.styleMap = quake_style_map; // Show stations stations_layer = loadKML(OpenLayers.i18n("Stations"), 'stations.kml', false, noFrils); map.addLayer(stations_layer); stations_layer.setVisibility(showStations); // Adding custom style to stations var station_style_default = new OpenLayers.Style({ fillColor: '#8dae10', fillOpacity: 0.8, strokeColor: 'black', strokeWidth: 2, label: "${text}", labelXOffset: 15, labelAlign: 'l', fontColor: "${tcolor}", fontFamily: 'sans-serif', fontWeight: 'bold', pointRadius: '${pntsize}', graphicName: '${pntsymbol}' }, { context: { text: function(feature){ if (feature.attributes.count) { var c = feature.attributes.count; for (var i=0; i=0; --i) { map.layers[i].animationEnabled = true; } // Show description select = new OpenLayers.Control.SelectFeature([quakes_layer, stations_layer]); map.addControl(select); select.activate(); // Add graticule map.addControl(new OpenLayers.Control.Graticule({layerName: OpenLayers.i18n("Grid"), visible: false})); } /* Function to load KML file */ function loadKML(name, file, useStyle, noFrils) { // define layer strategy var layer_strategy if (noFrils){ layer_strategy = [ new OpenLayers.Strategy.Fixed(), ]; } else { // define cluster parameters var thresholdValue = 4; if (map.getZoom() <= 8){ thresholdValue = 2} if (map.getZoom() >= 10){ thresholdValue = 6} if (noFrils) { thresholdValue = 99; distanceValue = 0 }; var distanceValue = 10; if (map.getZoom() <= 9){ distanceValue = 20} layer_strategy = [ new OpenLayers.Strategy.Fixed(), new OpenLayers.Strategy.Cluster({distance: distanceValue, threshold: thresholdValue}) ]; } // create kml layer var kml_layer = new OpenLayers.Layer.Vector( name, { strategies: layer_strategy, protocol: new OpenLayers.Protocol.HTTP( { url: file, format: new OpenLayers.Format.KML({ extractStyles: useStyle, extractAttributes: true, maxDepth: 1 }) }), transitionEffect: "resize", projection: new OpenLayers.Projection("EPSG:4326") }); kml_layer.events.on( { "featureselected": onFeatureSelect, "featureunselected": onFeatureUnselect }); // return layer object return kml_layer; } /* Function called at closing of a popup */ function onPopupClose(evt) { select.unselectAll(); } /* Function called when clicking on a marker */ function onFeatureSelect(event) { var feature = event.feature; // Since KML is user-generated, do naive protection against // Javascript. if (feature.attributes.name){ var content = "

"+feature.attributes.name + "

" + feature.attributes.description + '

'; if (content.search("