Why aren't some areas on the card index?



  • Continuing the question https://ru.stackoverflow.com/questions/462506/%D0%9A%D0%B0%D0%BA-%D0%BD%D0%B0-%D1%8F%D0%BD%D0%B4%D0%B5%D0%BA%D1%81-%D0%BA%D0%B0%D1%80%D1%82%D0%B5-%D0%BF%D0%BE%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D1%8C-%D1%80%D0%B0%D0%B9%D0%BE%D0%BD%D1%8B-%D0%B3%D0%BE%D1%80%D0%BE%D0%B4%D0%B0/554019#554019 ♪ Not all regions are selected in this way. For example, the region is not mapped:

    <script>
            ymaps.ready(function() {
    // 0. Создаем карту, например так:
        var map,
            regionName = "Bryansk Oblast",
            center = [52.8873315,33.415853],
            zoom = 5;
    
    map = new ymaps.Map('reviewsmap', {
        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);
    p.options.set('fillColor', 'rgba(255, 0, 0, 0.4)');
    p.options.set('strokeColor', '#F8DA19');
    // 3. Добавляем полигон на карту
    map.geoObjects.add(p);
    }
    });
    }, function (err) {
    console.log(err);
    });
    });
    </script>

    Such examples can be cited. Which makes it impossible.



  • I took an example of the area. Volgograd Oblast and Bryansk Oblast and looked at the data in response http://nominatim.openstreetmap.org/search

    You're giving a map of a set of pointsrested from. geojson.coordinates

    First field geojson.type == "Polygon"inside geojson.coordinates One mass. The region was right on the map.

    Bryansk Oblast. geojson.type == "MultiPolygon"inside geojson.coordinates Two sets. The region didn't paint on the map.

    I don't know api openstreetmap, but here we see that the search can return both to the coordinates of one region of the drawing and to several. And the map should be given only one of them (or all but in turn).

    So I'm offering you the right to check. type and if MultiPolygon - Describe only the first set of points:

    var coordinates = place.geojson.type == "MultiPolygon" ? place.geojson.coordinates[0] : place.geojson.coordinates;
    var p = new ymaps.Polygon(coordinates);
    

    Once again, I don't know Api and I don't know what the second region is in the case of the Bryansky. I painted them both on the map, and I didn't see any difference, so I'm just suggesting drawing one. Anyway, if you study the docks api and understand that all regions need to be painted, it's hard to do. Now you know where to dig.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2