var googlemap; var map; var nav_control; // TEST var markersLayer; var wdw_set_create_marker; var wdw_create_marker; var wdw_osm_layer; var wdw_osm_feature_layer; // Hash to store all currently displayed markers var wdw_current_markers = new Object(); var wdw_last_params = new Object(); var wdw_loading = 0; // add one for each load request, stop if 1 after load var wdw_reload_uri = ''; var wdw_click_offset_x = 0; var wdw_appid = 0; var wdw_domainid = 0; var wdw_current_popup; /*var wdw_bms_map_tiles_url; var wdw_bms_map_tiles_protocol; var wdw_bms_map_max_zoom;*/ function GUnload() { } OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false }, initialize: function(options) { this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions ); OpenLayers.Control.prototype.initialize.apply( this, arguments ); this.handler = new OpenLayers.Handler.Click( this, { 'click': this.trigger }, this.handlerOptions ); }, trigger: function(e) { var xy = e.xy; /* jQuery.each(xy, function(i, val) { alert(i + ' - ' + val); });*/ xy.x = xy.x + wdw_click_offset_x; var lonlat = map.getLonLatFromPixel(xy) .transform( map.getProjectionObject(), // to Spherical Mercator Projection new OpenLayers.Projection("EPSG:4326") // transform from WGS 1984 ); wdwMapClicked(lonlat, xy); } }); function wdwMapClicked(lonlat, px) { var map = getgooglemap(); if (wdw_create_marker != null) { markersLayer.removeMarker(wdw_create_marker); } if (map.projection == "EPSG:25832") { Proj4js.libPath = "http://wdwp.s3.amazonaws.com/r/028/static/js/"; var source = new Proj4js.Proj('EPSG:4326'); var target = new Proj4js.Proj('EPSG:25832'); var p = new Proj4js.Point(lonlat.lon + "," + lonlat.lat); var p = Proj4js.transform(source, target, p) //alert(" nachher " + p.toShortString()); point = new OpenLayers.LonLat(p.x , p.y); // wdw_create_marker = wdwAddMarker(point.lon, point.lat, 0, "", wdw_domain_staticUri+"/img/marker/marker-new.png"); // wdw_create_marker = wdwAddMarker(lonlat.lat, lonlat.lon, 0, "", wdw_domain_staticUri+"/img/marker/marker-new.png"); } wdw_create_marker = wdwAddMarker(lonlat.lat, lonlat.lon, 0, "", wdw_create_marker_uri ? wdw_create_marker_uri : wdw_domain_staticUri+"/img/marker/marker-new.png"); document.forms.bmsmessagecreateform.lat.value = lonlat.lat; document.forms.bmsmessagecreateform.lon.value = lonlat.lon; document.forms.bmsmessagecreateform.zoom.value = map.getZoom(); document.forms.bmsmessagecreateform.address.value = ''; $.getJSON('/bmsapi/get_domain', {'lat': lonlat.lat, 'long': lonlat.lon, 'appid': wdw_appid}, function(data){ if (data.isDefaultRecipient) { $('#bms-responsible-name-default').show(); } else { $('#bms-responsible-name-default').hide(); } if (data.domainid != wdw_domainid) { $('#bms-different-domain-container').show(); $('#bms-create-form-container').hide(); $('#bms-different-domain-name').text(data.name); $('#bms-different-domain-uri').attr('href',data.domainuri); } else { $('#bms-different-domain-container').hide(); $('#bms-create-form-container').show(); $('#bms-responsible-name').text(data.name); // Wird nicht benötigt, da dann ja der Link zur richtigen Domain angezeigt wird. // var types = data.types; // var options=""; // for (var i = 0; i < types.length; i++) { // options += ''; // } // $("#bms-messagetype").html(options); } }); } function wdwShowArea(wkt) { var in_options = { 'internalProjection': map.getProjectionObject(), 'externalProjection': new OpenLayers.Projection("EPSG:4326") }; var format = new OpenLayers.Format.WKT(in_options) wdw_osm_feature_layer.removeAllFeatures(); var feature = format.read(wkt); if (feature) { wdw_osm_feature_layer.addFeatures(feature); } } var old_x = false; var old_y = false; function wdwEnableMapZoom(event){ // Check existence of event. if(!event){ if(window.event){ // The event could be stored in the browser window. event = window.event; }else{ // Bad luck. There is no event, so just gracefully exit. return; } } // Only act if WheelZoom is disabled. if(nav_control && !nav_control.zoomWheelEnabled){ // If the mouse was previously outside the map. if(!old_x && !old_y){ old_x = event.screenX; old_y = event.screenY; } new_x = event.screenX; new_y = event.screenY; // Obtain pixels moved from first position on screen diff_x = Math.abs(old_x - new_x); diff_y = Math.abs(old_y - new_y); // If mouse moved more than 50px, then enable WheelZoom. if(diff_x > 10 || diff_y > 10){ nav_control.enableZoomWheel(); } } } function wdwDisableMapZoom(){ nav_control.disableZoomWheel(); old_x = false; old_y = false; } function wdwMapInit(lat, lon, op, zoom) { var protocol = 'OSM'; var tiles_url = "https://osmtiles.werdenktwas.de/tiles/osm-nopoi2/${z}/${x}/${y}.png"; var max_zoom = 19; $.ajaxSetup ({ cache: false}); jQuery.support.cors = true; if (wdw_bms_map_tiles_url != null) tiles_url = wdw_bms_map_tiles_url; if(wdw_bms_map_tiles_protocol != null) protocol = wdw_bms_map_tiles_protocol; if(wdw_bms_map_max_zoom != null) max_zoom = wdw_bms_map_max_zoom; if(protocol == 'WMS') { map = new OpenLayers.Map( 'map_canvas' , { projection: "EPSG:25832", //displayProjection: "EPSG:25832", maxResolution: 156543, units: 'meters', maxExtent: new OpenLayers.Bounds(477683,5543383,490440,5554383), restrictedExtent: new OpenLayers.Bounds(477683,5543383,490440,5554383), eventListeners: { "moveend": wdwMapEvent //,"zoomend": wdwMapEvent // not required, moveend fires on zoom } }); nav_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0]; nav_control.disableZoomWheel(); map.events.register('zoomend', this, function (event) { if( map.getZoom() < 13) { map.zoomTo(13); }}); wdw_osm_layer = new OpenLayers.Layer.WMS("Default", tiles_url, {},{transitionEffect: 'resize', "numZoomLevels": max_zoom}); /* map.addLayer(wdw_osm_layer); map.setCenter(new OpenLayers.LonLat(487683, 5593383), 14); return 1;*/ } else { map = new OpenLayers.Map("map_canvas",{eventListeners: { "moveend": wdwMapEvent //,"zoomend": wdwMapEvent // not required, moveend fires on zoom }} ); nav_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0]; nav_control.disableZoomWheel(); wdw_osm_layer = new OpenLayers.Layer.OSM("Default", tiles_url, {"numZoomLevels": max_zoom}); } wdw_osm_layer.attribution = ""; map.addLayer(wdw_osm_layer, { controls: [] }); wdw_osm_feature_layer = new OpenLayers.Layer.Vector('vectors'); map.addLayer(wdw_osm_feature_layer); map.addControl(new OpenLayers.Control.PanZoom()); googlemap=map; markersLayer = new OpenLayers.Layer.Markers( "Markers" ); map.addLayer(markersLayer); $('#map_canvas').mouseleave(wdwDisableMapZoom); var lonLat = new OpenLayers.LonLat( lon, lat ) .transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 map.getProjectionObject() // to Spherical Mercator Projection ); map.setCenter (lonLat, zoom); // Load markers and settings. wdwLoadMarker(); if(op == 2) { // bms create, select point on map var click = new OpenLayers.Control.Click(); map.addControl(click); click.activate(); } // TODO fix the bug in OpenLayers that returns wrong values for the click position in IE7 if(jQuery.browser.msie && jQuery.browser.version < 8) { wdw_click_offset_x = 0; } if(wdw_set_create_marker) { wdw_create_marker = wdwAddMarker(lat, lon, 0, "", wdw_domain_staticUri+"/img/marker/marker-new.png"); } } function wdwReloadMarkers(params) { // only reload markers if an uri was provided if(wdw_reload_uri == '') { wdw_loading = 0; return; } // save last params in case of panning and zooming wdw_last_params = params; // determine extent of current viewport var bounds = map.getExtent().clone(); bounds = bounds.transform( map.getProjectionObject(), // to Spherical Mercator Projection new OpenLayers.Projection("EPSG:4326") // transform from WGS 1984 ); // add extent to params //alert (bounds.left + " " + bounds.right); params['zoom'] = map.getZoom(); params['bottom'] = bounds.left; params['top'] = bounds.right; params['left'] = bounds.bottom; params['right'] = bounds.top; // show loading indicator $('#wdw-map-loading-indicator').css('visibility','visible'); // load markers $.ajaxSetup({ cache: false }); jQuery.support.cors = true; $.getJSON(URI(wdw_reload_uri).host("").scheme(""), params, function(data){ wdwReplaceMarkers(data); $('#wdw-map-loading-indicator').css('visibility','hidden'); if(wdw_loading > 1) { // map has changed again in between, reload wdw_loading = 0; window.setTimeout('wdwMapEvent()', 4); } else { // stop reloading markers wdw_loading = 0; } }); } function wdwBmsCreateUriFromParams() { var create_params = new Object(); create_params['lon'] = (wdw_last_params['top']+wdw_last_params['bottom'])/2; create_params['lat'] = (wdw_last_params['left']+wdw_last_params['right'])/2; create_params['zoom'] = wdw_last_params['zoom']; return '/bms/create?'+$.param(create_params); } function wdwReplaceMarkers(marker_list) { markersLayer.clearMarkers(); wdw_current_markers = new Object(); for (var i = 0; i < marker_list.length; i++) { wdw_current_markers[marker_list[i].msgid] = wdwAddMarker(marker_list[i].lat, marker_list[i].lon, marker_list[i].msgid, marker_list[i].html, marker_list[i].iconurl); } if(wdw_create_marker) { markersLayer.addMarker(wdw_create_marker); } } function wdwUpdateMarkers(marker_list) { for(key in marker_list) { var marker = marker_list[key]; if(marker.msgid in wdw_current_markers) { markersLayer.removeMarker(wdw_current_markers[msgid]); wdw_current_markers[msgid] = wdwAddMarker(marker.lat, marker.lon, marker.msgid, marker.html, marker.iconurl); } } } function wdwMapEvent(event){ if(wdw_loading == 0) { wdw_loading++; wdwReloadMarkers(wdw_last_params); } else { wdw_loading++; } } function wdwAddMarker(lat, lon, msgid, html, iconurl, heatmap) { var point = new OpenLayers.LonLat(lon ,lat).transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 map.getProjectionObject() // to Spherical Mercator Projection ); if (map.projection == "EPSG:25832") { Proj4js.libPath = "http://wdwp.s3.amazonaws.com/r/028/static/js/"; var source = new Proj4js.Proj('EPSG:4326'); var target = new Proj4js.Proj('EPSG:25832'); //alert(" vorher " + lat + "," + lon); var p = new Proj4js.Point(lon + "," + lat); var p = Proj4js.transform(source, target, p) //alert(" nachher " + p.toShortString()); point= new OpenLayers.LonLat(p.x , p.y); } var size = new OpenLayers.Size(30,38); var offset = new OpenLayers.Pixel(-15,-38); if(heatmap){ size = new OpenLayers.Size(12,12); offset = new OpenLayers.Pixel(-6,-6); } if(iconurl == "http://maps.google.com/mapfiles/marker.png" || iconurl == "http://maps.google.com/mapfiles/marker_green.png" ){ size = new OpenLayers.Size(20,34); offset = new OpenLayers.Pixel(-10,-24); } var icon = new OpenLayers.Icon(iconurl, size, offset); var marker = new OpenLayers.Marker(point,icon); var popup = new OpenLayers.Popup.FramedCloud("msgid-"+msgid, point, new OpenLayers.Size(200,200), html, null, true); if(html != null) { var markerClick = function (evt) { if(wdw_current_popup) { wdw_current_popup.hide(); } if (this.pop == null) { this.pop = popup; map.addPopup(this.pop); this.pop.show(); } else { this.pop.toggle(); } wdw_current_popup = this.pop; OpenLayers.Event.stop(evt); }; marker.events.register('mousedown', marker, markerClick); } markersLayer.addMarker(marker); // add marker to list of currently active markers wdw_current_markers[msgid] = marker; return marker; } function getgooglemap(){ return (googlemap); } function searchAddress(address) { $.getJSON(URI(wdw_searchAddress_uri).host("").scheme(""), {q :address} , function(data) { $('#bmsmessagecreateform input[name=search]').val(address); if (data.results.length>0) { var lonLat = new OpenLayers.LonLat( data.results[0].geometry.location.lng, data.results[0].geometry.location.lat ) .transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 map.getProjectionObject() // to Spherical Mercator Projection ); /*if (map.projection == "EPSG:25832") { lonLat= new OpenLayers.LonLat(lonLat.lat , lonLat.lon).transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection ); lonLat= new OpenLayers.LonLat(lonLat.lat - 500000, lonLat.lon); alert("searchAdress " + lonLat.lat + " " + lonLat.lon); }*/ map.setCenter (lonLat, 17); var lonLat2 = new OpenLayers.LonLat( data.results[0].geometry.location.lng, data.results[0].geometry.location.lat ); /*if (map.projection == "EPSG:25832") { lonLat2= new OpenLayers.LonLat(lonLat2.lat , lonLat2.lon).transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection ); lonLat2= new OpenLayers.LonLat(lonLat2.lat - 500000, lonLat2.lon); }*/ //wdw_create_marker = wdwAddMarker(lonLat2.lat, lonLat2.lon, 0, "", wdw_domain_staticUri+"/img/marker/marker-new.png"); wdwMapClicked(lonLat2,map.getPixelFromLonLat(lonLat2)); } else { alert("Ort nicht gefunden"); } }); }