How can I do when I retrieve a person from the BD and create a link to direct to the grave on the map?
I do a search in the BD and when I find a person, I want to create a url that, when clicked, shows the map of the cemetery showing the location of the grave.
Here's the code I have so far. It shows me the map, but it doesn't show the grave marker.
<script >
$(document).ready(function(){
var prev_path = prev_marker = null;
$('.btn_search').on('click',function(){
var firstname = $('input[name="deceased_firstname"]').val();
var lastname = $('input[name="deceased_lastname"]').val();
/* var f_firstname = firstname.replace(/ /g, '%20');
var l_lastname = lastname.replace(/ /g, '%20');
*/
var url = '<?=base_url()?>/pages/search_burial/'+firstname+'/'+lastname;
console.log(url);
$.getJSON(url, function(data){
if (data == null) { alert("no results found!"); }
console.log(data);
var icon_grave = L.icon({
iconUrl: "<?=base_url()?>" +'user_template/icons/catholicgrave.png',
iconSize: [30,30] });
var latlngs = []
if(data != null || data != undefined) {
var route = JSON.parse(data.lot_coordinates);
for (var i = 0, len = route.length; i < len; i++) {
latlngs.push(new L.LatLng(route[i][0], route[i][1]));
}
} else {
latlngs = [];
}
var path = L.polyline(latlngs);
var marker = L.marker(latlngs[len - 1]).addTo(map).bindPopup("</br>"+"<strong>Fullname:</strong>"+" "+data.occupant_firstname+" "+data.occupant_middlename+" "+ data.occupant_lastname +"</br>" +
"<strong>Date of Birth:</strong>"+" " +data.occupant_dateofbirth + "</br>"+
"<strong>Date of Death:</strong>"+" " +data.occupant_dateofdeath + "</br>"+
"<strong>Garden:</strong>"+" " +data.garden_name + "</br>"+
"<strong>Block:</strong>"+" " +data.block_name + "</br>"+
"<strong>Lot:</strong>"+" " +data.lot_name + "</br>"+
"<strong>Longitude:</strong>"+" "+data.lot_long + "</br>"+
"<strong>Latitude:</strong>"+" "+data.lot_lat ).openPopup();
if (prev_path != null){
map.removeLayer(prev_path);
}
if(prev_marker != null){
map.removeLayer(prev_marker);
}
prev_path = path;
prev_marker = marker;
//map.removeLayer(path)
//map.addLayer(L.marker(latlngs[0]));
if(latlngs.length > 0) {
map.addLayer(marker);
}
map.addLayer(path);
setTimeout(function(){ path.snakeIn(); }, 3000);
//path.snakeIn();
});
});
});
</script>
<script>
// Creating a map object
var map = L.map('map').setView([-1.055588,2.109375],1);
var base_url = "<?=base_url()?>";
// Creating a Layer object
L.tileLayer('<?php echo base_url("user_template/map/{z}/{x}/{y}.png"); ?>',
{
minZoom: 2,
maxZoom: 4,
continousWorld: false,
noWrap: true,
}).addTo(map);
var bounds = new L.LatLngBounds(new L.LatLng(-70.020587,-132.242584), new L.LatLng(69.900118,140.680943));
map.fitBounds(bounds);
//add standard controls
L.control.coordinates().addTo(map);
//add configured controls
L.control.coordinates({
position:"bottomleft",
decimals:6,
decimalSeperator:".",
labelTemplateLat:"Latitude: {y}",
labelTemplateLng:"Longitude: {x}"
}).addTo(map); //mao ni siya bert naa diay sa taas ang code adto
/*Legend specific*/
var legend = L.control({ position: "bottomright" });
legend.onAdd = function(map) {
var div = L.DomUtil.create("div", "legend");
div.innerHTML += "<h5>Legend:</h5>";
div.innerHTML += '<i style="background: #e8851e"></i><span>Garden</span><br>';
div.innerHTML += '<i style="background: #448D40"></i><span>Block</span><br>';
div.innerHTML += '<i style="background: #ff0000"></i><span>Lot</span><br>';
return div;
};
legend.addTo(map);
var marker_1 = L.marker([-60.064840460104506,13.005095612485837]).addTo(map).bindPopup("Gate is here").openPopup();
map.addLayer(marker_1);
$.getJSON(base_url+"pages/map_gardens", function(data)
{
$.each(data, function(i, field)
{
var mapgarden_longitude_1 = parseFloat(data[0].garden_longitude1);
var mapgarden_latitude_1 = parseFloat(data[0].garden_latitude1);
var mapgarden_longitude_2 = parseFloat(data[0].garden_longitude2);
var mapgarden_latitude_2 = parseFloat(data[0].garden_latitude2);
var mapgarden_longitude_3 = parseFloat(data[0].garden_longitude3);
var mapgarden_latitude_3 = parseFloat(data[0].garden_latitude3);
var mapgarden_longitude_4 = parseFloat(data[0].garden_longitude4);
var mapgarden_latitude_4 = parseFloat(data[0].garden_latitude4);
var polylinePoints = [
[mapgarden_longitude_1, mapgarden_latitude_1],
[mapgarden_longitude_2, mapgarden_latitude_2],
[mapgarden_longitude_3, mapgarden_latitude_3],
[mapgarden_longitude_4, mapgarden_latitude_4],
[mapgarden_longitude_1, mapgarden_latitude_1]];
var polyline = L.polyline(polylinePoints).addTo(map);
});
});
$.getJSON(base_url+"pages/map_gardens", function(data)
{
$.each(data, function(i, field)
{
var mapgarden_longitude_1 = parseFloat(data[i].garden_long1);
var mapgarden_latitude_1 = parseFloat(data[i].garden_lat1);
var mapgarden_longitude_2 = parseFloat(data[i].garden_long2);
var mapgarden_latitude_2 = parseFloat(data[i].garden_lat2);
var mapgarden_longitude_3 = parseFloat(data[i].garden_long3);
var mapgarden_latitude_3 = parseFloat(data[i].garden_lat3);
var mapgarden_longitude_4 = parseFloat(data[i].garden_long4);
var mapgarden_latitude_4 = parseFloat(data[i].garden_lat4);
var mapgarden_longitude_5 = parseFloat(data[i].garden_long5);
var mapgarden_latitude_5 = parseFloat(data[i].garden_lat5);
var mapgarden_longitude_6 = parseFloat(data[i].garden_long6);
var mapgarden_latitude_6 = parseFloat(data[i].garden_lat6);
var mapgarden_longitude_7 = parseFloat(data[i].garden_long7);
var mapgarden_latitude_7 = parseFloat(data[i].garden_lat7);
var mapgarden_longitude_8 = parseFloat(data[i].garden_long8);
var mapgarden_latitude_8 = parseFloat(data[i].garden_lat8);
var mapgarden_longitude_9 = parseFloat(data[i].garden_long9);
var mapgarden_latitude_9 = parseFloat(data[i].garden_lat9);
var mapgarden_longitude_10 = parseFloat(data[i].garden_long10);
var mapgarden_latitude_10 = parseFloat(data[i].garden_lat10);
var mapgarden_longitude_11 = parseFloat(data[i].garden_long11);
var mapgarden_latitude_11 = parseFloat(data[i].garden_lat11);
var mapgarden_longitude_12 = parseFloat(data[i].garden_long12);
var mapgarden_latitude_12 = parseFloat(data[i].garden_lat12);
var mapgarden_longitude_13 = parseFloat(data[i].garden_long13);
var mapgarden_latitude_13 = parseFloat(data[i].garden_lat13);
var mapgarden_longitude_14 = parseFloat(data[i].garden_long14);
var mapgarden_latitude_14 = parseFloat(data[i].garden_lat14);
var mapgarden_longitude_15 = parseFloat(data[i].garden_long15);
var mapgarden_latitude_15 = parseFloat(data[i].garden_lat15);
var mapgarden_longitude_16 = parseFloat(data[i].garden_long16);
var mapgarden_latitude_16 = parseFloat(data[i].garden_lat16);
var polylinePoints_1 = [
[mapgarden_longitude_1, mapgarden_latitude_1],
[mapgarden_longitude_2, mapgarden_latitude_2],
[mapgarden_longitude_3, mapgarden_latitude_3],
[mapgarden_longitude_4, mapgarden_latitude_4],
[mapgarden_longitude_5, mapgarden_latitude_5],
[mapgarden_longitude_6, mapgarden_latitude_6],
[mapgarden_longitude_7, mapgarden_latitude_7],
[mapgarden_longitude_8, mapgarden_latitude_8],
[mapgarden_longitude_9, mapgarden_latitude_9],
[mapgarden_longitude_10, mapgarden_latitude_10],
[mapgarden_longitude_11, mapgarden_latitude_11],
[mapgarden_longitude_12, mapgarden_latitude_12],
[mapgarden_longitude_13, mapgarden_latitude_13],
[mapgarden_longitude_14, mapgarden_latitude_14],
[mapgarden_longitude_15, mapgarden_latitude_15],
[mapgarden_longitude_16, mapgarden_latitude_16],
[mapgarden_longitude_1, mapgarden_latitude_1]];
var polyline = L.polyline(polylinePoints_1, {
color: "#e8851e",
}).addTo(map);
});
});
$.getJSON(base_url+"pages/map_blocks", function(data)
{
$.each(data, function(i, field)
{
var mapblocks_longitude_1 = parseFloat(data[i].block_long1);
var mapblocks_latitude_1 = parseFloat(data[i].block_lat1);
var mapblocks_longitude_2 = parseFloat(data[i].block_long2);
var mapblocks_latitude_2 = parseFloat(data[i].block_lat2);
var mapblocks_longitude_3 = parseFloat(data[i].block_long3);
var mapblocks_latitude_3 = parseFloat(data[i].block_lat3);
var mapblocks_longitude_4 = parseFloat(data[i].block_long4);
var mapblocks_latitude_4 = parseFloat(data[i].block_lat4);
var polygonPoints = [
[mapblocks_longitude_1, mapblocks_latitude_1],
[mapblocks_longitude_2, mapblocks_latitude_2],
[mapblocks_longitude_3, mapblocks_latitude_3],
[mapblocks_longitude_4, mapblocks_latitude_4]];
var poly = L.polygon([polygonPoints],{
color: "green"
}).addTo(map);
});
});
$.getJSON(base_url+"pages/map_lots", function(data)
{
$.each(data, function(i, field)
{
var mapLots_longitude = parseFloat(data[i].lot_long);
var mapLots_latitude = parseFloat(data[i].lot_lat);
var circle = L.circle([mapLots_longitude, mapLots_latitude], {
color: "red",
fillColor: "#f03",
fillOpacity: 1.5,
radius: 50.0
}).addTo(map);
});
});
</script>
I tried implementing image upload page for my app, but unfortunately the request is not reaching the server. I double checked this using tcpdump on the server side. The code doesnt seem to process beyond session.uploadFile in sendImages function
Please let me know if there is any issue with the code
var imageSource = require("image-source");
var frameModule = require("ui/frame");
var Observable = require("data/observable").Observable;
var fromObject = require("data/observable").fromObject;
var ObservableArray = require("data/observable-array").ObservableArray;
var platformModule = require("platform");
var permissions = require("nativescript-permissions");
var imagepickerModule = require("nativescript-imagepicker");
var bghttpModule = require("nativescript-background-http");
var session = bghttpModule.session("image-upload");
var fs = require("file-system");
var page;
var imageName;
var counter = 0;
function pageLoaded(args) {
page = args.object;
}
function onSelectSingleTap(args) {
var context = imagepickerModule.create({
mode: "single"
});
if (platformModule.device.os === "Android" && platformModule.device.sdkVersion >= 23) {
permissions.requestPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE, "I need these permissions to read from storage")
.then(function () {
console.log("Permissions granted!");
startSelection(context);
})
.catch(function () {
console.log("Uh oh, no permissions - plan B time!");
});
} else {
startSelection(context);
}
}
function sendImages(uri, fileUri) {
imageName = extractImageName(fileUri);
var request = {
url: "http://maskingIpForPost:8081/mobilepic/ctk/uploadpic",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"file-Name": imageName,
"uid": 30
},
description: "{ 'uploading': " + imageName + " }"
};
var task = session.uploadFile(fileUri, request);
task.on("progress", progress);
task.on("error", error);
task.on("complete", complete);
task.on("responded", responded);
function responded(e) {
console.log("eventName: " + e.eventName);
console.log("data: " + e.data);
}
function progress(e) {
console.log("currentBytes: " + e.currentBytes);
console.log("totalBytes: " + e.totalBytes);
console.log("eventName: " + e.eventName);
}
function error(e) {
console.log("eventName: " + e.eventName);
console.log("eventName: " + e.responseCode);
console.log("eventName: " + e.response);
}
function complete(e) {
console.log("eventName: " + e.eventName);
console.log("response: " + e.responseCode);
}
return task;
}
function startSelection(context) {
context
.authorize()
.then(function () {
return context.present();
})
.then(function (selection) {
selection.forEach(function (selected_item) {
var localPath = null;
if (platformModule.device.os === "Android") {
localPath = selected_item._android;
} else {
// selected_item.ios for iOS is PHAsset and not path - so we are creating own path
let folder = fs.knownFolders.documents();
let path = fs.path.join(folder.path, "Test" + counter + ".png");
//let saved = imagesource.saveToFile(path, "png");
localPath = path;
}
alert("final path " + localPath);
if (localPath) {
var task = sendImages("Image" + counter + ".png", localPath);
//mainViewModel.get("items").push(fromObject({ thumb: imagesource, uri: "Image" + counter + ".png", uploadTask: task }));
}
counter++;
});
}).catch(function (e) {
console.log(e.eventName);
});
}
function extractImageName(fileUri) {
var pattern = /[^/]*$/;
var imageName = fileUri.match(pattern);
return imageName;
}
exports.pageLoaded = pageLoaded;
exports.onSelectSingleTap = onSelectSingleTap;
On Further research found the following
net.gotev.uploadservice.UploadService is undefined in background-http.android.js. At this moment i am not sure what this means. Would appreciate if anyone has idea about this
You need to change the following line in your code.
var session = bghttpModule.session("image-upload");
It has to be file upload
var session = bghttpModule.session("file-upload");
Just tested your code by using Azure Blob Storage PUT url at my side and got the below response.
ActivityManager: START u0 {act=android.intent.action.OPEN_DOCUMENT typ=image/* cmp=com.android.documentsui/.DocumentsActivity (has extras)} from pid 2835
JS: currentBytes: 4096
JS: totalBytes: 25220
JS: eventName: progress
JS: currentBytes: 25220
JS: totalBytes: 25220
JS: eventName: progress
JS: currentBytes: 25220
JS: totalBytes: 25220
JS: eventName: progress
JS: eventName: responded
JS: data:
JS: eventName: complete
JS: response: 201
thanks for the quick response, i tried running it on a emulator and i faced the above mentioned issue, i tried the same by connecting a device and it worked just fine.
Can someone help me.
I've implemented a file upload / download in UI5 that seems to work but when I download the file it gets corrupted and I can't open it.
For now I'm only testing with image files:
new sap.ui.unified.FileUploader({
buttonOnly: true,
buttonText: "Upload files",
icon: "sap-icon://upload",
change: function(oEvent) {
var oFileUploader = oEvent.getSource();
oItem = oFileUploader.getParent().getParent().getParent();
var sPath = oItem.getBindingContext().getPath();
var files = oEvent.getParameter("files");
var file = files[0];
if (file) {
var oNewFile = {
ID: that.count++,
SurveyAnswerID: oSA.ID,
FileName: oEvent.getParameter("newValue"),
FileBinary: null,
MimeType: "image/jpeg",
Mode: "POST"
};
var reader = new FileReader();
reader.onload = function(evt) {
var binaryString = evt.target.result;
oNewFile.FileBinary = binaryString;
};
reader.readAsBinaryString(file);
} else {
oNewFile.FileBinary = "";
oNewFile.FileName = "";
MessageToast.show("Something went wrong with the file upload.\n Please try again");
}
that._pushItemToFileUploadModel(oNewFile.ID, oNewFile);
that._getFileUploadModel().refresh();
}
})
Download code:
selectionChange: function(oEvent) {
var item = oEvent.getSource().getSelectedItem();
var model = that._getFileUploadModel();
if (item) {
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([item.getDocumentId()], {
type: item.getMimeType()
}));
a.download = item.getFileName();
// Append anchor to body.
document.body.appendChild(a);
a.click();
// Remove anchor from body
document.body.removeChild(a);
}
try {
oEvent.getSource()._oList.removeSelections();
} catch (e) {
//DO nothing
}
},
What an I doing wrong here?
I solved my issue converting the file this way:
var u8_2 = new Uint8Array(atob(data).split("").map(function(c) {
return c.charCodeAt(0);
}));
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob([u8_2], {
type: item.getMimeType()
}));
I am trying to set autoUpdater for mac
var os = require('os');
var electron = require('electron');
var app = electron.app;
var autoUpdater = electron.autoUpdater;
var dialog = electron.dialog;
var BrowserWindow = electron.BrowserWindow;
function createWindow() {
mainWindow = new BrowserWindow();
mainWindow.loadURL('file://' + __dirname + '/index.html');
var url;
if (os.platform() == 'darwin') {
autoUpdater.on('error', function (error) {
dialog.showMessageBox(mainWindow, {
buttons: [],
title: 'Error',
message: JSON.stringify(error)
});
});
url = 'https://www.office.dok32.com/dental/appversion/check.json?version=' + app.getVersion();
}
autoUpdater.setFeedURL(url);
autoUpdater.checkForUpdates();
}
and it returns empty error object when setFeedURL call's.
{"sender":{"_events":{},"_eventsCount":3}}
What I do wrong?
I am developing my mobile application using ionic framework and I want it to connect to my API through ajax. Currenty, in the mobile side, which is I am using Ionic Framework, I want to upload an image and pass it to my api through ajax. I am using Cordova for the upload but it seems it doesn't found the URL I indicated.
Here's the HTML
<ion-footer-bar class="bar bar-positive">
<div class="button-bar">
<button class="button icon-left ion-upload" ng-click="uploadImage()" ng-disabled="image === null">Upload</button>
</div>
</ion-footer-bar>
Here's the uploadImage() function in the controller (Just copied the code in a site. Forgot where) EDIT: added targetPath
$scope.uploadImage = function() {
// Destination URL
var url = "http://192.168.0.19/identificare_api/public/api/plants/image";
var targetPath = $scope.pathForImage($scope.image);
// File name only
var filename = $scope.image;
var options = {
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "multipart/form-data",
params : {'fileName': filename}
};
$cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
var jsonparse = JSON.parse(result);
$scope.showAlert(jsonparse);
}
But in the upload part, I want to do it in ajax to indicate the method for the URL but the problem I don't know what put in data.
$.ajax({
url: "http://192.168.0.19/identificare_api/public/api/plants/image",
type: 'POST',
data:
success:function(json){
var jsonparse = JSON.parse(json);
alert(jsonparse);
},
error:function(){
alert("Error");
}
});
Can someone help me with this issue?
UPDATE: Applied here #Blauharley's comment below
I had another issue here. I returned the $_FILES['image']['tmp_name'] in the API side but it returns nothing but when I returned the $_FILES['image']['name'], it returned my_image.jpg. Why it doesn't have tmp_name?
$scope.uploadImage = function() {
// File for Upload
var targetPath = $scope.pathForImage($scope.image);
$scope.getBase64ImageByURL(targetPath).then(function(base64Image){
var blob = $scope.base64ToBlob(base64Image,'image/jpeg');
var fd = new FormData();
fd.append('image', blob, "my_image.jpg");
fd.append('user_token', "rLUrh37rfTozuBxmemHtlKMgH");
$.ajax({
url: 'http://192.168.0.19/identificare_api/public/api/plants/image',
type: 'POST',
data: fd,
contentType: false,
processData: false,
success:function(res){
alert(res);
},
error:function(err){
alert("Something's wrong with your api. Come on fix it!");
}
});
});
};
$scope.getBase64ImageByURL = function(url) {
var dfd = new $.Deferred();
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
dfd.resolve(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.send();
return dfd.promise();
};
$scope.base64ToBlob = function(base64Image,toMimeType) {
var byteCharacters = atob(base64Image.replace('data:'+toMimeType+';base64,',''));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {
type: toMimeType
});
return blob;
};
ADDED: API side
public function image(){
echo json_encode($_FILES['image']['tmp_name']);
}