D
D
dmitpap2019-08-09 21:01:31
2GIS
dmitpap, 2019-08-09 21:01:31

API 2GIS maps - how to calculate the occurrence of marks in a polygon?

You need the ability to calculate the occurrence of tags in a polygon (a command or function to determine which are included and which are not)
, for example, as Yandex has here: How to check the occurrence of a tag in polygons?

D
dmitpap, 2019-08-20
@dmitpap

As Yandex fails, the API does not provide for such a command. Solution:
function pointInPoly(vs,point){
var x = point[0], y = point[1];
var inside = false;
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
var xi = vs[i][0], yi = vs[i][1];
var xj = vs[j][0], yj = vs[j][1];
var intersect = ((yi > y) != (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};
DG.then(function() {
var map;
map = DG.map('map', {
center: [55.752283, 37.625224],
zoom: 10
});
= points [
[56.00161461335189,36.947861328124986],
[55.97236171651059,38.22776855468748],
[55.49816766327379,38.115158691406236],
[55.42794458112196,37.39280761718749],
[56.00161461335189,36.947861328124986]
];
// Adding polygons to the group and map
varp=false;
group.eachLayer(function(layer){
var g=layer.toGeoJSON().geometry;
if(g.type=='Polygon'){
p=g.coordinates;
}else if(p){
console.log(pointInPoly(p[0],g.coordinates));
}
});
});

Didn't find what you were looking for?