我正在尝试优化长途远足径的Mapbox视图,例如Appalachian Trail或Pacific Crest Trail.这是一个例子,我手工定向,展示了西班牙的SendaPirenáica:
给出了感兴趣的区域,视口和音高.我需要找到正确的中心,方位和缩放.
这个map.fitBounds方法对我没有帮助,因为它假设pitch = 0且bearing = 0.
我做了一些戳,这似乎是最小的周围矩形问题的变化,但我仍然坚持一些额外的复杂性:
FWIW我也使用turf-js,这可以帮助我获得线的凸包.
我需要找到点的地理空间坐标,这是我的 GeoJSON 数据集中所有要素之间距离的平均值。在 turf.js 中,centroid 和 centerOfMass 都出现了。centerOfMass 的解释是它“采用任何 Feature 或 FeatureCollection 并使用此公式返回其质心:多边形质心。” 但是应用于我的功能的 centroid 和 centerOfMass 给出了不同的结果。它们之间有什么区别?那应该用什么?
所以我想在 javascript 中合并相邻的多边形,这就是我在代码中实际拥有的:
我想删除内部描边但保留边框描边。
所以我想从这里开始:
对此:
我想保留巴黎的洞 - 我可以定义哪些多边形必须分组,但我无法将它们与以下代码合并:
var map = L.map('map', {
center: [46.52863469527167, 2.43896484375],
zoom: 6,
maxZoom: 18,
minZoom: 7
});
$http.get("france.json").then(function (response) {
$scope.communeFr = response.data.features
$http.get(apiult).then(function (response) {
$scope.showCommune = response.data.Liste
$scope.communeFr.map(x => {
x.show = false
for (let i = 0; i < $scope.showCommune .length; i++) {
if (x.properties.insee == $scope.showCommune[i].insee) {
x.show = true
return
}
}
})
L.geoJson($scope.communeFr, {
filter: function (feature, latlng) {
return feature.show
}
}).addTo(map);
});
});
Run Code Online (Sandbox Code Playgroud)
更新 - …
我想根据最近的草皮更改地图点击时的图标大小。我如何做到这一点?nearestBuilding.properties['icon-size'] = 0.2;不起作用。
var retail = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
title: 'TEST',
description: 'TEST'
},
geometry: {
type: 'Point',
coordinates: [121.051779, 14.550224]
}
},
{
type: 'Feature',
properties: {
title: 'TEST',
description: 'TEST'
},
geometry: {
type: 'Point',
coordinates: [121.04568958282472, 14.552170837008527]
}
}
]
};
map.on('load', function() {
map.loadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Wiki_Loves_Earth_map_marker.svg/600px-Wiki_Loves_Earth_map_marker.svg.png', function(error, image) {
if (error) throw error;
map.addImage('marker', image);
map.addLayer({
id: 'retail',
type: 'symbol',
source: {
type: 'geojson',
data: retail
},
layout: { …Run Code Online (Sandbox Code Playgroud) 当我在地图框上使用草皮时,特别是以下行,它会产生错误var nearestBuilding = turf.nearest(currentLocation, geoJson);。我使用mapbox-gl和草皮来获取最近的建筑物。当我手动输入数据而无需object.push()但我需要数据库中的信息时,它会起作用。
var object = [];
for (var x = 0; x < json.length; x++) {
var
image = json[x].image == '' ? '' : "<div style='text-align:center;'><img src='" + json[x].image + "' width='100' height='75' /></div>",
number = json[x].contact == '' ? '' : "<br/>" + json[x].contact,
details = json[x].details == '' ? '' : '<br/>' + '<a href="{{ url('restaurants-and - cafe') }}/' + json[x].details + '">More Details</a>';
object.push({
type: 'Feature',
properties: {
title: …Run Code Online (Sandbox Code Playgroud) 如何将坐标的 JSON 数据提供给 turf.polygon?
示例: turf.polygon();
var polygon = turf.polygon([[
[-2.275543, 53.464547],
[-2.275543, 53.489271],
[-2.215118, 53.489271],
[-2.215118, 53.464547],
[-2.275543, 53.464547]
]], { name: 'poly1', population: 400});
Run Code Online (Sandbox Code Playgroud)
示例: JSON 形式
var json =
{
"type": "geojson",
"data":
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[
[1.275543, 54.464547], // I want to feed these coordinates
[1.275543, 54.489271],
[1.215118, 54.489271],
[1.215118, 54.464547],
[1.275543, 54.464547]
]]
}
}]
}
}
Run Code Online (Sandbox Code Playgroud)
我的伪代码:这不起作用并返回错误消息"LinearRing of a Polygon must have 4 …
我是一个 angular 5(和 turfjs)菜鸟,试图使用 turfjs()。
我有一个非常简单的 angular 5 项目(用 angular-cli 构建)。
要添加草皮,我跑了:
npm install @turf/along --save
Run Code Online (Sandbox Code Playgroud)
我在我的节点模块目录中看到 @turf/along。我尝试添加到我的 js 文件中:
declare var along: any;
Run Code Online (Sandbox Code Playgroud)
但这没有用。我也尝试添加
"../node_modules/@turf/along/index.js"
Run Code Online (Sandbox Code Playgroud)
到我的 angular-cli.json 文件,但没有运气。
导入此方法以便我可以使用它的正确方法是什么?
我在网上看到过这个例子,它进行数据驱动的建筑挤压,但根本不提供代码。
我非常想实现同样的目标。我有一个 geojson 文件,其中包含某种属性,我想将其映射到建筑物的高度。你知道这怎么可能吗?
我已经考虑了推荐的替代方案:对已经根据我的数据生成的圆进行 3D 挤压。未提供此博客文章中的代码,因此我起诉了此帖子中的代码。
代码如下:
<html>
<head>
<meta charset='utf-8' />
<title>Display buildings in 3D</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.48.0/mapbox-gl.css' rel='stylesheet' />
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoicXVlMzIxNiIsImEiOiJjaWhxZmMxMDUwMDBzdXhsdWh0ZDkyMzVqIn0.sz3lHuX9erctIPE2ya6eCw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [8.538961, 47.372476],
zoom: 16,
pitch: 40, …Run Code Online (Sandbox Code Playgroud) 我有两个多边形,它们的交叉点不可见且不可移动。我试图通过从第一个中删除第二个区域来找到它们之间的差异,然后再次找到交叉点 - 结果交叉点仍然存在并且具有公共区域。为什么会发生这种情况?如何去除两个多边形之间的交点并使它们的边界接触?
const turf = require("@turf/turf");
const poly1 = [
[
[37.367249, 55.615589],
[37.372462, 55.612478],
[37.372463, 55.61248],
[37.453365, 55.564205],
[37.45336, 55.564206],
[37.459431, 55.560583],
[37.558005, 55.682037],
[37.367249, 55.615589]
]
];
const poly2 = [
[
[37.336522, 55.603857],
[37.360725, 55.57621],
[37.408614, 55.591334],
[37.371557, 55.613064],
[37.336522, 55.603857]
]
];
const difference = turf.difference(turf.polygon(poly1), turf.polygon(poly2)); // removed poly2 from poly1, difference now is Feature<Polygon>
const intersection = turf.intersect(turf.polygon(difference.geometry.coordinates), turf.polygon(poly2));
if (intersection) { //intersection is geometry collection with polygons
// why???
}
Run Code Online (Sandbox Code Playgroud) turfjs ×10
javascript ×6
mapbox-gl-js ×4
geospatial ×2
mapbox ×2
polygon ×2
angular ×1
angular-cli ×1
geojson ×1
geometry ×1
json ×1
leaflet ×1
maps ×1
node.js ×1