/* Copyright (C) 2008 Étienne Loks 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 . See the file COPYING for details. */ /* main map */ /* show a block panel */ function show(id){ document.getElementById(id).style.display = 'block'; } /* hide a panel */ function hide(id){ document.getElementById(id).style.display = 'None'; } var map; /* availaible map layers */ var layerMapnik = new OpenLayers.Layer.OSM.Mapnik('Classic'); var cyclemap = new OpenLayers.Layer.OSM.CycleMap("Cycle map", { displayOutsideMaxExtent: true, wrapDateLine: true}); /* default size and offset for icon */ var size = new OpenLayers.Size(21, 25); var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); /* define global variable */ var markers = new Array(); var layerMarkers; var layerVectors; var currentPopup; var currentFeature; var clicked = false; /* show a popup */ function showPop(feature) { if (currentPopup != null) { currentPopup.hide(); } if (feature.popup == null) { feature.popup = feature.createPopup(); map.addPopup(feature.popup); } else { feature.popup.toggle(); } currentPopup = feature.popup; } /* load geo objects with an AJAX request */ function loadGeoObjects(){ /* get checked categories */ inputs = window.document.forms["frm_categories"]; var categories = ''; for (var i = 0; i < inputs.length; i++) { input = inputs[i]; if (input.checked && input.name.substring('category_'.length, 0) == 'category_'){ id = input.name.substring('category_'.length, input.name.length); if(categories) categories += '_'; categories += id; } } /* 0 stand for all categories */ if (!categories) categories = '0'; var uri = "/chimere/getGeoObjects/" + categories; OpenLayers.loadURL(uri, '', this, setGeoObjects); } /* update the marker and vector layers from an http response GeoJSON */ function setGeoObjects(response){ if(layerMarkers) layerMarkers.destroy(); if(layerVectors) layerVectors.destroy(); if (response.responseText.indexOf('no results') == -1) { /* clean the marker layer */ if (currentPopup) { currentPopup.hide(); hide('detail'); } layerVectors = new OpenLayers.Layer.Vector("Vector Layer"); map.addLayer(layerVectors); layerVectors.setOpacity(0.8); layerMarkers = new OpenLayers.Layer.Markers('POIs'); map.addLayer(layerMarkers); layerMarkers.setOpacity(0.8); var json = new OpenLayers.Format.JSON(); var geo_objects = json.read(response.responseText); /* load every geo object */ for (var i = 0; i < geo_objects.features.length; i++) { var feature = geo_objects.features[i]; if (feature.geometry.type == 'Point') putMarker(feature); if (feature.geometry.type == 'LineString') { putRoute(feature); } } /* var geojson = new OpenLayers.Format.GeoJSON(); var markers_pt = geojson.read(response.responseText); for (var i = 0; i < markers_pt.length; i++) { putMarker2(markers_pt[i]); }*/ } } /* put a route on the map */ function putRoute(route) { var polyline = route.geometry; var point_array = new Array(); for (i=0; i