地理对象从 geojson 文件加载到地图上,我需要两个选项来使用多边形和标签打开地图,并且仅使用多边形,无法更改 geojson 文件,我需要制作没有标签的第二个版本的脚本。
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map('map', {
center: [30.448166334957177, 59.9220776628873],
zoom: 15,
controls: ['searchControl']
}),
searchControl = myMap.controls.get('searchControl');
searchControl.options.set({noPlacemark: true, placeholderContent: 'Введите адрес'});
function onZonesLoad(json) {
// Добавляем зоны на карту.
var deliveryZones = ymaps.geoQuery(json).addToMap(myMap);
// Задаём цвет и контент балунов полигонов.
deliveryZones.each(function (obj) {
obj.options.set({
fillColor: obj.properties.get('fill'),
fillOpacity: obj.properties.get('fill-opacity'),
strokeColor: obj.properties.get('stroke'),
strokeWidth: obj.properties.get('stroke-width'),
strokeOpacity: obj.properties.get('stroke-opacity')
});
obj.properties.set('balloonContent', obj.properties.get('description'));
});
}
$.ajax({
url: 'lib/cart.geojson',
dataType: 'json',
success: onZonesLoad
});
}
购物车.geojson
{
"type": "FeatureCollection",
"metadata": {
"name": "geoObjects",
"creator": "Yandex Map Constructor"
},
"features": [
{
"type": "Feature",
"id": 0,
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
30.442541174676739,
59.92002251063883
],
[
30.445974402215794,
59.91920375455527
],
[
30.446210436609108,
59.91941921864753
],
[
30.44902139165672,
59.920097921364028
],
[
30.44887118795188,
59.92039956254539
],
[
30.449579291131824,
59.92114288084794
],
[
30.445824198510978,
59.92209085678325
],
[
30.44610314824848,
59.92245172682361
],
[
30.44562035062585,
59.922562141511509
],
[
30.445228748109668,
59.92230899511611
],
[
30.443764261987544,
59.92293108545654
],
[
30.441897444513164,
59.92162764466863
],
[
30.442541174676739,
59.92002251063883
]
]
]
},
"properties": {
"description": "1:1:1:1:1:1:0:0:0:0:0:0:0:0:0",
"fill": "#1bad03",
"fill-opacity": 0.1,
"stroke": "#1bad03",
"stroke-width": "2",
"stroke-opacity": 0.9
}
},
{
"type": "Feature",
"id": 5,
"geometry": {
"type": "Point",
"coordinates": [
30.444435038298836,
59.92078156674039
]
},
"properties": {
"description": "1:1:1:1:1:1:0:0:0:0:0:0:0:0:0",
"iconCaption": "Адрес",
"iconContent": "5"
},
"options": {
"preset": "islands#darkGreenCircleIcon"
}
}
]
}