gpt4 book ai didi

dictionary - Mapbox fitBounds,函数边界映射但不渲染图 block

转载 作者:行者123 更新时间:2023-12-04 05:38:36 25 4
gpt4 key购买 nike

在这里,我的 javascript 代码在 map 中呈现标记,然后是该 map 的 fitBounds。

map 边界根据geojson得到拟合,但问题是当有任何标记时
在 map 上,我尝试适应绑定(bind), map 图 block 图像未得到渲染。

在 map 中它只显示标记,没有平铺图像。

var latLongCollection = [];
var map;
$(document).ready(function() {
map();
});


function map() {
map = L.mapbox.map('DivId', 'ProjectId');
GetData();
}

function GetData() {
$.ajax({
type: "GET",
url: someUrl,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: AjaxSuccess,
error: function () {
}
});
}

function AjaxSuccess(data) {
if (data == null || data.length == 0) {
return;
}

var geoJson = {
"type": "FeatureCollection",
"features": []
};

$.each(data, function (index, value) {

var latitude = parseFloat(value.Latitude),
longitude = parseFloat(value.Longitude);

if (latitude && longitude) {
var dataJson = {
type: "Feature",
geometry: { type: "Point", coordinates: [longitude, latitude] },
properties: {
someProp: value.SomeProperty,
}
};

geoJson.features.push(vehicleJson);
}
});

var markerLayer = L.mapbox.featureLayer(geoJson).addTo(map);

markerLayer.eachLayer(function (marker) {
var feature = marker.feature;
var featureProperty = feature.properties;

if (featureProperty.someProp) {
marker.setIcon(L.divIcon({
html: 'htmlstring',
iconSize: [35, 75]
}));
}
else {
marker.setIcon(L.divIcon({
html: 'anotherhtmlstring',
iconSize: [35, 75]
}));
}

latLongCollection.push(marker._latlng);
});

markerLayer.on('click', function (e) {
map.panTo(e.layer.getLatLng());
});

if (latLongCollection.length > 0) {
map.fitBounds(latLongCollection);
}
}

最佳答案

如果有人仍在为此苦苦挣扎,这似乎是传单中的一个错误:https://github.com/Leaflet/Leaflet/issues/2021

它已在最新版本中修复,但如果您无法更新,您可以通过设置超时来解决竞争条件:

setTimeout(function () {
map.fitBounds(latLongCollection);
}, 0);

关于dictionary - Mapbox fitBounds,函数边界映射但不渲染图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23260369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com