var PublicPluginNeedsMapMap=(function(){var _this=this;_this.params={config:null,bounds:null};_this.vars={map:null,markers:null,mask:null,popup:null,requestUrl:null,geocoder:null,newNeedMarker:null};_this.menu_items=[{text:' Utwórz zgłoszenie',callback:function(e){$('body').trigger('plugin-needs-map-open-form',[e.latlng.lat,e.latlng.lng]);}},{separator:true,index:2},{text:' Współrzędne',callback:function(e){_this.showCoordinates(e.latlng.lat,e.latlng.lng);}},{text:' Wyśrodkuj',callback:function(e){_this.setCenter(e.latlng.lat,e.latlng.lng);}},{text:' Przybliż',callback:function(e){_this.zoomIn();}},{text:' Oddal',callback:function(e){_this.zoomOut();}}];_this.setConfig=function(config){_this.params.config=config;};_this.getConfig=function(name){return _this.params.config[name];};_this.setMap=function(map){_this.vars.map=map;};_this.getMap=function(){return _this.vars.map;};_this.setMarkers=function(markers){_this.vars.markers=markers;};_this.getMarkers=function(){return _this.vars.markers;};_this.setPopup=function(popup){_this.vars.popup=popup;};_this.getPopup=function(){return _this.vars.popup;};_this.setRequestUrl=function(url){_this.vars.requestUrl=url;};_this.getRequestUrl=function(){return _this.vars.requestUrl;};_this.setBounds=function(bounds){_this.params.bounds=bounds;};_this.getBounds=function(bounds){return _this.params.bounds;};_this.setMask=function(mask){_this.vars.mask=mask;};_this.getMask=function(){return _this.vars.mask;};_this.setGeocoder=function(geocoder){_this.vars.geocoder=geocoder;};_this.getGeocoder=function(){return _this.vars.geocoder;};_this.setNewNeedMarker=function(marker){_this.vars.newNeedMarker=marker;};_this.getNewNeedMarker=function(){return _this.vars.newNeedMarker;};_this.init=function(config){_this.setConfig(config);_this.setRequestUrl(window.location.protocol+'//'+window.location.host+'/public/request.php');_this.initMap(_this.getConfig('base_lat'),_this.getConfig('base_lng'),_this.getConfig('base_zoom'));_this.initGeocoder();_this.initBounds();};_this.initMap=function(lat,lng,zoom){_this.setMap(_this.createMap(lat,lng,zoom));_this.setMarkers(L.markerClusterGroup({spiderfyDistanceMultiplier:1.5}));_this.addTitleLayer();_this.getMap().addLayer(_this.getMarkers());_this.vars.map.addLayer(_this.vars.markers);};_this.createMap=function(lat,lng,zoom){return L.map('needs-map-map').setView([lat,lng],zoom);};_this.addTitleLayer=function(){L.tileLayer('../../%7bs%7d.tile.osm.org/%7bz%7d/%7bx%7d/%7by%7d.png',{attribution:'© OpenStreetMap contributors'}).addTo(_this.getMap());};_this.initGeocoder=function(){_this.setGeocoder(L.esri.Geocoding.geocodeService());};_this.initBounds=function(){var locationMapName=_this.getConfig('api_bounds_search');if(locationMapName) {$.ajax({method:'GET',url:'http://nominatim.openstreetmap.org/search/pl/'+locationMapName+'/?format=json',data:{polygon_geojson:'1'},success:_this.parseApiBounds,error:function(jqXHR,textStatus,errorThrown){console.log(errorThrown);_this.parseBounds();}});} else {console.log('no api_bounds_search defined in config');_this.parseBounds();}};_this.parseApiBounds=function(response){var latLngs=[];var osmId=_this.getConfig('osm_id');var coordinates=null;if(typeof response!='undefined'&&response) {if(osmId!='') {if(parseInt(osmId)===0) {if(typeof response[0].geojson!='undefined'&&typeof response[0].geojson.coordinates!='undefined'&&response[0].geojson.coordinates.length>0) {coordinates=response[0].geojson.coordinates[0];}} else {for(var i=0;i0) {coordinates=response[i].geojson.coordinates[0];} else console.log('geojson.coordinates are missing for '+i+' result');}} else console.log('osm_id is missing for '+i+' result');}}} else console.log('no osm_id defined in config');} if(coordinates==null) {console.log('could not find matching result');if(typeof json_bounds!='undefined') {coordinates=json_bounds;} else console.log('no json_bounds defined');} if(coordinates!=null) {for(var i=0;i'});var marker=L.marker(pos,{icon:icon});marker.bindPopup('
'+category+' ('+date+')
W trakcie
'+text+'
',{offset:new L.Point(-1,-24)}).openPopup();_this.getMarkers().addLayer(marker);};_this.addNewNeedMarker=function(lat,lng){var pos=new L.LatLng(lat,lng);var icon=L.divIcon({className:'map-marker new-need-marker',iconSize:null,iconAnchor:[11,33],html:''});if(!_this.getNewNeedMarker()) {var marker=L.marker(pos,{icon:icon});marker.addTo(_this.getMap());_this.setNewNeedMarker(marker);} else {_this.getNewNeedMarker().setLatLng(pos);}};_this.removeNewNeedMarker=function(){if(_this.getNewNeedMarker()) {_this.getNewNeedMarker().remove();_this.setNewNeedMarker(null);}};_this.showCoordinates=function(lat,lng){var text_lat='Szerokość geograficzna '+magellan(lat).latitude().toDMS()+'';var text_lng='Długość geograficzna '+magellan(lng).latitude().toDMS()+'';_this.showPopup("
Współrzędne
"+text_lat+"
"+text_lng+"
",lat,lng);};_this.showPopup=function(content,lat,lng){_this.setPopup(L.popup());_this.getPopup().setLatLng([lat,lng]);_this.getPopup().setContent(content);_this.getPopup().openOn(_this.getMap());};_this.setCenter=function(lat,lng){_this.getMap().setView([lat,lng],_this.getMap().getZoom());};_this.zoomIn=function(){_this.getMap().zoomIn();};_this.zoomOut=function(){_this.getMap().zoomOut();};_this.reverseGeocode=function(lat,lng,callback){_this.getGeocoder().reverse().latlng([lat,lng]).run(function(error,result){if(typeof result!=="undefined"&&typeof result.address!=="undefined"&&callback){callback(result.address);}else{console.info(error);}});};_this.geocode=function(street,callback,error_callback){_this.getGeocoder().geocode().country('polska').city($('#needs_map_city').html()).address(street).run(function(error,result){if(typeof result!=="undefined"&&typeof result.results!=="undefined"&&typeof result.results[0]!=="undefined"&&typeof result.results[0].latlng!=="undefined"&&callback){var bounds=L.latLngBounds(_this.getBounds());if(bounds.contains(result.results[0].latlng)){callback(result.results[0].latlng.lat,result.results[0].latlng.lng);}else{error_callback('Punkt nie znajduje się w obszarze!')}}else{error_callback('Nie udało się wyznaczyć położenia!')}});};_this.geolocate=function(callback,reverseGeocodeCallback,error_callback,options) {navigator.geolocation.getCurrentPosition(function(position){var bounds=L.latLngBounds(_this.getBounds());if(typeof position.coords!='undefined'&&typeof position.coords.latitude!='undefined'&&typeof position.coords.longitude!='undefined'&&position.coords.latitude&&position.coords.longitude) {var currentLatLng=new L.LatLng(position.coords.latitude,position.coords.longitude);if(bounds.contains(currentLatLng)){_this.reverseGeocode(position.coords.latitude,position.coords.longitude,reverseGeocodeCallback);callback(position.coords.latitude,position.coords.longitude);}else{error_callback('Punkt nie znajduje się w obszarze!')}} else {error_callback('Nie udało się wyznaczyć położenia!');}},function(error){console.log(error);error_callback('Nie udało się wyznaczyć położenia!');},options);};_this.ajaxRequest=function(dataSet,successCallback,type,dataType){type=typeof a!=='undefined'?type:'POST';dataType=typeof dataType!=='undefined'?dataType:'JSON';$.ajax({type:type,url:_this.vars.requestUrl,data:dataSet,success:successCallback,dataType:dataType});};_this.fitBounds=function(bounds){_this.getMap().fitBounds(bounds);};var publicFunctions={init:function(config){_this.init(config);},fitBounds:function(bounds){_this.fitBounds(bounds);},addMarker:function(lat,lng,icon,text,category,date){_this.addMarker(lat,lng,icon,text,category,date);},addNewNeedMarker:function(lat,lng){_this.addNewNeedMarker(lat,lng);},removeNewNeedMarker:function(){_this.removeNewNeedMarker();},showCoordinates:function(lat,lng){_this.showCoordinates(lat,lng);},showPopup:function(content,lat,lng){_this.showPopup(content,lat,lng);},setCenter:function(lat,lng){_this.setCenter(lat,lng);},zoomIn:function(){_this.zoomIn();},zoomOut:function(){_this.zoomOut();},reverseGeocode:function(lat,lng,callback){_this.reverseGeocode(lat,lng,callback);},geocode:function(street,callback,error_callback){_this.geocode(street,callback,error_callback);},geolocate:function(callback,error_callback,options){_this.geolocate(callback,error_callback,options);}};return publicFunctions;});