I write a vba-macro with a map display.

YMaps.jQuery(function () { var map = new YMaps.Map(YMaps.jQuery("#YMapsID")[0]); map.setCenter(new YMaps.GeoPoint(37.617671,55.752283), 6); YMaps.Regions.load("ru", function (state, response) { if (state == YMaps.State.SUCCESS) { var regionVba = response.filter(function (obj) { return obj.name == "Московская область"; })[0]; regionVba.setStyle({ polygonStyle : { fillColor : "b00c0c55", strokeColor : "b00c0c" }, hasHint : true }); map.addOverlay(regionVba); } else { alert("Error: " + response.error.message) } }); }) 

What needs to be changed in the code so that the area is always highlighted, and not just during hover?

Examples taken from here.

  • And what have the VBA? - tutankhamun
  • As far as I can see, you want to use version 1 of Yandex.Map. I recommend to immediately deal with version 2.1. There, everything is more logically arranged and works faster on modern browsers. - tutankhamun
  • @tutankhamun vba generates the html code and opens the map in the MS WebBrowser component on the excel sheet, and the WebBrowser in Excel is IE. In 2.1 did not find the highlight areas. I have not studied JS, so I experiment with examples) - Denis
  • I recently answered a similar question. If there is something incomprehensible, reformulate your current question - tutankhamun
  • By the way, in the code given in the answer, you need to connect the jQuery library. If the current question is not relevant, delete it. - tutankhamun

1 answer 1

If you really want to stay with the old code, you can do this:

 ... if (state == YMaps.State.SUCCESS) { var regionVba = response.filter(function (obj) { return obj.name == "Московская область"; })[0]; // Отличия начинаются тут // Берем фигуры регионов var shapes = regionVba.metaDataProperty.encodedShapes; var polygon; // Перебираем фигуры for (var ix = shapes.length; ix--; ) { // Создаем полигон polygon = YMaps.Polygon.fromEncodedPoints( shapes[ix].coords, shapes[ix].levels ); // Указываем цвета polygon.setStyle({ polygonStyle: { fillColor: "b00c0c55", strokeColor: "b00c0c" } }); // Помещаем полученный полигон на карту map.addOverlay(polygon); } } else { ... 

The minus of this solution is compared with that in a very low accuracy of drawing regions, but at the same time drawing takes place rather quickly.

See also Region.encodedShapes , Polygon.fromEncodedPoints ()

  • Thank you very much - what you need! and on the 1st version I want to stay, because there is an example with a small amount of code and everything in the html page. In 2.1 I opened a sandbox in Yandex, I looked, the code is a bit too much + the js file is separate from the html, it makes it difficult for me to work in vba. - Denis
  • I just don’t need accuracy and the rendering speed is important) - Denis