There is a task to show the administrative districts of the city on the Yandex maps. Moreover, each district should have its own color and transparency. For example, one district of the city is displayed here: on Yandex Map

You need to show all (or several) areas (s) of the city and be able to set color and transparency through the API. Tell me, how can this be done?

UPD1. There is an idea to make areas in the form of polygons. Then you can edit them as you please. But we need the coordinates of the districts. Yandex map from where it takes this data. Here's how to get them?

UPD2. Received an official response from those supporting Yandex Maps. "It is impossible to do this with the means of the IPA Yandex Maps." So we use OSM.

    1 answer 1

    The general action plan is:

    ymaps.ready(function() { // 0. Создаем карту, например так: var map, regionName = "Краснодар, Западный округ", center = [38.943216, 45.033266], zoom = 11; map = new ymaps.Map('yamap', { center: center, zoom: zoom, controls: [] }); // 1. Запрашиваем через геокодер район (у Яндекса этой возможности пока нет, придется пользоваться OSM) var url = "http://nominatim.openstreetmap.org/search"; $.getJSON(url, {q: regionName, format: "json", polygon_geojson: 1}) .then(function (data) { $.each(data, function(ix, place) { if ("relation" == place.osm_type) { // 2. Создаем полигон с нужными координатами var p = new ymaps.Polygon(place.geojson.coordinates); // 3. Добавляем полигон на карту map.geoObjects.add(p); } }); }, function (err) { console.log(err); }); }); 

    Step 1, as an example, is done using jQuery.

    Stage 2 hides a little problem. OSM returns the coordinates in order (longitude, latitude), Yandex works by default with the order (latitude, longitude). To change this you need to specify the order when connecting the API

     <script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU&coordorder=longlat" type="text/javascript"></script> 

    Also in step 2, you can add a "taste" background color, stroke, transparency, and more, see Polygon

    • Where have you been before Man! So much manual work was done to get these coordinates. Download data from beryllium.gis-lab.info/project/osmshp shape files. Opening them in the GIS program. Finding a way to convert data to GeoJSON. Finally, the conversion. I need to tear out the necessary areas from this huge file. Manually pull and add to the area. But it turns out you need to send one request for API! tutankhamun you helped me a lot. Since I need to later add areas in other cities. - Alma Z
    • one
      @AlmaZ I just didn’t immediately think that you could take regions from OSM (and Yandex doesn’t have them). It happens like this :) As they say, to give an answer you need to know half the answer. You gave me this half in another question - tutankhamun