123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- var map;
- var pois;
- var selectControl;
- function init() {
- map = new OpenLayers.Map("mapdiv");
- //map.addControl(new OpenLayers.Control.LayerSwitcher());
- var osm = new OpenLayers.Layer.OSM();
- /* var osm = new OpenLayers.Layer.WMS(
- "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
- {layers: 'basic'}
- );*/
- map.addLayers([osm]);
- update_markers();
-
- //Set start centrepoint and zoom
- var lonLat = new OpenLayers.LonLat( 20.263889, 63.825 )
- .transform(
- new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
- map.getProjectionObject() // to Spherical Mercator Projection
- );
- var zoom=9;
- map.setCenter (lonLat, zoom);
- }
- function update_markers() {
- if (pois) {
- while( map.popups.length ) {
- map.removePopup(map.popups[0]);
- }
- pois.destroyFeatures();
- map.removeLayer(pois);
- selectControl.deactivate();
- }
-
- selectbox = document.getElementById('btype');
- btype = [];
- for (var i=0; i<selectbox.options.length; i++) {
- if (selectbox.options[i].selected) {
- btype.push(selectbox.options[i].value);
- }
- }
- pois = new OpenLayers.Layer.Vector("Umeå Fritid Facilities", {
- strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1.1})],
- protocol: new OpenLayers.Protocol.HTTP({
- url: "./filter-markers.php?btype[]=" + btype.join('&btype[]='),
- format: new OpenLayers.Format.Text()
- })
- });
- map.addLayer(pois);
- selectControl = new OpenLayers.Control.SelectFeature(pois);
- map.addControl(selectControl);
- selectControl.activate();
- pois.events.on({
- 'featureselected': onFeatureSelect,
- 'featureunselected': onFeatureUnselect
- });
- update_facility_list(btype);
- // Needed only for interaction, not for the display.
- function onPopupClose(evt) {
- // 'this' is the popup.
- var feature = this.feature;
- if (feature.layer) { // The feature is not destroyed
- selectControl.unselect(feature);
- } else { // After "moveend" or "refresh" events on POIs layer all
- // features have been destroyed by the Strategy.BBOX
- this.destroy();
- }
- }
- function onFeatureSelect(evt) {
- feature = evt.feature;
- popup = new OpenLayers.Popup.FramedCloud("featurePopup",
- feature.geometry.getBounds().getCenterLonLat(),
- new OpenLayers.Size(100,100),
- facility_popup_data(feature.attributes.id),
- null, true, onPopupClose);
- feature.popup = popup;
- popup.feature = feature;
- map.addPopup(popup, true);
- }
- function onFeatureUnselect(evt) {
- feature = evt.feature;
- if (feature.popup) {
- popup.feature = null;
- map.removePopup(feature.popup);
- feature.popup.destroy();
- feature.popup = null;
- }
- }
- }
- function update_facility_list(btype) {
- var r = new XMLHttpRequest();
- r.open("GET", "./facility-list.php?btype[]=" + btype.join('&btype[]='), false);
- r.send();
- var databox = document.getElementById('facility-list');
- databox.innerHTML = r.responseText;
- }
- function facility_popup_data(facility_id) {
- var r = new XMLHttpRequest();
- r.open("GET", "./facility-data.php?id=" + facility_id + "&popup", false);
- r.send();
- return r.responseText;
- }
- function update_facility_data(facility_id) {
- var r = new XMLHttpRequest();
- r.open("GET", "./facility-data.php?id=" + facility_id, false);
- r.send();
- var databox = document.getElementById('facility-data');
- databox.innerHTML = r.responseText;
- make_facility_popup(facility_id);
- }
- function make_facility_popup(facility_id) {
- // using layer 'pois'
- for (var i=0; i<pois.features.length; i++) {
- feature = pois.features[i];
- if (feature.attributes.id == facility_id) {
- map.setCenter(feature.geometry.getBounds().getCenterLonLat(), 16);
- selectControl.select(feature);
- break;
- }
- }
- }
|