Argument of type '{ type: string; features: ({ type: is not assignable to parameter of type 'GeoJsonObject' - leaflet

I am trying to integrate offline map with leaflet, angular and GeoJson.I am using below sample world map json for co-ordinates and adding the json to map post tile definition.
GeoJson file
import * as L from 'leaflet';
countries = geoJson referred above.
this.map = L.map('map');
const tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
});
tiles.addTo(this.map);
L.geoJson(this.countries).addTo(this.map);
but last line is throwing error with below error message. I am new to leaflet . can anyone please suggest?
Error Message:
Argument of type '{ type: string; features: ({ type: string; id: string; properties: { name: string; }; geometry: { type: string; coordinates: number[][][]; }; } | { type: string; id: string; properties: { name: string; }; geometry: { ...; }; })[]; }' is not assignable to parameter of type 'GeoJsonObject | GeoJsonObject[]'
I have referred below stack-overflow links .
Leaflet offline map without map tiles
https://plnkr.co/edit/aB6p7IC2cF7xW41Ju8m7?p=preview&preview
https://www.npmjs.com/package/geojson#readme

Related

TypeOrm updating geography column error: unknown GeoJSON type

I have NestJs+TypeOrm+PostgreSQL project with a table column that is defined like so:
"area" GEOGRAPHY(POLYGON,4326) DEFAULT NULL
My entity column is defined like this:
#Column({
type: 'geography',
spatialFeatureType: 'Polygon',
srid: 4326,
nullable: true,
default: null,
transformer: {
from: (dbValue) => {...},
to: (entityValue: Position[]) => {
const polyObj: Polygon = {
type: 'Polygon',
coordinates: [entityValue]
}
return JSON.stringify(polyObj)
}
}
}
area: Position[]
When I try to update an entry with a new value I get this error:
error: error: unknown GeoJSON type
The TypeOrm logs show this as the parametrized query:
query failed: UPDATE "<tablename>" SET "uuid" = $1, "area" = ST_SetSRID(ST_GeomFromGeoJSON($2), 4326)::geography WHERE "uuid" IN ($3)
-- PARAMETERS: ["<uuid>","\"{\\\"type\\\":\\\"Polygon\\\",\\\"coordinates\\\":[[[10.053713611343388,57.20829976160476],[10.052780202606208,57.20646356881912],[10.054282239654546,57.206306674693764],[10.055151275375371,57.20820098140615],[10.053713611343388,57.20829976160476]]]}\"","<uuid>"]
Does anyone know what I might be doing wrong?

Loopback 4/MongoDB - Foreign key not converted to ObjectID

I am trying to set up an hasMany relation using a Mongo database.
I have followed the guide to create an hasMany relation in the loopback 4 documentation (https://loopback.io/doc/en/lb4/HasMany-relation.html) and tryied to set differents properties but the foreign key custId is saved as a string and not as an ObjectID.
I also found a few other properties or options from others topics but people were using Loopback 3 and it doesn't seem to work with Loopback 4.
Did I miss something or is there any workaround ?
Here are my models :
#model()
export class Order extends Entity {
#property({
type: 'string',
id: true,
generated: true,
})
id: string;
#property({
type: 'array',
itemType: 'string',
required: true,
})
product: string[];
#property({
type: 'number',
required: true,
})
price: number;
#property({
type: 'string',
id: true,
generated: true,
})
custId: string;
constructor(data?: Partial<Order>) {
super(data);
}
}
#model()
export class Customer extends Entity {
#property({
type: 'string',
id: true,
generated: true,
})
id: string;
#property({
type: 'string',
required: true,
})
name: string;
#property({
type: 'string',
})
adress?: string;
#hasMany(() => Order, {keyTo: 'custId'})
orders?: Order[];
constructor(data?: Partial<Customer>) {
super(data);
}
}
This is currently a bug. The hasMany / belongsTo will end up saving the relation id as a string instead of an ObjectId. You can verify this by changing the id in the database directly to an ObjectId and then it will find it.
Reference: https://github.com/strongloop/loopback-next/issues/2085
It is also mentioned on the latest Monthly Milestone here, so hopefully it will be resolved soon: https://github.com/strongloop/loopback-next/issues/2313
Edit: I was able to get it working by adding strictObjectIDCoercion to the model, but that can break other things according to issue 2085 linked above.
#model({
settings: {
strictObjectIDCoercion: true,
}
})
For hasMany relationship you need to update order Model.
Update order.model with :
1.Import Customer Model
import {Customer} from './customer.model';
remove custId: string;
2.For reference customer Id Just update code with
#belongsTo(() => Customer)
custId: number;
Reference Example : here

Meteor - node simple schema validate data to match schema

I want to change my Rest-API validation to node simple schema for schema definition and collection2#core for schema validation.
I want to use the Person schema to validate the data provided by the users.
Schemas = {};
Schemas.Person = new SimpleSchema({
name: {
type: String,
label: "Person's Name",
unique: true,
max: 200
},
surname: {
type: String,
unique: true,
label: "person's surname"
},
};
validData = API.utility.validate(data, Schemas.Person });
API: {
utility: {
validate: function(data, schema) {
return "The SimpleSchema Validation";
}
}
};
This case is described in the simpl-schema documentation
With your schema definition you can just do:
Schemas.person.validate(data);
If right after that you want to look at the result or the errors:
Schemas.person.isValid();
Schemas.person.validationErrors();

ER_TOO_LONG_KEY in SailsJS 1.0 with sails-mysql

I got this error with sails when I try to sails lift:
info: ·• Auto-migrating... (drop)
error: A hook (`orm`) failed to load!
error:
error: Error: ER_TOO_LONG_KEY: Specified key was too long; max key length is 767 bytes
I just have one model for now: 
module.exports = {
datastore: 'default',
tableName: 'sci_user',
attributes: {
email: {
type: 'string',
required: true,
unique: true
},
password: {
type: 'string',
required: true
}
}
It's really simple and I got it from the documentation. I don't understand. It seems it's because of the unique: true.
This is due to a combination of factors, but the most pertinent one is that sails-mysql currently defaults to using the utf8mb4 character set for string attributes, to allow the use of emojis and other extended characters. We're working on a patch to make this configurable rather than the default, but in the meantime the quickest workaround is to declare the columnType for your attributes directly:
module.exports = {
datastore: 'default',
tableName: 'sci_user',
attributes: {
email: {
type: 'string',
required: true,
unique: true,
columnType: 'varchar'
},
password: {
type: 'string',
required: true,
columnType: 'varchar'
}
}

Fit Mapbox map to boundaries of dynamic markers

I try to create a map with mapbox, that features dynamic markers. I want the map to automatically fit to the markers, as described here: https://www.mapbox.com/mapbox.js/example/v1.0.0/fit-map-to-markers/. Unfortunately I can't get it working.
The code also contains the feature markers as links (https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-as-links/), which works great – but as JS- and Mapbox-Noob, I can't figure out how to combine both.
The code right now is this:
<div class='start-map'>
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'XXX', {zoomControl: false})
.setView([-20.1908, -67.5893], 3);
var geoJson = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-67.5893, -20.1908]
},
properties: {
title: 'Salar de Uyuni',
'marker-size': 'small',
'marker-color': '#fff',
url: 'http://localhost'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [170.2, -43.4764]
},
properties: {
title: 'Franz Josef Glacier',
'marker-size': 'small',
'marker-color': '#fff',
url: 'http://localhost'
}
}
]
};
map.featureLayer.setGeoJSON(geoJson);
map.featureLayer.on('click', function(e) {
e.layer.unbindPopup();
window.open(e.layer.feature.properties.url);
});
geoJson.on('ready', function() {
// featureLayer.getBounds() returns the corners of the furthest-out markers,
// and map.fitBounds() makes sure that the map contains these.
map.fitBounds(geoJson.getBounds());
});
</script>
</div>
Here's corrected code: https://gist.github.com/tmcw/10203442
Issues in this example:
geoJson is a simple JavaScript object, not a layer, so you can't call methods on it.
If you're adding custom data to a map, create a new L.mapbox.featureLayer rather than using map.featureLayer
If you're calling .setGeoJSON() you do not have to wait for the .on('ready' event.