I am using leaflet draw to create polygons.
My requirement is when a user draws a polygon ,it should not intersect/overlap with existing polygons.
I have used point in polygon leaflet to detect if point falls within the polygon and it is working,
but the problem is i am not able to detect if a line crosses another polygons.In this case points lie outside the existing polygons but overlapping exists.
Below attached image can give a better picture!
You can also probably use Turf.js. Turf is a new js GIS engine developed by the guys at Mapbox.
Here are few examples that may do the job:
Turf Intersects
Turf Overlaps
In leaflet.draw, you can pass options to individual draw handlers. One of them allowIntersection is a boolean type that "Determines if line segments can cross."
Your options would look something like this (excerpted from the leaflet.draw example config):
var options = {
position: 'topright',
draw: {
polygon: {
allowIntersection: false, // Restricts shapes to simple polygons
drawError: {
color: '#e1e100', // Color the shape will turn when intersects
message: '<strong>Oh snap!<strong> you can\'t draw that!' // Message that will show when intersect
},
shapeOptions: {
color: '#bada55'
}
},
},
edit: {
featureGroup: editableLayers, //REQUIRED!!
remove: false
}
};
var drawControl = new L.Control.Draw(options);
map.addControl(drawControl);
You can probably also use Terraformer Core, which is an open-source project done by the folks at ESRI. You would probably do something like this:
var polygon = new Terraformer.Primitive({
"type": "Polygon",
"coordinates": [ [ [ -101.46972656250001, 34.125447565116126 ],
[ -100.85449218750001, 33.760882000869195 ],
[ -101.09619140625, 33.19273094190692 ],
[ -102.12890625000001, 33.137551192346145],
[ -102.19482421875, 33.63291573870479 ],
[ -101.46972656250001, 34.125447565116126 ] ] ] });
var intersects = polygon.intersects({
"type": "Polygon",
"coordinates": [ [ [ -103.32539, 30.58608 ], [ -102.32083, 29.87894 ], [ -103.32539, 30.58608 ] ] ] });
// intersects is a bool.
Related
I've started building a form in react-jsonschema-form and i'm having a lot of difficulty changing it visually.
The form is an array and it has a button to add and remove a set of input boxes.
I've build it as a component in a test project which has no css applied to it so far.
The form will render as a tiny box where there is no room for the buttons (they are cut of as shown below in images).
a single element
a second element
How its supposed to look on react-jsonschema-form playground
A key difference between my array and the sample array is that i'm having two text input elements per array element. I dont know if this could cause it.
I do need to have two input values as its a group of data that is related, and both is required.
This is my code:
//json schema
const schema = {
type: "object",
properties: {
listOfNumbers: {
title: "opret ledig nummerserie",
type: "array",
required: ["nr_fra", "nr_til"],
items: {
properties: {
nr_fra: {
type: "string",
pattern: "^\\d*$",
minLength: 8,
maxLength: 8,
},
nr_til: {
type: "string",
pattern: "^\\d*$",
minLength: 8,
maxLength: 8,
},
},
},
},
},
};
//uiSchema
const uiSchema = {
listOfNumbers: {
"ui:options": {
orderable: false,
},
items: {
//nr_fra: { "ui:options": { label: false } },
//nr_til: { "ui:options": { label: false } },
},
},
}
I'm applying no css to the below form.
// Form
<Form
schema={schema}
uiSchema={uiSchema}
formData={this.state.formData}
onSubmit={(formOutput) => this.handleSubmit(formOutput)}
transformErrors={transformErrors}
/>
I've spent a day and a half on trying to strongarm this, but i could really use some help on how to proceed.
It seems it was css inputs that was needed to solve this.
The below will expand the elements to their proper size/form.
Posting this here for posterity, as this is not accurately documented.
<div className="col-md-offset-3 col-md-6">
<Form schema={schema}
uiSchema={uiSchema}>
</Form>
</div>
I'm trying to use a ObHighcharts bundle with symfony2.
Basically, it generates the following code:
$(function () {
var chart = new Highcharts.Chart({
chart: {"renderTo":"dailyChart","type":"spline"},
series: {"name":"My spline","data":
[
[1369519200,"2055.5"],
[1370469600,"1986.3"],
[1369087200,"1804.0"],
[1368655200,"1783.3"],
[1366840800,"1734.3"],
[1369000800,"1693.2"],
[1368309600,"1515.4"],
*lots of other similar data*
]
},
title: {"text":"My Chart"},
xAxis: {"title":{"type":"datetime","title":"Date"}},
yAxis: {"title":{"title":"Sugar, mg","min":0}}
});
});
But when I try rendering it, there's just a title, an export button and a blank screen. Console shows no signs of errors. What can be wrong here? Appreciate any input.
Because your data element is a string:
[
[1369519200,"2055.5"],
[1370469600,"1986.3"],
[1369087200,"1804.0"],
[1368655200,"1783.3"],
[1366840800,"1734.3"],
[1369000800,"1693.2"],
[1368309600,"1515.4"],
*lots of other similar data*
]
It should be something like [1369519200,2055.5].
You also need to enclose the series element in brackets:
series: [{"name":"My spline","data":
[
[1369519200,"2055.5"],
[1370469600,"1986.3"],
[1369087200,"1804.0"],
[1368655200,"1783.3"],
[1366840800,"1734.3"],
[1369000800,"1693.2"],
[1368309600,"1515.4"],
]}
]
Also, note that your time elements are not in ascending order. For a proper datetime axis you need to go in ascending time.
I'm trying to create pyramid chart similar to this http://www.highcharts.com/demo/pyramid in rCharts, however it gives me an error even though the output looks fine
h1 <- Highcharts$new()
h1$chart(type = "pyramid")
h1$series(name='Unique users', data=list(
list('Website visits', 15654),
list('Downloads', 4064),
list('Requested price list', 1987),
list('Invoice sent', 976),
list('Finalized', 84)
))
Here is an output
(function ($) {
$(function () {
var chart = new Highcharts.Chart({
"dom": "chartee4502dd16c",
"width": 800,
"height": 400,
"credits": {
"href": null,
"text": null
},
"exporting": {
"enabled": false
},
"title": {
"text": null
},
"yAxis": {
"title": {
"text": null
}
},
"chart": {
"type": "pyramid",
"renderTo": "chartee4502dd16c"
},
"series": [{
"name": "Unique users",
"data": [
[
"Website visits",
15654],
[
"Downloads",
4064],
[
"Requested price list",
1987],
[
"Invoice sent",
976],
[
"Finalized",
84]
]
}],
"id": "chartee4502dd16c"
});
});
})(jQuery);
Am I doing a mistake somewhere or is pyramid chart just not supported by rCharts? Thanks.
#Ondkloss is right on the money here. All that you need to do is to add the funnel script to your page. There is a quick and easy way to do that in rCharts without hacking at config.yml. You can use the addAssets method to inject a javascript asset in the head.
library(rCharts)
h1 <- Highcharts$new()
h1$addAssets(jshead = "http://code.highcharts.com/modules/funnel.js")
Now run the same code you ran previously and you should get a nice pyramid chart.
h1$chart(type = "pyramid")
h1$series(name='Unique users', data=list(
list('Website visits', 15654),
list('Downloads', 4064),
list('Requested price list', 1987),
list('Invoice sent', 976),
list('Finalized', 84)
))
h1
Here is the final version of the chart. You can click here fpr a version that is editable online.
From the Highcharts API (and as included in your demonstration) a Pyramid chart is "a reversed funnel chart without a neck", and a Funnel chart "requires that the modules/funnel.js file is loaded".
Judging from the config.yml for the Highcharts library in rCharts that specific module is not included:
highcharts:
jshead:
- js/jquery-1.9.1.min.js
- js/highcharts.js
- js/highcharts-more.js
- js/exporting.js
cdn:
jshead:
- "http://code.jquery.com/jquery-1.9.1.min.js"
- "http://code.highcharts.com/highcharts.js"
- "http://code.highcharts.com/highcharts-more.js"
- "http://code.highcharts.com/modules/exporting.js"
There's not much between you and a modified rCharts to make it happen though, if you so desire.
I am trying to build an array of data returned from a third party API, and display it using the Highcharts map module.
I've done so with the charts module, using line and pie charts both with not much difficulty. Now that I've moved onto maps, I seem to be running into a bit of difficulty. It was quite clear from the examples provided how the data should be structured to be properly read by Highcharts.
When it comes to the maps module, the data structure is not clear at all. How would I structure my data to pass into my Highcharts map???
[ 'US' , 'United States' , 32 ] , [ 'CA' , 'Canada' , 100 ]
If I use the provided :
jQuery.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=world-population-density.json&callback=?', function (data) {
console.log(data);
// Initiate the chart
jQuery('#geo_map').highcharts('Map', {
title : {
text : 'Campaign Link Clicks Around The World'
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
colorAxis: {
min: 1,
max: 1000,
type: 'logarithmic'
},
series : [{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'code'],
name: 'Population density',
states: {
hover: {
color: '#BADA55'
}
},
tooltip: {
valueSuffix: '/kmĀ²'
},
}],
credits: {
enabled: false
},
});
});
});
It works. But I can't seem to figure out how to pass in my data. I thought it was as simple as
[ 'Abbreviation' , 'Name' , Value ] , [ 'Abbreviation' , 'Name' , Value ]
but clearly not. The documentation isn't very clear on data structure.
Thanks.
When you use the Ext.dataview.List in Sencha, it automatically inserts a nice loading spinner while the data is loading. That's all fine and dandy, but I'd like to know how to use a custom loader .gif.
I've looked around and think I need to change the loadmask but not positive cause I'm new to this. See this link.
Below is the code for one of my Lists. I'm hoping to be able to add the code suggested to one place so that all lists are affected and have the new spinner.
{
xtype: 'list',
height: '',
id: 'categoryList',
itemId: '',
width: '100%',
scrollable: false,
emptyText: '<div class="pdtsListHtml" style="margin-top:30%">Product List Empty</div>',
itemTpl: [
'<div ><div class="pdtsListHtml" style="display:inline;">{navigationElementItemName} ({navigationElementItemRecordCounts})</div><div style="display:inline;float:right;margin-right:5px;"><img src="resources/image/arrow.png" width="11" height="11"></div></div>'
],
store: 'productListStore',
allowDeselect: true,
onItemDisclosure: false
}
Here's a fiddle that shows you an example list with a loading mask that uses a gif.
Basically you should define your own Ext.LoadMask subclass and use it on the list:
Ext.define("Test.MyLoadMask", {
extend: "Ext.LoadMask",
alias: "widget.myloadmask",
getTemplate: function() {
var prefix = Ext.baseCSSPrefix;
return [
{
reference: 'innerElement',
cls: prefix + 'mask-inner',
children: [
{
reference: 'indicatorElement',
cls: prefix + 'loading-spinner-outer',
children: [
{ tag: 'img', src: "http://example.com/my-spinner.gif" }
]
},
{
reference: 'messageElement'
}
]
}
];
}
});
Then you should define an applyMasked on your lists that modifies the xtype and sets it to myloadmask instead of loadmask.