I have created a sanity schema which works perfectly according to the tutorial. However I have a leaflet.js plugin and I am trying to get it to auto find my location when I create a new template in the sanity studio. This was already done in the tutorial below, but when I do it, I get the sanity map showing up but I do not get the marker on my current location. Instead I get the default San-Francisco.
In the tutorial the lady gets allows the browser to share her location. However I do not get that prompt. Is this something to do with localhost?
I am following this tutorial but I don't know what I missed.
Relevant parts from 31.00-37.00. Tutorial below:
https://www.youtube.com/watch?v=YtFfUER8ta8
Below is my posts.js
const getPosition = (options) => {
if (navigator.geolocation) {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
}
};
export default {
name: "post",
title: "Blog Post",
type: "document",
initialvalue: async () => ({
postedAt: await getPosition()
.then(({ coords }) => {
const { latitude, longtitude, altitude } = coords;
return {
_type: "geopoint",
lat: latitude,
lng: longtitude,
alt: altitude || undefined,
};
})
.catch(() => undefined),
}),
fields: [
{
name: "title",
title: "Title",
type: "string",
},
{
name: "postedAt",
type: "geopoint",
title: "Location",
},
{
name: "slug",
title: "Slug",
type: "slug",
options: {
source: "title",
maxLength: 96,
},
},
{
name: "author",
title: "Author",
type: "reference",
to: { type: "author" },
},
{
name: "mainImage",
title: "Main image",
type: "image",
options: {
hotspot: true,
},
},
{
name: "categories",
title: "Categories",
type: "array",
of: [{ type: "reference", to: { type: "category" } }],
},
{
name: "publishedAt",
title: "Published at",
type: "datetime",
},
{
name: "body",
title: "Body",
type: "blockContent",
},
],
preview: {
select: {
title: "title",
author: "author.name",
media: "mainImage",
},
prepare(selection) {
const { author } = selection;
return Object.assign({}, selection, {
subtitle: author && `by ${author}`,
});
},
},
};
leaflet-input.json
{
"tileLayer": {
"attribution": "© OpenStreetMap contributors",
"url": "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
}
}
Related
I'm using NestJS in the vanillaJS way (because I can't write typescript) and I have a many-to-many relation from user to bubble.
I want to write a updateUser-Route in which I also want to be able to update the bubble-affiliation.
But when I do so like this:
user.controller.js:
#Patch(':id')
#Bind(Param('id'), Body())
async updateUser(id, body) {
if (Object.keys(body).length !== 0) {
return await this.userService.updateUser(id, body);
}
throw new BadRequestException('Missing Body');
}
user.service.js:
async updateUser(id, user) {
return await this.userRepository.update(id, user);
}
I get this error:
Cannot query across many-to-many for property bubble
This is my user.entity.js:
var EntitySchema = require('typeorm').EntitySchema;
var User = require('./user.model').User;
var Bubble = require('../bubble/bubble.model').Bubble;
module.exports = new EntitySchema({
name: 'User',
target: User,
columns: {
id: {
primary: true,
type: 'int',
},
handle: {
type: 'varchar',
},
lastCheck: {
type: 'datetime',
default: () => 'NOW()',
},
rating: {
type: 'int',
},
},
relations: {
bubble: {
type: 'many-to-many',
target: 'Bubble',
joinTable: true,
cascade: true,
},
},
});
in postman I try to call it like this:
{
"rating": 10,
"bubble": [{
"id": "1234"
}]
}
if I leave bubble out it works and rating gets updated. with bubble I get the error described above
I want to display a hyperlink on the bottom of the popup template in arcgis esri map. I've added the code I've tried, but hyperlink is not displaying in the popup template. Only the fields table is displaying. Could you please have look into this code and let me know if I've missed something.
.ts file
const popUpTemplate = new PopupTemplate({
title: "{name}",
content: [
{
type: "fields",
fieldInfos: [
{
fieldName: "PhysicianName",
label: "Physician Name"
},
{
fieldName: "Practice",
label: "Primary Practise",
},
]
},
new CustomContent({
outFields: ["*"],
creator: (graphic) => {
const a = document.createElement("a");
a.href = "https://www.youtube.com/";
a.target = "_blank";
a.innerText = graphic.attributes.PhysicianName;
return a;
}
})
],
outFields: ["*"]
});
const myLayer = new FeatureLayer({
source: physicianData.map((d,i)=>(
{
geometry: new Point({
longitude: d.Longitude,
latitude: d.Latitude
}),
attributes: {
ObjectID: i,
name : d.PhysicianName,
PhysicianName : d.PhysicianName,
Practice : d.Practice,
...d
}
}
)),
fields: [{
name: "ObjectID",
alias: "ObjectID",
type: "oid"
},
{
name: "name",
alias: "Physician : ",
type: "string"
},
{
name: "PhysicianName",
alias: "Physician Name",
type: "string"
},
{
name: "Practice",
alias: "Practice",
type: "string"
},
],
objectIdField: 'ObjectID',
geometryType: "point",
popupTemplate : popUpTemplate,
});
.html file
<div #mapViewNode></div>
I think your issue is that you need to define the fields of the layer.
If you are working with client side graphics and FeatureLayer, you need to set:
source, the collection of graphics (geometry + attributes)
objectIdField, the field that is going to identify the graphics, type oid (*)
fields, the name, alias, and type of each field of the graphics attributes
In your case, just by deducing the possible attributes, it should be something like this
const dataFeedLayer = new FeatureLayer({
source: locationData.map((d,i)=>(
{
geometry: new Point({
longitude: d.longitude,
latitude: d.latitude
}),
attributes: {
ObjectID: i,
...d
}
}
)),
objectIdField: 'ObjectID',
popupTemplate : popUpTemplate,
fields: [
{
name: "ObjectID",
alias: "ID",
type: "oid"
},
{
name: "PhysicianName",
alias: "Physician Name",
type: "string"
},
{
name: "PrimarySpecialty",
alias: "Primary Specialty",
type: "string"
},
{
name: "url",
alias: "Url",
type: "string"
}
]
});
When creating a FeatureLayer from client-side features, this property should be set in the constructor along with the source property. The objectId field also must be set either in this array or in the objectIdField property.
From ArcGIS JS API - FeatureLayer fields
I have this JSON
const Menu = [{
icon: "home",
text: "Inicio",
url: {
name: "home"
},
typeUrl: "exact"
},
{
heading: "Operaciones"
},
{
icon: "settings",
"icon-alt": "settings",
text: "Operación",
model: true,
children: [{
icon: "add",
text: "Cargar Pedidos",
url: {
name: "cargarpedidos"
}
},
{
icon: "playlist_add_check",
text: "Aprobar Pedidos"
},
{
icon: "content_copy",
text: "Remitir Pedidos"
}
]
},
{
heading: "Informes"
},
{
icon: "widgets",
"icon-alt": "widgets",
text: "Informe",
model: false,
children: [{
icon: "view_module",
text: "Usuarios"
},
{
icon: "view_module",
text: "Perfiles"
},
{
icon: "view_module",
text: "Permisos Perfiles"
},
{
icon: "view_module",
text: "Resetear Password"
},
{
icon: "view_module",
text: "Cambiar Password"
}
]
},
{
heading: "APSI"
},
{
icon: "view_module",
text: "Informes del APSI"
},
{
heading: "Administaciones"
},
{
icon: "extension",
"icon-alt": "extension",
text: "Administración",
model: false,
children: [{
icon: "face",
text: "Usuarios"
},
{
icon: "assignment_ind",
text: "Perfiles"
},
{
icon: "settings",
text: "Permisos Perfiles"
},
{
icon: "cached",
text: "Resetear Password"
},
{
icon: "fingerprint",
text: "Cambiar Password"
}
]
},
{
heading: "Mantenimientos"
},
{
icon: "build",
"icon-alt": "build",
text: "Mantenimiento",
model: true,
children: [{
icon: "group_work",
text: "Departamentos"
},
{
icon: "room",
text: "Locales"
},
{
icon: "donut_large",
text: "Unidades de Medida"
},
{
icon: "spellcheck",
text: "Articulos"
},
{
icon: "toc",
text: "Categorías"
},
{
icon: "supervisor_account",
text: "Usuario Aprobador"
}
]
}
];
export default Menu;
I use it to create the menu of my system that I am developing with VueJS + Vuetify and I need to filter it through the "text" field by words that contain it regardless of position, in the style of SQL's like '%filter%', also without distinguish upper and lower case. As far as possible don't distinguish accents (but this is already very picky, if it is not possible or it is very cumbersome, I can skip it).
Also in the case that the pattern of coincidence is in a child node and not in the father, does this father also have to appear in the filter, is it possible to do this with a Javascript function?
The menu looks like this:
I expect this behavior
I am not sure but if you want to get text fields of children, I think something like that should do it. You just need to initialize all your parents with empty children arrays:
tempArr = Menu.filter(function (elem) {
return elem.children == null ;
});
textFields = tempArr.map(({ text }) => text)
Here is how you can filter match regular expression in an array.
var arr = [{
icon: "add",
text: "Cargar Pedidos",
url: {
name: "cargarpedidos"
}
},
{
icon: "playlist_add_check",
text: "Aprobar Pedidos"
},
{
icon: "content_copy",
text: "Remitir Pedidos"
},
{
icon: "content_copy",
text: "Remitir Pedisddos"
},
{
icon: "content_copy",
text: "Remitir Pediados"
},
{
icon: "content_copy",
text: "Remitir asdaasd"
}
];
var name = "dido";
var regex = "/" + name + "/g";
var filtered = arr.filter(
(val) => val.text.match(name)
);
console.log(filtered);
These are the basics of filtering. If you want to search for any property in an array object than use this function:
var result = Menu.filter(function(o) {
return Object.keys(o).some(function(k) {
return o[k].toString().toLowerCase().indexOf('dido') != -1;
})
})
console.log(result)
Trying to create an event that changes a String called status in my NetworkApp collection.
Event:
Template.app_detail.events({
'click .accept': function (e, t) {
console.log("Accept");
NetworkApp.update(this._id, {$set:{
status: "Accepted"
}});
},
'click .reject': function (e, t) {
console.log("Reject");
NetworkApp.update(this._id, {$set:{
status: "Rejected"
}});
}
})
It updates the last time the application was modified but not the status. No errors appear in the console but it does log Accepted or Rejected so the code can connect to the db and the helper is being triggered by the buttons. Any help is appreciated!~
Simple Schema:
NetworkAppSchema = new SimpleSchema({
ign: {
type: String,
label: "IGN"
},
discordName: {
type: String,
label: "Discord Name"
},
memberlength: {
type: String,
label: "How long have you been a member at Digital Hazards?"
},
languageKnown: {
type: String,
label: "What languages do you know?",
autoform: {
type: 'textarea'
}
},
whyyou: {
type: String,
label: "Why do you want to join the Network staff?",
autoform: {
type: 'textarea'
}
},
applicant: {
type: String,
label: "Applicant",
autoValue: function() {
return Meteor.userId();
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Applied At",
autoValue: function() {
return new Date();
},
autoform: {
type: "hidden"
}
},
status: {
type: String,
label: "Status",
autoValue: function() {
return "Pending";
},
autoform: {
type: "hidden",
}
}
});
autoValue does not mean initial value: your autoValue functions are running every time.
For createdAt for example you should have:
createdAt: {
type: Date,
denyUpdate: true,
autoValue() {
if (this.isInsert) return new Date();
},
},
this will avoid the createdAt ever changing after insert.
Similarly for status:
status: {
type: String,
label: "Status",
autoValue() {
if (this.isInsert) return "Pending";
},
autoform: {
type: "hidden",
}
}
I have the following Scheme:
dGroup = new SimpleSchema({
title: { type: String, optional: true },
element: { type: String, optional: true }
});
MongoDB.attachSchema(new SimpleSchema({
title: { type: String },
slug: { type: String, unique: true },
language: { type: String, defaultValue: "en" },
group: { type: [dGroup], optional: true },
}));
... and in the DB I got this:
{ "_id" : "ag9qXWpCYm87kZbEk", "title" : "Test", "slug" : "test", "language" : "en" }
Now I want to add a dGroup -> title:
updates['group.title'] = 'insert this as a new group title with no element';
MongoDB.update({ _id: Id }, { $push: updates }, function(error) { if(error) console.warn(error); });
But this doesn't work. So I need some help to add subdocuments in meteor in case they do not exist.
Try declaring your object first and push it properly, like this:
var newGroup = {
title: 'insert this as a new group title with no element'
};
MongoDB.update({ _id: Id }, { $push: {group: newGroup }}, function(error) { if(error) console.warn(error); });