﻿
function ShowMap() {


    var map = new YMaps.Map(document.getElementById("YMapsID"));
    map.setCenter(new YMaps.GeoPoint(34.30, 45.20), 8);
    map.addControl(new YMaps.TypeControl());
    map.addControl(new YMaps.ToolBar());
    map.addControl(new YMaps.Zoom());
    map.addControl(new YMaps.MiniMap());
    map.addControl(new YMaps.ScaleLine());
    map.enableScrollZoom();

    var style = new YMaps.Style("default#greenPoint");
    style.polygonStyle = new YMaps.PolygonStyle();
    style.polygonStyle.fill = 1;
    style.polygonStyle.outline = 1;
    style.polygonStyle.strokeWidth = 2;
    style.polygonStyle.strokeColor = "ffff0033";
    style.polygonStyle.fillColor = "ff000055";
    YMaps.Styles.add("polygon#Example", style);
    var polygon = new YMaps.Polygon([new YMaps.GeoPoint(33.102388, 45.70893),
                                              new YMaps.GeoPoint(33.179284, 45.804102),
                                              new YMaps.GeoPoint(33.613251, 45.890473),
                                              new YMaps.GeoPoint(33.745079, 45.92307),
                                              new YMaps.GeoPoint(33.898897, 45.929778),
                                              new YMaps.GeoPoint(34.109013, 46.065705),
                                              new YMaps.GeoPoint(34.346591, 46.035107),
                                              new YMaps.GeoPoint(34.254585, 45.884739),
                                              new YMaps.GeoPoint(34.122749, 45.787789),
                                              new YMaps.GeoPoint(33.822002, 45.70319),
                                              new YMaps.GeoPoint(33.67369, 45.611703),
                                              new YMaps.GeoPoint(33.532241, 45.537443),
                                              new YMaps.GeoPoint(33.296038, 45.505584),
                                              new YMaps.GeoPoint(33.228781, 45.605922),
                                              new YMaps.GeoPoint(33.102388, 45.70893)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });

    polygon.name = "Северо-Западный Крым";
    polygon.description = "<a href=\"Region.aspx?RegionID=1\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "FF03DE55";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(33.061793, 45.702548),
                                              new YMaps.GeoPoint(33.103098, 45.712618),
                                              new YMaps.GeoPoint(33.136057, 45.661607),
                                              new YMaps.GeoPoint(33.204724, 45.657758),
                                              new YMaps.GeoPoint(33.236309, 45.558473),
                                              new YMaps.GeoPoint(33.321451, 45.551721),
                                              new YMaps.GeoPoint(33.335178, 45.466749),
                                              new YMaps.GeoPoint(33.265145, 45.46965),
                                              new YMaps.GeoPoint(33.256907, 45.473512),
                                              new YMaps.GeoPoint(33.100349, 45.384554),
                                              new YMaps.GeoPoint(33.050906, 45.367137),
                                              new YMaps.GeoPoint(33.015207, 45.36423),
                                              new YMaps.GeoPoint(32.972663, 45.351646),
                                              new YMaps.GeoPoint(32.838068, 45.370037),
                                              new YMaps.GeoPoint(32.755674, 45.366168),
                                              new YMaps.GeoPoint(32.656779, 45.313871),
                                              new YMaps.GeoPoint(32.496115, 45.346801),
                                              new YMaps.GeoPoint(32.485147, 45.404871),
                                              new YMaps.GeoPoint(32.563426, 45.46965),
                                              new YMaps.GeoPoint(32.698003, 45.520837),
                                              new YMaps.GeoPoint(32.798695, 45.561585),
                                              new YMaps.GeoPoint(32.819293, 45.592446),
                                              new YMaps.GeoPoint(33.102191, 45.710906),
                                              new YMaps.GeoPoint(33.103098, 45.712618)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Тарханкут";
    polygon.description = "<a href=\"Region.aspx?RegionID=2\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "8503FF55";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(33.265145, 45.46965),
                                              new YMaps.GeoPoint(33.256907, 45.473512),
                                              new YMaps.GeoPoint(33.100349, 45.384554),
                                              new YMaps.GeoPoint(33.050906, 45.367137),
                                              new YMaps.GeoPoint(33.015207, 45.36423),
                                              new YMaps.GeoPoint(32.972663, 45.351646),
                                              new YMaps.GeoPoint(33.017084, 45.303405),
                                              new YMaps.GeoPoint(33.267013, 45.145212),
                                              new YMaps.GeoPoint(33.47712, 45.155904),
                                              new YMaps.GeoPoint(33.585619, 45.047947),
                                              new YMaps.GeoPoint(33.662524, 45.056709),
                                              new YMaps.GeoPoint(33.904215, 45.388612),
                                              new YMaps.GeoPoint(33.814959, 45.441807),
                                              new YMaps.GeoPoint(33.265145, 45.46965)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Западный Крым";
    polygon.description = "<a href=\"Region.aspx?RegionID=3\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "03FFF055";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(33.585134, 45.049214),
                                              new YMaps.GeoPoint(33.6387, 45.0424),
                                              new YMaps.GeoPoint(33.688835, 44.969821),
                                              new YMaps.GeoPoint(33.771903, 44.905448),
                                              new YMaps.GeoPoint(33.726583, 44.854679),
                                              new YMaps.GeoPoint(33.659299, 44.798972),
                                              new YMaps.GeoPoint(33.68402, 44.687396),
                                              new YMaps.GeoPoint(33.726592, 44.464647),
                                              new YMaps.GeoPoint(33.681272, 44.41643),
                                              new YMaps.GeoPoint(33.379141, 44.585483),
                                              new YMaps.GeoPoint(33.538439, 44.645316),
                                              new YMaps.GeoPoint(33.531567, 44.838127),
                                              new YMaps.GeoPoint(33.591988, 44.845944),
                                              new YMaps.GeoPoint(33.598815, 44.972792),
                                              new YMaps.GeoPoint(33.585134, 45.049214)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Севастополь-Николаевка";
    polygon.description = "<a href=\"Region.aspx?RegionID=4\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "03FF4A55";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(34.073988, 44.560075),
                                              new YMaps.GeoPoint(34.395342, 44.832381),
                                              new YMaps.GeoPoint(34.686477, 45.028954),
                                              new YMaps.GeoPoint(34.779076, 44.818221),
                                              new YMaps.GeoPoint(34.671952, 44.78742),
                                              new YMaps.GeoPoint(34.456347, 44.707168),
                                              new YMaps.GeoPoint(34.346483, 44.549277),
                                              new YMaps.GeoPoint(34.250336, 44.506055),
                                              new YMaps.GeoPoint(34.128112, 44.428366),
                                              new YMaps.GeoPoint(33.968768, 44.388989),
                                              new YMaps.GeoPoint(33.864357, 44.403758),
                                              new YMaps.GeoPoint(33.739348, 44.386032),
                                              new YMaps.GeoPoint(33.710485, 44.418522),
                                              new YMaps.GeoPoint(34.073988, 44.560075)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Южный Берег Крыма";
    polygon.description = "<a href=\"Region.aspx?RegionID=5\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "009CFF55";
    polygon = new YMaps.Polygon([
                                              new YMaps.GeoPoint(34.779076, 44.818221),
                                              new YMaps.GeoPoint(34.686477, 45.028954),
                                              new YMaps.GeoPoint(34.961748, 45.08578),

                                              new YMaps.GeoPoint(35.357258, 45.2257),
                                              
                                              new YMaps.GeoPoint(35.428683, 45.317819),
                                              new YMaps.GeoPoint(35.85303, 45.472634),
                                              new YMaps.GeoPoint(36.348289, 45.487661),
                                              new YMaps.GeoPoint(36.58999, 45.438373),
                                              new YMaps.GeoPoint(36.651785, 45.37647),
                                              new YMaps.GeoPoint(36.580378, 45.329986),
                                              new YMaps.GeoPoint(36.493861, 45.3571),
                                              new YMaps.GeoPoint(36.491121, 45.29801),
                                              new YMaps.GeoPoint(36.438929, 45.261169),
                                              new YMaps.GeoPoint(36.401846, 45.206837),
                                              new YMaps.GeoPoint(36.452655, 45.096056),
                                              new YMaps.GeoPoint(36.37301, 45.056161),
                                              new YMaps.GeoPoint(36.285119, 45.055187),
                                              new YMaps.GeoPoint(36.226064, 45.025004),
                                              new YMaps.GeoPoint(35.837426, 44.986035),
                                              new YMaps.GeoPoint(35.746786, 45.082439),
                                              new YMaps.GeoPoint(35.569629, 45.125228),
                                              new YMaps.GeoPoint(35.440532, 45.087301),
                                              new YMaps.GeoPoint(35.424057, 45.011363),
                                              new YMaps.GeoPoint(35.3856, 44.949966),
                                              new YMaps.GeoPoint(35.266124, 44.960695),
                                              new YMaps.GeoPoint(35.240037, 44.910945),
                                              new YMaps.GeoPoint(35.163132, 44.896306),
                                              new YMaps.GeoPoint(35.131548, 44.825004),
                                              new YMaps.GeoPoint(35.083488, 44.791764),
                                              new YMaps.GeoPoint(35.045085, 44.803494),
                                              new YMaps.GeoPoint(35.03276, 44.826954),
                                              new YMaps.GeoPoint(34.896845, 44.81425)
                                              
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Восточный Крым";
    polygon.description = "<a href=\"Region.aspx?RegionID=6\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "FCFF0355";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(35.357258, 45.2257),
                                              new YMaps.GeoPoint(35.218487, 45.174378),
                                              new YMaps.GeoPoint(34.919177, 45.241359),
                                              new YMaps.GeoPoint(34.728393, 45.404105),
                                              new YMaps.GeoPoint(34.238137, 45.507479),
                                              new YMaps.GeoPoint(34.287572, 45.760846),
                                              new YMaps.GeoPoint(34.450975, 45.943178),
                                              new YMaps.GeoPoint(34.571825, 45.976709),
                                              new YMaps.GeoPoint(34.765439, 45.893346),
                                              new YMaps.GeoPoint(35.033236, 45.633834),
                                              new YMaps.GeoPoint(35.114264, 45.489134),
                                              new YMaps.GeoPoint(35.358714, 45.271376),
                                              new YMaps.GeoPoint(35.357258, 45.2257)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Северо - Восточный Крым";
    polygon.description = "<a href=\"Region.aspx?RegionID=7\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    style.polygonStyle.fillColor = "FFBB0355";
    polygon = new YMaps.Polygon([new YMaps.GeoPoint(33.6387, 45.0424),
                                              new YMaps.GeoPoint(33.688835, 44.969821),
                                              new YMaps.GeoPoint(33.771903, 44.905448),
                                              new YMaps.GeoPoint(33.726583, 44.854679),
                                              new YMaps.GeoPoint(33.659299, 44.798972),
                                              new YMaps.GeoPoint(33.68402, 44.687396),
                                              new YMaps.GeoPoint(33.726592, 44.464647),
                                              new YMaps.GeoPoint(34.073988, 44.560075),
                                              new YMaps.GeoPoint(34.395342, 44.832381),
                                              new YMaps.GeoPoint(34.686477, 45.028954),
                                              new YMaps.GeoPoint(34.156382, 45.300977),
                                              new YMaps.GeoPoint(33.6387, 45.0424)
                                            ], {
                                                style: "polygon#Example",
                                                hasHint: 1,
                                                hasBalloon: 1
                                            });
    polygon.name = "Центральный Крым";
    polygon.description = "<a href=\"Region.aspx?RegionID=8\">Смотреть подробнее...</a>";
    map.addOverlay(polygon);

    for (var i = 0; i < placeArr.length; i++) {
        var s = new YMaps.Style();
        s.iconStyle = new YMaps.IconStyle("example#customPointIcon");
        s.iconStyle.href = placeArr[i].icon;
        s.iconStyle.size = new YMaps.Point(26, 46);
        YMaps.Styles.add("example#customPoint", s);

        var t = new YMaps.Template("<div><img alt=\"123\" style=\"height:$[style.iconStyle.size.y];width:$[style.iconStyle.size.x];\" src=\"$[style.iconStyle.href]\"\/></div>");
        YMaps.Templates.add("example#customPointIcon", t);

        var point = new YMaps.GeoPoint(placeArr[i].lng, placeArr[i].lat);
        var placemark = new YMaps.Placemark(point, { style: "example#customPoint", hasHint: 0, hasBalloon: 0 });
        placeArr[i].iconRef = placemark;
        map.addOverlay(placemark);
    }

    return map;
}