Map
Changes
web-map/Controllers/MapController.cs 44(+44 -0)
web-map/Scripts/mapInit.js 123(+94 -29)
web-map/Views/Map/Map.cshtml 6(+4 -2)
web-map/web-map.csproj 1(+1 -0)
Details
web-map/Controllers/MapController.cs 44(+44 -0)
diff --git a/web-map/Controllers/MapController.cs b/web-map/Controllers/MapController.cs
index cde152f..176bf2d 100644
--- a/web-map/Controllers/MapController.cs
+++ b/web-map/Controllers/MapController.cs
@@ -13,5 +13,49 @@ namespace web_map.Controllers
{
return View();
}
+
+ [HttpPut]
+ public JsonResult MapData(string id)
+ {
+ if (Convert.ToInt32(id) == 0)
+ {
+ List<Settlement> data = Settlement.GetData();
+ //var smth = Json(data, JsonRequestBehavior.AllowGet);
+
+
+ return Json(data, JsonRequestBehavior.AllowGet);
+ //return Json("abc", JsonRequestBehavior.AllowGet);
+ }
+ return Json(null, JsonRequestBehavior.AllowGet);
+ }
+
+
+ public class Settlement
+ {
+ public class Position
+ {
+
+ public double X { set; get; }
+ public double Y { set; get; }
+
+ }
+ public string Name { set; get; }
+ public Position position { set; get; }
+
+ public int Year { set; get; }
+ public string Type { set; get; }
+
+ public static List<Settlement> GetData(int Count = 5)
+ {
+ List<Settlement> settlements = new List<Settlement>()
+ {
+ new Settlement() { Name = "Саратов", Type = "Город", position = new Position() {X = 51.533103, Y = 46.034158 }, Year = 1590 },
+ new Settlement() { Name = "Балаково", Type = "Город", position = new Position() { X = 52.02782, Y = 47.8007 }, Year = 1911 },
+ new Settlement() { Name = "Балашов", Type = "Город", position = new Position() { X = 51.5502, Y = 43.1667 }, Year = 1780 },
+ new Settlement() { Name = "Маркс", Type = "Город", position = new Position() { X = 51.71111, Y = 46.74861 }, Year = 1942 }
+ };
+ return settlements;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/web-map/Properties/PublishProfiles/FolderProfile.pubxml b/web-map/Properties/PublishProfiles/FolderProfile.pubxml
new file mode 100644
index 0000000..cc28682
--- /dev/null
+++ b/web-map/Properties/PublishProfiles/FolderProfile.pubxml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Этот файл используется процессом публикации или упаковки вашего веб-проекта. Можно настроить поведение этого процесса,
+изменив этот файл MSBuild. Подробности см. на странице https://go.microsoft.com/fwlink/?LinkID=208121.
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <WebPublishMethod>FileSystem</WebPublishMethod>
+ <PublishProvider>FileSystem</PublishProvider>
+ <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
+ <LastUsedPlatform>Any CPU</LastUsedPlatform>
+ <SiteUrlToLaunchAfterPublish />
+ <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
+ <ExcludeApp_Data>False</ExcludeApp_Data>
+ <publishUrl>bin\Release\Publish</publishUrl>
+ <DeleteExistingFiles>False</DeleteExistingFiles>
+ </PropertyGroup>
+</Project>
\ No newline at end of file
web-map/Scripts/mapInit.js 123(+94 -29)
diff --git a/web-map/Scripts/mapInit.js b/web-map/Scripts/mapInit.js
index 9ad700f..9abf009 100644
--- a/web-map/Scripts/mapInit.js
+++ b/web-map/Scripts/mapInit.js
@@ -1,5 +1,9 @@
ymaps.ready(init);
+
+
+
+
function init() {
var map = new ymaps.Map
('map', {
@@ -53,41 +57,102 @@ function init() {
map.geoObjects.add(background);
});
+ var startData;
+ function onLoad()
+ {
+ Data = new Date();
+ console.log("onLoad: " + Data.getHours() + "." + Data.getMinutes() + "." + Data.getSeconds());
+ startData = getData(0);
+ }
+ onLoad();
+ //console.log(startData);
+
var allMarks = new ymaps.GeoObjectCollection({},
{
preset: 'islands#redStretchyIcon'
});
+ loadMarks(allMarks, startData);
+ map.geoObjects.add(allMarks);
+}
- // Имя, тип_поселения, координаты, дата_основания
- var response =
- [
- ["Саратов", "Город", [51.533103, 46.034158], 1590],
- ["Балаково", "Город", [52.02782, 47.8007], 1911],
- ["Балашов", "Город", [51.5502, 43.1667], 1780],
- ["Маркс", "Город", [51.71111, 46.74861], 1942]
- ]
-
- function loadMarks() {
- allMarks.removeAll();
- //sendRequest
- //var response = getRequest().then(function)
+function loadMarks(collection, fromData)
+{
+ collection.removeAll();
+ //sendRequest
+ //var response = getRequest().then(function)
+ {
+ Data = new Date();
+ console.log("loadMarks: " + Data.getHours() + "." + Data.getMinutes() + "." + Data.getSeconds());
+
+ fromData.forEach(function (el)
{
- response.forEach(function (el, i, response) {
- var tmp = new ymaps.Placemark(el[2],
- {
- iconContent: el[0],
- //balloonContent: String(el[1]) + " " + String(el[0]) + ". Год основания " + String(el[3]),
- hintContent: el[2]
- }
- );
- tmp.events.add('click', function (e) {
- e.preventDefault();
- alert(String(el[1]) + " " + String(el[0]) + ". Год основания " + String(el[3]));
- });
- allMarks.add(tmp);
+ console.log("2");
+ var tmp = new ymaps.Placemark(el.Position,
+ {
+ iconContent: el.Name,
+ //balloonContent: String(el[1]) + " " + String(el[0]) + ". Год основания " + String(el[3]),
+ hintContent: el.Position
+ }
+ );
+ tmp.events.add('click', function (e) {
+ e.preventDefault();
+ alert(String(el.Type) + " " + String(el.Name) + ". Год основания " + String(el.Year));
});
- map.geoObjects.add(allMarks);
- }
+ collection.add(tmp);
+ });
+ console.log("3");
}
- loadMarks();
}
+
+
+function getData(id)
+{
+ Data = new Date();
+ console.log("getData: " + Data.getHours() + "." + Data.getMinutes() + "." + Data.getSeconds());
+ var result = new Array();
+ console.log(result);
+ $.ajax({
+ url: '/Map/MapData',
+ type: 'PUT',
+ contentType: "application/json; charset=utf-8",
+ dataType: 'json',
+ cache: false,
+
+ success: function (data) {
+ for (var i = 0; i < data.length; i++) {
+ var temp = Parse(data[i]);
+ console.log(temp);
+ result.push(temp);
+ console.log(result.length);
+ console.log(result.i);
+ }
+ console.log("result length " + result.length);
+ // !!!!!!!!!!!!!!! Здесь нужно не самописный метод, а JSON.parse
+ },
+
+ error: function (response) {
+ console.log(response.responseText);
+ }
+ });
+ console.log("result");
+ console.log(result);
+ console.log("result length " + result.length);
+ return result;
+}
+
+function Parse(obJSON) {
+ Data = new Date();
+ console.log("Parse: " + Data.getHours() + "." + Data.getMinutes() + "." + Data.getSeconds());
+ var res = new Object();
+
+ res.Name = obJSON["Name"];
+ res.Position = [obJSON["position"].X, obJSON["position"].Y];
+
+ res.Year = obJSON["Year"];
+ res.Type = obJSON["Type"];
+
+ return res;
+}
+
+
+
web-map/Views/Map/Map.cshtml 6(+4 -2)
diff --git a/web-map/Views/Map/Map.cshtml b/web-map/Views/Map/Map.cshtml
index 81dd48e..36ad70d 100644
--- a/web-map/Views/Map/Map.cshtml
+++ b/web-map/Views/Map/Map.cshtml
@@ -8,8 +8,10 @@
<h2>Здесь будет размещена карта</h2>
-<div id="map" style="width: 100%; height: 1000px; padding-left: 0px; ">
-</div>
+
+<div id="map" style="width: 100%; height: 1000px; padding-left: 0px; "></div>
+
+
web-map/web-map.csproj 1(+1 -0)
diff --git a/web-map/web-map.csproj b/web-map/web-map.csproj
index dab25c5..ae1c9fc 100644
--- a/web-map/web-map.csproj
+++ b/web-map/web-map.csproj
@@ -188,6 +188,7 @@
<Content Include="ApplicationInsights.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
<None Include="Scripts\jquery-3.3.1.intellisense.js" />
<Content Include="Scripts\jquery-3.3.1.js" />
<Content Include="Scripts\jquery-3.3.1.min.js" />