Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.46 KB | None | 0 0
  1. <?php
  2. $username = 'aname';
  3. $password = 'apassword;
  4. $host = 'localhost';
  5. $dbname = 'adb';
  6.  
  7. // open the database
  8. try {
  9. $db = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  10. } catch(PDOException $e) {
  11. // send the PDOException message
  12. $ajxres=array();
  13. $ajxres['resp']=40;
  14. $ajxres['dberror']=$e->getCode();
  15. $ajxres['msg']=$e->getMessage();
  16. sendajax($ajxres);
  17. }
  18.  
  19. try {
  20. $sql="SELECT protocol,jurisdiction,date,time,comments,video,lat,lng FROM Incidents";
  21. $stmt = $db->prepare($sql);
  22. $stmt->execute();
  23. } catch(PDOException $e) {
  24. print "db error ".$e->getCode()." ".$e->getMessage();
  25. }
  26.  
  27. $ajxres=array(); // place to store the geojson result
  28. $features=array(); // array to build up the feature collection
  29. $ajxres['type']='FeatureCollection';
  30.  
  31. // go through the list adding each one to the array to be returned
  32. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  33. $lat=$row['lat'];
  34. $lng=$row['lng'];
  35. $prop=array();
  36. $prop['protocol']=$row['protocol'];
  37. $prop['jurisdiction']=$row['jurisdiction'];
  38. $prop['date']=$row['date'];
  39. $prop['time']=$row['time'];
  40. $prop['comments']=$row['comments'];
  41. $prop['video']=$row['video'];
  42. $f=array();
  43. $geom=array();
  44. $coords=array();
  45.  
  46. $geom['type']='Point';
  47. $coords[0]=floatval($lng);
  48. $coords[1]=floatval($lat);
  49.  
  50. $geom['coordinates']=$coords;
  51. $f['type']='Feature';
  52. $f['geometry']=$geom;
  53. $f['properties']=$prop;
  54.  
  55. $features[]=$f;
  56.  
  57. }
  58.  
  59. // add the features array to the end of the ajxres array
  60. $ajxres['features']=$features;
  61. // tidy up the DB
  62. $db = null;
  63. sendajax($ajxres); // no return from there
  64.  
  65. function sendajax($ajx) {
  66. // encode the ajx array as json and return it.
  67. $encoded = json_encode($ajx);
  68. exit($encoded);
  69. }
  70. ?>
  71.  
  72. var map;
  73. var centerlatlng = L.latLng(35.85199,-119.6577);
  74.  
  75. var southWest = L.latLng(3.3,-154.2),
  76. northEast = L.latLng(61.5,-58.4),
  77. bounds = L.latLngBounds(southWest, northEast);
  78.  
  79.  
  80.  
  81. var myIcon1 = L.icon({
  82. iconUrl: 'http://www.broomfield.org/images/pages /N315/blue%20heading%20icons_building.png',
  83. iconSize: [30, 30]
  84. });
  85.  
  86.  
  87. var red = L.icon({
  88. iconUrl: 'img/red.png',
  89. iconSize: [30, 30]
  90. });
  91.  
  92. var lyr;
  93.  
  94.  
  95. $(document).ready(function (){
  96.  
  97.  
  98. // Creating a tile layer using ESRI - World Physical Map
  99. var aLayerOne = L.tileLayer('http://services.arcgisonline.com/arcgis /rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.png', {
  100. maxZoom: 19
  101.  
  102. });
  103.  
  104. // Creating a tile layer using MapBox
  105. var aLayerTwo = L.tileLayer('http://api.tiles.mapbox.com /v4/davidjbailey.jg612ji1/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZGF2aWRqYmFpbGV5IiwiYSI6InFxSzA5bjgifQ.tDw01mG43kf6hWUIAtBEAw#4/33.75/-117.87', {
  106. attribution: 'Developed <a href="">DB</a>',
  107. maxZoom: 18
  108. });
  109.  
  110. // Creating a geojson layer using geojson file
  111. // You can set the style using Leaflet Path Class - http://leafletjs.com/reference.html#path
  112.  
  113.  
  114. // Incidents geojson layer
  115. lyr = L.geoJson(Incidents, {
  116. onEachFeature: makePopup
  117. }
  118. )
  119.  
  120.  
  121. // Cities
  122. var aLayerThree = L.geoJson(aGeoJson1, {
  123. pointToLayer: function (feature, latlng) {
  124. return L.marker(latlng,{icon: myIcon1});
  125. }, // end of point to layer{
  126.  
  127. onEachFeature: function(feature, layer){
  128.  
  129. layer.on('load', function(e){
  130. marker.openPopup();
  131. }); // event functio
  132.  
  133. layer.on('click', function(e){
  134. map.setView([e.latlng.lat, e.latlng.lng], 11);
  135. map.removeLayer(aLayerThree)
  136. aDiv.innerHTML = "<center>" + "<strong>Welcome to </strong>" + "<strong>" + feature.properties.name + "!" + "</strong>" + "<br>" + "<h5>" + "Explore the data by zooming in" + "<br>" +
  137. "and out and by clicking on points." + "</h5>" + "------------" + "<h5>" + "Add an incident to the map by clicking on the" +
  138. "<br>" + "marker symbol in the upper left corner of the map." + "</h5>" + "</center>"
  139. }); // event function
  140.  
  141. layer.on('mouseover', function(e){
  142. aDiv.innerHTML = "<strong>" + feature.properties.name + "</strong>"
  143.  
  144. }); // End of mouseover event function
  145. layer.on('mouseout', function(e){
  146. aDiv.innerHTML = "<strong>Click on your city!</strong>"
  147.  
  148.  
  149. });
  150.  
  151.  
  152. }});
  153.  
  154.  
  155.  
  156. //Create our Map Object
  157. map = L.map('myMap', {
  158. center: centerlatlng,
  159. zoom: 6,
  160. maxBounds: bounds,
  161. minZoom: 4,
  162. maxZoom: 18,
  163.  
  164. layers: [aLayerThree, aLayerTwo]
  165. });
  166.  
  167. L.drawLocal.draw.toolbar.buttons.marker = 'Add an incident to the map!';
  168.  
  169.  
  170. var drawControl = new L.Control.Draw({
  171. draw: {
  172. polygon: false,
  173. polyline: false,
  174. rectangle: false,
  175. marker:{
  176. icon: red
  177. },
  178. circle: false,
  179. },
  180.  
  181. edit: {
  182. featureGroup: UserMarker
  183. }
  184. });
  185. map.addControl(drawControl);
  186.  
  187. map.on('draw:created', function (e) {
  188. var type = e.layerType,
  189. layer = e.layer;
  190. var coords = e.layer._latlng;
  191. console.log(coords);
  192. UserMarker.addLayer(layer);
  193. var popup = L.popup({maxWidth: 1400})
  194. .setLatLng(layer.getLatLng())
  195. .setContent('<form role="form" id="form" enctype="multipart/form-data" onsubmit="addMarker()">'+
  196.  
  197.  
  198. '<div class="form-group">'+
  199. '<label class="control-label col-sm-10"><strong>Was the person following protocol?</strong></label>'+ "<br>" +
  200. '<input type="text" placeholder="Yes, No, or I dont know" id="protocol" name="protocol" class="form-control"/>'+
  201. '</div>'+
  202.  
  203. '<div class="form-group">'+
  204. '<label class="control-label col-sm-10"><strong>Jurisdiction </strong></label>'+ "<br>" +
  205. '<input type="text" placeholder="City, State, County, or Other" id="jurisdiction" name="jurisdiction" class="form-control"/>'+
  206. '</div>'+
  207.  
  208.  
  209. '<div class="form-group">'+
  210. '<label class="control-label col-sm-10"><strong>Date </strong></label>'+ "<br>" +
  211. '<input type="text" placeholder="8/1/2015" id="date" name="date" class="form-control"/>'+
  212. '</div>'+
  213.  
  214. '<div class="form-group">'+
  215. '<label class="control-label col-sm-10"><strong>Time of day </strong> </label>'+ "<br>" +
  216. '<input type="text" placeholder="Morning, Afternoon, or Night" id="time" name="time" class="form-control"/>'+
  217. '</div>'+
  218.  
  219. '<div class="form-group">'+
  220. '<label class="control-label col-sm-10"><strong>Comments </strong></label>'+ "<br>" +
  221. '<input type="text" placeholder="Briefly tell us what happened" id="comments" name="comments" class="form-control"/>'+
  222. '</div>'+
  223.  
  224. '<div class="form-group">'+
  225. '<label class="control-label col-sm-10"><strong>Video Link </strong></label>'+ "<br>" +
  226. '<input type="text" placeholder="Do you have a video? Add link here" id="video" name="video" class="form-control"/>'+
  227. '</div>'+
  228.  
  229. '<input style="display: none;" type="text" id="lat" name="lat" value="'+coords.lat.toFixed(6)+'" />'+
  230. '<input style="display: none;" type="text" id="lng" name="lng" value="'+coords.lng.toFixed(6)+'" />'+
  231.  
  232. '<div class="form-group">'+
  233. '<div style="text-align:center;" class="col-xs-11"><button style="text-align:center;" type="submit" id="submit" value="submit" class="btn btn-primary trigger-submit">Submit</button></div>'+
  234. '</div>'+ "<br>" +
  235.  
  236. '<strong>' + '-' + '</strong'+
  237.  
  238. '</form>')
  239. .openOn(map);
  240.  
  241. $('#form').submit(function(e){
  242. e.preventDefault();
  243. });
  244.  
  245. $('#submit').click(function(e) {
  246. console.log('clicked!');
  247.  
  248.  
  249. //do your own request an handle the results
  250. $.ajax({
  251. url: 'submit.php',
  252. type: 'post',
  253. dataType: 'json',
  254. data: $("#form").serialize(),
  255. complete: function(data) {
  256. console.log("DONE");
  257. window.location = "Map_member1.php"
  258. }
  259.  
  260.  
  261. });
  262. });
  263.  
  264.  
  265. }
  266.  
  267. )
  268.  
  269.  
  270. //Adding a Scale Control
  271. L.control.scale().addTo(map);
  272.  
  273.  
  274. //adding a Layer Control
  275. var baseLayers = {
  276. "Satellite imagery": aLayerOne,
  277. "Streets": aLayerTwo
  278. };
  279.  
  280. // create a variable holding the overlays
  281. var overLays = {
  282. 'Cities': aLayerThree,
  283.  
  284.  
  285. };
  286.  
  287.  
  288. function askForIndidents() {
  289. $.ajax({
  290. url: 'get.php',
  291. dataType: 'json',
  292. data: data,
  293. success: showIncidents
  294. });
  295. }
  296.  
  297. function showIncidents(ajxresponse) {
  298. lyr.clearLayers();
  299. lyr.addData(ajxresponse);
  300. }
  301.  
  302. map.on('moveend', whenMapMoves);
  303.  
  304.  
  305.  
  306. L.control.layers(baseLayers, overLays, {collapsed: false}).addTo(map);
  307.  
  308. $(document).ready(function() {
  309. $.ajaxSetup({cache:false});
  310. $('#myMap').css('height', ($(window).height() - 50));
  311. getUsers();
  312. });
  313.  
  314. $(window).resize(function () {
  315. $('#myMap').css('height', ($(window).height() - 50));
  316. }).resize();
  317.  
  318. ///Creating custom control here
  319. // part 1/3 : Creates a control with the given position
  320. var aControl = L.control({position: 'bottomright'});
  321.  
  322. // part 2/3 : Should contain code that creates all the neccessary DOM elements for the control
  323. aControl.onAdd = function () {
  324.  
  325. aDiv = L.DomUtil.create('div', 'aCustomC'); // create a div with a class "aCustomC"
  326. aDiv.innerHTML = "<strong>Click on your city!</strong>" // Each HTML element has an innerHTML property that defines both the HTML code and the text that occurs between that element's opening and closing tag.
  327.  
  328. return aDiv;
  329. }; // end function onAdd
  330.  
  331. // part 3/3 : Add the control to the map
  332. aControl.addTo(map);
  333.  
  334. // create the geocoding control and add it to the map
  335. var searchControl = new L.esri.Controls.Geosearch({useMapBounds: 8}).addTo(map);
  336.  
  337. // create an empty layer group to store the results and add it to the map
  338. var results = new L.LayerGroup().addTo(map);
  339.  
  340. // listen for the results event and add every result to the map
  341. searchControl.on("results", function(data){
  342. results.clearLayers();
  343. for (var i = data.results.length - 1; i >= 0; i--) {
  344. results.addLayer(L.marker(data.results[i].latlng));
  345.  
  346.  
  347. };
  348. });
  349.  
  350. });// end document ready
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement