/******************************MapObject******************************/ /******************************地图初始化类******************************/ if (typeof (MapObject) !== "function") { MapC = undefined; LocatorC = undefined; esriConfigC = undefined; WebTileLayerC = undefined; GraphicsLayerC = undefined; GraphicC = undefined; PointC = undefined; MultipointC = undefined; PolylineC = undefined; PolygonC = undefined; CircleC = undefined; ExtentC = undefined; GeometryEngineC = undefined; SimpleMarkerSymbolC = undefined; SimpleLineSymbolC = undefined; SimpleFillSymbolC = undefined; TextSymbolC = undefined; PictureMarkerSymbolC = undefined; FontC = undefined; InfoWindowC = undefined; PopupTemplateC = undefined; InfoTemplateC = undefined; BasemapToggleC = undefined; BasemapGalleryC = undefined; BasemapC = undefined; BasemapLayerC = undefined; UnitsC = undefined; ColorC = undefined; ClusterLayerC = undefined; ArcGISDynamicMapServiceLayerC = undefined; On = undefined; Dom = undefined; MapObject = function () { this.mapContainer = ""; this.basemapToggleContainer = ""; this.mapInitialized = undefined; this.MyMap = undefined; this.BaseMachineLayer = undefined this.BaseMapLayer = undefined this.HisptoryPointLayer = undefined//用于显示历史记录的点 this.RoutePointLayer = undefined; this.RouteSelectionPointLayer = undefined; this.SearchPointLayer = undefined; this.BasePolygonLayer = undefined; this.TrafficLayer = undefined; this.WeatherLayer = undefined; this.TransportationLayer = undefined; this.load = function (mc, bmtc, mapInitialized) { this.mapContainer = mc; this.basemapToggleContainer = bmtc; this.mapInitialized = mapInitialized; this.initMap(this); } this.initialized = function (mapObj) { //var infoWindow = new InfoWindowC({}, $("
")[0]); //infoWindow.startup(); var basemap = currentbasemap; if (userParams) { if (userParams.BaseMap == "Imagery") { basemap = "satellite"; $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.40/esri/images/basemap/satellite.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_IMAGERY", "Imagery")); } else if (userParams.BaseMap == "Streets") { basemap = "streets"; $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.40/esri/images/basemap/streets.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_STREETS", "Streets")); } else { $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.40/esri/images/basemap/topo.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_TOPOGRAPHIC", "Topographic")); } } else { $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.40/esri/images/basemap/topo.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_TOPOGRAPHIC", "Topographic")); } mapObj.MyMap = new MapC(this.mapContainer, { basemap: basemap,// "streets", "satellite", "topo", center: [0, 0], zoom: 5, sliderPosition: "top-right", slider: showMapSlider //infoWindow: infoWindow }); if (typeof setCookie === "function") setCookie("basemap", basemap); mapObj.MyMap.disableKeyboardNavigation(); mapObj.MyMap.on("load", function (e) { $("#mapView_zoom_slider").css("top", 100).css("right", 10); }); mapObj.MyMap.on("click", function (e) { if (window.currentRouteStop != null) { var stop = { 'x': e.mapPoint.getLongitude(), 'y': e.mapPoint.getLatitude() }; stop.name = stop.x.toFixed(6) + ', ' + stop.y.toFixed(6); window.currentRouteStop.data('stop', stop); window.currentRouteStop.val(stop.name).trigger('change'); window.currentRouteStopName = window.currentRouteStop; var point = new PointC([stop.x, stop.y]); mapObj.Locator.locationToAddress(point, 100); window.currentRouteStop.removeClass('focusing'); $('#routeCurrentLocation').hide(); delete window.currentRouteStop; } else { $("#basemapGallery").hide(); } }); this.BasePolygonLayer = mapObj.addGraphicsLayer(); this.BaseMapLayer = mapObj.addGraphicsLayer(); this.HisptoryPointLayer = mapObj.addGraphicsLayer();//用于显示历史记录的点,需在BaseMapLayer之后 this.RoutePointLayer = mapObj.addGraphicsLayer(); this.RouteSelectionPointLayer = mapObj.addGraphicsLayer(); this.SearchPointLayer = mapObj.addGraphicsLayer(); var layer = new ClusterLayerC({ "labelOffset": 35, "labelColor": "#F00", "labelFontSize": "20px", "labelFontFamily": "Calibri", "labelFontWeight": FontC.WEIGHT_BOLD });//可合并显示的图层 mapObj.MyMap.addLayer(layer); this.BaseMachineLayer = layer; this.TransportationLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/Reference/World_Transportation/MapServer"); if (basemap == "satellite") mapObj.MyMap.addLayer(this.TransportationLayer); //var toggle = new BasemapToggleC({ // //titleVisible: true, // map: this.MyMap, // basemap: "satellite" //}, this.basemapToggleContainer); //toggle.startup(); var basemapGallery = new BasemapGalleryC({ showArcGISBasemaps: false, map: this.MyMap }, this.basemapToggleContainer); var satellitemap = new esri.dijit.Basemap({ layers: [new esri.dijit.BasemapLayer({ url: "http://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer" })], title: GetTextByKey("P_MAP_IMAGERY", "Imagery"), thumbnailUrl: "https://js.arcgis.com/3.40/esri/images/basemap/satellite.jpg" }); basemapGallery.add(satellitemap); var topomap = new esri.dijit.Basemap({ layers: [new esri.dijit.BasemapLayer({ url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" })], title: GetTextByKey("P_MAP_TOPOGRAPHIC", "Topographic"), thumbnailUrl: "https://js.arcgis.com/3.40/esri/images/basemap/topo.jpg" }); basemapGallery.add(topomap); var streetmap = new esri.dijit.Basemap({ layers: [new esri.dijit.BasemapLayer({ //type: "OpenStreetMap", url: "http://server.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" })], title: GetTextByKey("P_MAP_STREETS", "Streets"), thumbnailUrl: "https://js.arcgis.com/3.40/esri/images/basemap/streets.jpg" }); basemapGallery.add(streetmap); basemapGallery.startup(); var _this = this; basemapGallery.on("selection-change", function () { var basemap = basemapGallery.getSelected(); if (basemap) { if (basemap.title == "Imagery") mapObj.MyMap.addLayer(_this.TransportationLayer); else mapObj.MyMap.removeLayer(_this.TransportationLayer); $("#basemapImg").css("background-image", "url('" + basemap.thumbnailUrl + "')"); $("#basemapTitle").text(basemap.title); if (userParams) { userParams.Basemap = basemap.title; setUserParams(); if (typeof setCookie === "function") { var bm = "topo"; if (userParams.Basemap == "Imagery") bm = "satellite"; else if (userParams.Basemap == "Streets") bm = "streets"; setCookie("basemap", bm); } } } $("#basemapGallery").hide(); }); basemapGallery.on("error", function (msg) { console.log("basemap gallery error:  ", msg); }); if (this.mapInitialized) this.mapInitialized(); } this.initMap = function (mapObj) { require([ "esri/map", "esri/tasks/locator", "esri/layers/WebTiledLayer", "esri/layers/GraphicsLayer", "esri/graphic", "esri/geometry/Point", "esri/geometry/Multipoint", "esri/geometry/Polyline", "esri/geometry/Polygon", "esri/geometry/Circle", "esri/geometry/Extent", "esri/geometry/geometryEngine", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/symbols/TextSymbol", "esri/symbols/PictureMarkerSymbol", "esri/symbols/Font", "esri/dijit/InfoWindow", "esri/dijit/PopupTemplate", "esri/InfoTemplate", "esri/dijit/BasemapToggle", "esri/dijit/BasemapGallery", "esri/dijit/Basemap", "esri/dijit/BasemapLayer", "esri/units", "esri/Color", "extras1/clusterlayer", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/urlUtils", "dojo/on", "dojo/dom", "dojo/domReady!" ], function (Map, Locator, WebTileLayer, GraphicsLayer, Graphic, Point, Multipoint, Polyline, Polygon, Circle, Extent, GeometryEngine, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, TextSymbol, PictureMarkerSymbol, Font, InfoWindow, PopupTemplate, InfoTemplate, BasemapToggle, BasemapGallery, Basemap, BasemapLayer, Units, Color, ClusterLayer, ArcGISDynamicMapServiceLayer, urlUtils, on, dom) { MapC = Map; LocatorC = Locator; esriConfigC = esriConfig; WebTileLayerC = WebTileLayer; GraphicsLayerC = GraphicsLayer; GraphicC = Graphic; PointC = Point; MultipointC = Multipoint; PolylineC = Polyline; PolygonC = Polygon; CircleC = Circle; ExtentC = Extent; GeometryEngineC = GeometryEngine; SimpleMarkerSymbolC = SimpleMarkerSymbol; SimpleLineSymbolC = SimpleLineSymbol; SimpleFillSymbolC = SimpleFillSymbol; TextSymbolC = TextSymbol; PictureMarkerSymbolC = PictureMarkerSymbol; FontC = Font; InfoWindowC = InfoWindow; PopupTemplateC = PopupTemplate; InfoTemplateC = InfoTemplate; BasemapToggleC = BasemapToggle; BasemapGalleryC = BasemapGallery; BasemapC = Basemap; BasemapLayerC = BasemapLayer; UnitsC = Units; ColorC = Color; ClusterLayerC = ClusterLayer; ArcGISDynamicMapServiceLayerC = ArcGISDynamicMapServiceLayer; On = on; Dom = dom; urlUtils.addProxyRule({ urlPrefix: "traffic.arcgis.com", proxyUrl: "proxy/proxy.ashx" }); if (mapObj) { mapObj.initialized(mapObj); mapObj.Locator = new Locator("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); mapObj.LocatorAsync = new Locator("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); mapObj.Locator.on('location-to-address-complete', function (e) { if (e.address.address) { var address = e.address.address; if (window.currentRouteStopName) { var label = getAddressLabel(address); window.currentRouteStopName.val(label); // LongLabel var stop = window.currentRouteStopName.data('stop'); if (stop != null) { stop.name = label; } delete window.currentRouteStopName; } } }); } }); } this.addGraphicsLayer = function () { var layer = new GraphicsLayerC(); this.MyMap.addLayer(layer); return layer; } this.showTrafficLayer = function (state) { if (state) { if (!this.TrafficLayer) this.TrafficLayer = new ArcGISDynamicMapServiceLayerC("https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer"); this.TrafficLayer.refreshInterval = 3; this.MyMap.addLayer(this.TrafficLayer); } else { if (this.TrafficLayer) this.MyMap.removeLayer(this.TrafficLayer); } } this.showWeatherLayer = function (state) { if (state) { if (!this.WeatherLayer) this.WeatherLayer = new ArcGISDynamicMapServiceLayerC("https://nowcoast.noaa.gov/arcgis/rest/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer"); this.WeatherLayer.refreshInterval = 5; this.MyMap.addLayer(this.WeatherLayer); } else { if (this.WeatherLayer) this.MyMap.removeLayer(this.WeatherLayer); } } } } /******************************MapHelper******************************/ /******************************Machine,Jobsite,Dealer Location,Shape相关地图操作类******************************/ if (typeof (MapHelper) !== "function") { MapHelper = function (mapInitialized) { var mapObj = new MapObject(); mapObj.load("mapView", "basemapGallery", afterMapInitialized); var machineGraphics = []; var shownMachines = []; this.unShownMachineIDs = [];//不需显示的机器ID this.unShownJobSiteIDs = [];//不需要显示的JobSiteID var toolTipAssetSummary; var toolTipJobsiteSummary; function afterMapInitialized() { var alwaysShow = false; mapObj.BaseMachineLayer.on("mouse-over", function (e) { if (!alwaysShow) { mapObj.BaseMachineLayer.clearSingles(); showInfoWindow(e, 0); } }); mapObj.BaseMachineLayer.on("mouse-out", function (e) { if (!alwaysShow) { mapObj.MyMap.infoWindow.hide(); if (toolTipAssetSummary) toolTipAssetSummary.status = 1; } }); mapObj.BaseMachineLayer.on("click", function (e) { if (e.graphic) { if (window.currentRouteStopName != null) { //delete window.currentRouteStopName; } else { alwaysShow = true; } } }); mapObj.BaseMapLayer.on("mouse-over", function (e) { if (!alwaysShow) showInfoWindow(e); }); mapObj.BaseMapLayer.on("mouse-out", function (e) { if (!alwaysShow) mapObj.MyMap.infoWindow.hide(); }); mapObj.BaseMapLayer.on("click", function (e) { if (e.graphic) { mapObj.BaseMachineLayer.clearSingles(); e.graphic.getDojoShape().moveToFront(); showInfoWindow(e); alwaysShow = true; } }); mapObj.BasePolygonLayer.on("mouse-over", function (e) { if (!alwaysShow && userParams.ShowJSTooltip) { mapObj.MyMap.infoWindow.clearFeatures(); showInfoWindow(e, 1); } }); mapObj.BasePolygonLayer.on("mouse-out", function (e) { if (!alwaysShow) { mapObj.MyMap.infoWindow.hide(); if (toolTipJobsiteSummary) toolTipJobsiteSummary.status = 1; } }); mapObj.HisptoryPointLayer.on("click", function (e) { if (e.graphic) { mapObj.MyMap.infoWindow.clearFeatures(); e.graphic.getDojoShape().moveToFront(); //showInfoWindow(e); alwaysShow = true; mapObj.MyMap.infoWindow.setFeatures(locationHistoryPointGraphics); var index = locationHistoryPointGraphics.indexOf(e.graphic); if (index >= 0) mapObj.MyMap.infoWindow.select(index) mapObj.MyMap.infoWindow.show(e.screenPoint, mapObj.MyMap.getInfoWindowAnchor(e.screenPoint)); } }); mapObj.HisptoryPointLayer.on("mouse-over", function (e) { if (!alwaysShow) { mapObj.MyMap.infoWindow.clearFeatures(); showInfoWindow(e); } }); mapObj.HisptoryPointLayer.on("mouse-out", function (e) { if (!alwaysShow) mapObj.MyMap.infoWindow.hide(); }); mapObj.BasePolygonLayer.on("click", function (e) { if (e.graphic) { mapObj.MyMap.infoWindow.clearFeatures(); e.graphic.getDojoShape().moveToFront(); alwaysShow = true; var singles = []; for (var ii in machineGraphics) { if (ii.indexOf("JSID") < 0) continue; var gg = machineGraphics[ii]; if (GeometryEngineC.intersects(e.graphic.geometry, gg.geometry)) singles.push(gg); } if (singles.length > 0) { mapObj.MyMap.infoWindow.setFeatures(singles); mapObj.MyMap.infoWindow.show(e.screenPoint, mapObj.MyMap.getInfoWindowAnchor(e.screenPoint)); } else//shape showInfoWindow(e); } }); mapObj.MyMap.infoWindow.on("hide", function (e) { alwaysShow = false; mapObj.BaseMachineLayer._popupedClusterData = null; toolTipAssetSummary = null; toolTipJobsiteSummary = null; }); mapObj.MyMap.infoWindow.on("selection-change", function (e) { var f = mapObj.MyMap.infoWindow.getSelectedFeature(); if (f && f.attributes) { if (enableInfoWindow) { if (f.attributes.Type === 0) {//Asset if (window.currentRouteStop != null) { var stop = { 'x': f.geometry.x, 'y': f.geometry.y, 'name': GetTextByKey('P_MR_ASSET', 'Asset') + ': ' + f.attributes.DisplayName, 'assetId': f.attributes.ID }; window.currentRouteStop.data('stop', stop); window.currentRouteStop.val(stop.name).trigger('change'); window.currentRouteStopName = window.currentRouteStop; mapObj.Locator.locationToAddress(new PointC([stop.x, stop.y]), 100); window.currentRouteStop.removeClass('focusing'); $('#routeCurrentLocation').hide(); delete window.currentRouteStop; mapObj.MyMap.infoWindow.clearFeatures(); mapObj.MyMap.infoWindow.hide(); } else { mapObj.MyMap.infoWindow.resize(520, 460);//resize只能设置max-height $(".contentPane").css("height", 460).unbind(); if (typeof $assetsummary === "function") { mapObj.MyMap.infoWindow.setContent("
"); if (toolTipAssetSummary) toolTipAssetSummary.status = 1; var assetInfos = null; if (mapObj.MyMap.infoWindow.features && mapObj.MyMap.infoWindow.features.length > 0) assetInfos = mapObj.MyMap.infoWindow.features.map(function (item) { return item.attributes }); toolTipAssetSummary = new $assetsummary("assetDetailCtrl", f.attributes.CompanyID, f.attributes.ID, f.attributes.AlertTip, 1, assetInfos); var esripopop = $(".esriPopupWrapper"); esripopop.find(".tempdropdown").remove(); esripopop.find(".title").unbind().removeClass("titlelink"); if (assetInfos.length > 1) { esripopop.find(".title").addClass("titlelink").click(function () {//title 弹出搜索框 var div_assets = $('
'); div_assets.dropdown(assetInfos, { search: true, valueKey: 'ID', textKey: 'DisplayName_O', searchKeys: ['Name', 'Name2', 'VIN'] }); div_assets.find(".dropdown-wrapper").css("border", "1px solid #b9b9b9"); div_assets.dropdownVal(f.attributes.ID); div_assets.on('select', function (_e, item) { if (item && item.ID != f.attributes.ID) { var temps = assetInfos.filter(function (a) { return a.ID == item.ID }) if (temps && temps.length > 0) mapObj.MyMap.infoWindow.select(assetInfos.indexOf(temps[0])); } esripopop.find(".tempdropdown").remove(); }); $(".esriPopupWrapper").find(".tempdropdown").remove(); $(".esriPopupWrapper").append(div_assets); }); } } else { mapObj.MyMap.infoWindow.currentattributes = f.attributes; getAssetByID(f.attributes.ID); } } } else if (f.attributes.Type === 1) {//Jobsite mapObj.MyMap.infoWindow.resize(420, 300);//resize只能设置max-height $(".contentPane").css("height", 300); if (typeof $jobsitesummary === "function") { mapObj.MyMap.infoWindow.setContent("
"); if (toolTipJobsiteSummary) toolTipJobsiteSummary.status = 1; var jsInfos = null; if (mapObj.MyMap.infoWindow.features && mapObj.MyMap.infoWindow.features.length > 0) jsInfos = mapObj.MyMap.infoWindow.features.map(function (item) { return item.jobsite }); toolTipJobsiteSummary = new $jobsitesummary("JobsiteDetailCtrl", f.jobsite, 1, jsInfos); toolTipJobsiteSummary.jobsitechanged = function (index) { if (index >= 0) mapObj.MyMap.infoWindow.select(index); } var esripopop = $(".esriPopupWrapper"); esripopop.find(".tempdropdown").remove(); esripopop.find(".title").unbind().removeClass("titlelink"); if (jsInfos.length > 1) { esripopop.find(".title").addClass("titlelink").click(function () {//title 弹出搜索框 var div_assets = $('
'); div_assets.dropdown(jsInfos, { search: true, valueKey: 'ID', textKey: 'Name' }); div_assets.find(".dropdown-wrapper").css("border", "1px solid #b9b9b9"); div_assets.dropdownVal(f.jobsite.ID); div_assets.on('select', function (_e, item) { if (item && item.ID != f.jobsite.ID) { var temps = jsInfos.filter(function (a) { return a.ID == item.ID }) if (temps && temps.length > 0) mapObj.MyMap.infoWindow.select(jsInfos.indexOf(temps[0])); } esripopop.find(".tempdropdown").remove(); }); $(".esriPopupWrapper").find(".tempdropdown").remove(); $(".esriPopupWrapper").append(div_assets); }); } } else { } } else if (f.attributes.Type === 2) {//History Point mapObj.MyMap.infoWindow.resize(420, 200);//resize只能设置max-height $(".contentPane").css("height", 200); mapObj.MyMap.infoWindow.setContent(f.attributes.infoContent + "
");//setContent最后没有空行,需添加一个空行,和selection-change保持一致 } else if (f.attributes.Type === 3) {//Shape mapObj.MyMap.infoWindow.setContent(f.attributes.infoContent + "
");//setContent最后没有空行,需添加一个空行,和selection-change保持一致 } } } }); mapObj.SearchPointLayer.on("click", function (e) { var input = $('#routePlaces').data('parent'); if (input == null) { return; } var graphic = e.graphic; if (graphic == null) { return; } var level = mapObj.MyMap.getLevel(); if (level < 14) { mapObj.MyMap.setLevel(14); } mapObj.MyMap.centerAt(graphic.geometry); $('#routePlaces').hide(); mapObj.SearchPointLayer.clear(); input.val(graphic.attributes.name).data('stop', { 'x': graphic.geometry.x, 'y': graphic.geometry.y, 'name': graphic.attributes.name }).trigger('change'); }); if (mapInitialized) mapInitialized(); } function showInfoWindow(e, type) { var esripopop = $(".esriPopupWrapper"); esripopop.find(".tempdropdown").remove(); esripopop.find(".title").unbind().removeClass("titlelink"); $(".esriPopupWrapper").find(".tempdropdown").remove(); if (enableInfoWindow && e.graphic && e.graphic.attributes) { $(".maximize").css("display", "none"); $(".actionsPane").addClass("hidden"); mapObj.MyMap.infoWindow.setTitle(e.graphic.attributes.name || e.graphic.attributes.DisplayName); if (type == 0) { mapObj.MyMap.infoWindow.resize(520, 460);//resize只能设置max-height $(".contentPane").css("height", 460).unbind(); if (typeof $assetsummary === "function") { mapObj.MyMap.infoWindow.setContent("
"); if (toolTipAssetSummary) toolTipAssetSummary.status = 1; toolTipAssetSummary = new $assetsummary("assetDetailCtrl", e.graphic.attributes.CompanyID, e.graphic.attributes.ID, e.graphic.attributes.AlertTip, 1); } else { var currentattrs = mapObj.MyMap.infoWindow.currentattributes; if (!currentattrs || e.graphic.attributes.ID != currentattrs.ID) { mapObj.MyMap.infoWindow.currentattributes = e.graphic.attributes; getAssetByID(e.graphic.attributes.ID); } } } else if (type == 1) { mapObj.MyMap.infoWindow.resize(420, 300);//resize只能设置max-height $(".contentPane").css("height", 300); if (typeof $jobsitesummary === "function") { mapObj.MyMap.infoWindow.setContent("
"); if (toolTipJobsiteSummary) toolTipJobsiteSummary.status = 1; toolTipJobsiteSummary = new $jobsitesummary("JobsiteDetailCtrl", e.graphic.jobsite, 1); } else { mapObj.MyMap.infoWindow.setContent(e.graphic.attributes.infoContent + "
");//setContent最后没有空行,需添加一个空行,和selection-change保持一致 } } else { mapObj.MyMap.infoWindow.resize(undefined, undefined); $(".contentPane").css("height", "unset"); mapObj.MyMap.infoWindow.setContent(e.graphic.attributes.infoContent + "
");//setContent最后没有空行,需添加一个空行,和selection-change保持一致 } mapObj.MyMap.infoWindow.show(e.screenPoint, mapObj.MyMap.getInfoWindowAnchor(e.screenPoint)); } } this.changeBaseMap = function (bm) { mapObj.MyMap.setBasemap(bm); } this.showTraffic = function (state) { mapObj.showTrafficLayer(state); } this.showWeather = function (state) { mapObj.showWeatherLayer(state); } this.showAssetDetailInfo = function (assetdetail) { var attrs = mapObj.MyMap.infoWindow.currentattributes; if (attrs && attrs.Type === 0 && attrs.ID == assetdetail.ID) { assetdetail.AlertTip = attrs.AlertTip; var popContent = getAssetPopupContent(assetdetail); mapObj.MyMap.infoWindow.setContent(popContent + "
"); attrs.infoContent = popContent; } } this.showMachine = function (machine) { this.removeMachine(machine); var p = this.createMachinePoint(machine); mapObj.BaseMachineLayer.add(p); mapObj.MyMap.infoWindow.currentattributes = null; shownMachines["MachineID" + machine.ID] = p; } this.showMachines = function (machines) { var ps = []; var infowindowassetexist = false;//infowindow显示的机器是否在查询结果里 var infowindowassetid = -1; if (toolTipAssetSummary && toolTipAssetSummary.status == 0) infowindowassetid = toolTipAssetSummary.assetid; for (var i = 0; i < machines.length; i++) { var machine = machines[i]; var p = this.createMachinePoint(machine); ps.push(p); shownMachines["MachineID" + machine.ID] = p; if (infowindowassetid == machine.ID) infowindowassetexist = true; } if (toolTipAssetSummary && toolTipAssetSummary.status == 0) { if (infowindowassetexist) { toolTipAssetSummary.refresh(); } else { mapObj.MyMap.infoWindow.currentattributes = null; alwaysShow = false; mapObj.MyMap.infoWindow.hide(); } } mapObj.BaseMachineLayer.adds(ps); } this.createMachinePoint = function (machine) { var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(machine.Name) + "
"; popContent += "" + GetTextByKey("P_MV_NAMECUSTOM_COLON", "Name (Custom):") + " " + htmlencode(machine.Name2) + "
"; popContent += "" + GetTextByKey("P_MV_SN_COLON", "SN:") + " " + machine.VIN + "
"; popContent += "" + GetTextByKey("P_MV_MAKE_COLON", "Make:") + " " + machine.Make + "
"; popContent += "" + GetTextByKey("P_MV_MODEL_COLON", "Model:") + " " + machine.Model + "
"; popContent += "" + GetTextByKey("P_MV_TYPE_COLON", "Type:") + " " + machine.AssetType + "
"; var attributes = { "Type": 0,//用于区分InfoWindow是否是Asset "CompanyID": machine.CompanyID, "ID": machine.ID, "Name": htmlencode(machine.Name), "Name2": htmlencode(machine.Name2), "VIN": machine.VIN, "DisplayName": htmlencode(machine.DisplayName), "DisplayName_O": machine.DisplayName + " (" + machine.VIN + ")", "Make": machine.Make, "Model": machine.Model, "AssetType": machine.AssetType, //"EngineHours": machine.EngineHours, //"Odometer": machine.Odometer, //"OdometerUOM": machine.OdometerUOM, "AlertTip": htmlencode(machine.AlertTips), "IconUrl": machine.IconUrl, //"EmptyIconUrl": machine.IconUrl.replace(new RegExp("typeid=\\d+&", "i"), "typeid=-1&").replace(new RegExp("mid=\\d+&", "i"), ""), "EmptyIconUrl": machine.IconUrl.replace("typeid", "typeid=-1&t").replace("mid", "m"), "Priority": machine.Priority, "infoContent": popContent }; var p = { "id": machine.ID, "x": machine.Longitude, "y": machine.Latitude, "attributes": attributes } return p; } this.locateMachine = function (machine, notShowInfowindow, level) { //隐藏Popup的最大化和缩放至 $(".maximize").css("display", "none"); $(".actionsPane").addClass("hidden"); if (!level) { level = mapObj.MyMap.getLevel(); if (level < 6) level = 6 } mapObj.MyMap.setLevel(level); //mapObj.MyMap.centerAndZoom(point, level); var p = shownMachines["MachineID" + machine.ID]; if (p) { mapObj.BaseMachineLayer.locate(p, true, notShowInfowindow); } return p; } this.gotoMap = function (obj) { if (obj) mapObj.MyMap.setExtent(obj, true); } this.centerAt = function (point) { mapObj.MyMap.centerAt(point); } this.removeMachine = function (machine) { var p = shownMachines["MachineID" + machine.ID]; if (p) { mapObj.BaseMachineLayer.remove(p); //shownMachines.splice("MachineID" + machine.ID, 1); delete shownMachines["MachineID" + machine.ID]; } } this.removeMachines = function (machines) { if (machines && machines.length > 0) { //var ps = []; var psid = []; for (var i in machines) { var p = shownMachines["MachineID" + machines[i].ID]; //ps.push(p); psid.push(p.id); //shownMachines.splice("MachineID" + machines[i].ID, 1); delete shownMachines["MachineID" + machines[i].ID]; } //mapObj.BaseMachineLayer.removes(ps); mapObj.BaseMachineLayer.removebyid(psid); } } this.clearMachine = function () { shownMachines = []; mapObj.BaseMachineLayer.clearData(); } this.showJobSite = function (js) { this.removeJobSite(js); if (js.Longitude == 0 && js.Latitude == 0) return; var jsShape = null; if (js.Radius > 0) { jsShape = createJobSiteCircle(js); } else if (js.Polygon && js.Polygon.length >= 4) {//多边形 jsShape = createJobSitePolygon(js); } if (jsShape) { mapObj.BasePolygonLayer.add(jsShape); machineGraphics["JSID" + js.ID] = jsShape; } } this.refreshJobsiteTooltip = function (jss) { if (!toolTipJobsiteSummary || !toolTipJobsiteSummary.jobsite || toolTipJobsiteSummary.status != 0) return; for (var i = 0; i < jss.length; i++) { var js = jss[i]; if (toolTipJobsiteSummary.jobsite.ID == js.ID) { toolTipJobsiteSummary.refresh(js); return; } } if (toolTipJobsiteSummary && toolTipJobsiteSummary.status == 0) { mapObj.MyMap.infoWindow.currentattributes = null; alwaysShow = false; mapObj.MyMap.infoWindow.hide(); } } function createJobSiteCircle(js) { var point = new PointC({ longitude: js.Longitude, latitude: js.Latitude }); var unit = UnitsC.MILES; if (js.Radius_UOM === "Kilometre") unit = UnitsC.KILOMETERS; var circle = new CircleC( { center: point, radius: js.Radius, radiusUnit: unit, geodesic: true }); // Create a symbol for rendering the graphic var fillSymbol = new SimpleFillSymbolC({ color: [js.Color.Red, js.Color.Green, js.Color.Blue, 51], outline: { // autocasts as new SimpleLineSymbol() color: [js.Color.Red, js.Color.Green, js.Color.Blue] } }); fillSymbol.setStyle(SimpleFillSymbolC.STYLE_SOLID); var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(js.Name) + "
"; popContent += "" + GetTextByKey("P_MV_CODE_COLON", "Code:") + " " + htmlencode(js.Code) + "
"; popContent += "" + GetTextByKey("P_MV_NUMBER_COLON", "Number:") + " " + htmlencode(js.Number) + "
"; popContent += "" + GetTextByKey("P_MV_LATLONG_COLON", "Lat/Long:") + " " + js.Latitude + ", " + js.Longitude + "
"; popContent += "" + GetTextByKey("P_MV_DELIVERYADDRESS_COLON", "Delivery Address:") + " " + htmlencode(js.Address1) + "
"; popContent += "
" + GetTextByKey("P_MV_FOREMAN_COLON", "Foreman:") + " " + htmlencode(js.Foreman) + "
"; popContent += "
" + GetTextByKey("P_MV_STARTDATE_COLON", "Start Date:") + " " + js.StartDateStr + "
"; popContent += "" + GetTextByKey("P_MV_ENDDATE_COLON", "End Date:") + " " + js.EndDateStr + "
"; popContent += "
" + GetTextByKey("P_MV_NOTES_COLON", "Notes:") + " " + htmlencode(js.Notes) + "
"; var g = new GraphicC(circle, fillSymbol); var name = htmlencode(js.Name); if (js.Code && $.trim(js.Code) != "") name += " / " + htmlencode(js.Code); if (js.Number && $.trim(js.Number) != "") name += " / " + htmlencode(js.Number); g.setAttributes({ "infoContent": popContent, "name": name, "Type": 1 }); g.jobsite = js; return g; } function createJobSitePolygon(js) { var points = new Array(); for (var i = 0; i < js.Polygon.length; i++) { var pi = js.Polygon[i]; var point = [pi.Longitude, pi.Latitude]; points.push(point); } var polygon = new PolygonC(points); // Create a symbol for rendering the graphic var fillSymbol = new SimpleFillSymbolC({ color: [js.Color.Red, js.Color.Green, js.Color.Blue, 51], outline: { // autocasts as new SimpleLineSymbol() color: [js.Color.Red, js.Color.Green, js.Color.Blue] } }); fillSymbol.setStyle(SimpleFillSymbolC.STYLE_SOLID); var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(js.Name) + "
"; popContent += "" + GetTextByKey("P_MV_CODE_COLON", "Code:") + " " + htmlencode(js.Code) + "
"; popContent += "" + GetTextByKey("P_MV_NUMBER_COLON", "Number:") + " " + htmlencode(js.Number) + "
"; popContent += "" + GetTextByKey("P_MV_LATLONG_COLON", "Lat/Long:") + " " + js.Latitude + ", " + js.Longitude + "
"; popContent += "" + GetTextByKey("P_MV_DELIVERYADDRESS_COLON", "Delivery Address:") + " " + htmlencode(js.Address1) + "
"; popContent += "
" + GetTextByKey("P_JS_FOREMAN_COLON", "Foreman:") + " " + htmlencode(js.Foreman) + "
"; popContent += "
" + GetTextByKey("P_MV_STARTDATE_COLON", "Start Date:") + " " + js.StartDateStr + "
"; popContent += "" + GetTextByKey("P_MV_ENDDATE_COLON", "End Date:") + " " + js.EndDateStr + "
"; popContent += "
" + GetTextByKey("P_MV_NOTES_COLON", "Notes:") + " " + htmlencode(js.Notes) + "
"; var g = new esri.Graphic(polygon, fillSymbol); var name = htmlencode(js.Name); if (js.Code && $.trim(js.Code) != "") name += " / " + htmlencode(js.Code); if (js.Number && $.trim(js.Number) != "") name += " / " + htmlencode(js.Number); g.setAttributes({ "infoContent": popContent, "name": name, "Type": 1 }); g.jobsite = js; return g; } this.locateJobSite = function (js) { var g = machineGraphics["JSID" + js.ID]; if (g) { mapObj.MyMap.setExtent(g.geometry.getExtent()); var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(js.Name) + "
"; popContent += "" + GetTextByKey("P_MV_LATITUDE_COLON", "Latitude:") + " " + js.Latitude + "
"; popContent += "" + GetTextByKey("P_MV_LONGITUDE_COLON", "Longitude:") + " " + js.Longitude + "
"; var point = new PointC({ longitude: js.Longitude, latitude: js.Latitude }); //var p = mapObj.MyMap.toScreen(point); //mapObj.MyMap.infoWindow.setTitle(htmlencode(js.Name)); //mapObj.MyMap.infoWindow.setContent(popContent); //mapObj.MyMap.infoWindow.show(point, mapObj.MyMap.getInfoWindowAnchor(p)); showInfoWindow({ graphic: g, screenPoint: point }, 1); } } this.removeJobSite = function (js, hidden) { var g = machineGraphics["JSID" + js.ID]; if (g) { mapObj.BasePolygonLayer.remove(g); //machineGraphics.splice("JSID" + js.ID, 1); delete machineGraphics["JSID" + js.ID]; if (hidden && toolTipJobsiteSummary && toolTipJobsiteSummary.status == 0 && mapObj.MyMap.infoWindow.features) { for (var i = 0; i < mapObj.MyMap.infoWindow.features.length; i++) { var f = mapObj.MyMap.infoWindow.features[i]; if (f && f.jobsite && f.jobsite.ID == js.ID) { setTimeout(function () { mapObj.MyMap.infoWindow.hide(); }); break; } } } } } this.removeJobsites = function (jobsites) { if (jobsites && jobsites.length > 0) { for (var i in jobsites) { var js = jobsites[i]; this.removeJobSite(js); } } } var lastLocation; var locationHistoryPolylines = []; var locationLineGraphics = []; var locationHistoryPointGraphics = []; this.showLocationHistoryFromStart = function (m, locs, toindex, needCenter) {//从开始位置显示到指定索引的索引Location this.clearLocationHistory(); var point; for (var i = 0; i < locs.length && i <= toindex; i++) { var loc = locs[i]; point = this.showLocationHistory(m, loc, false); } if (needCenter) { mapObj.MyMap.centerAt(point); } } this.showLocationHistory = function (m, loc, needCenter) { var point = new PointC({ longitude: loc.Longitude, latitude: loc.Latitude }); point.loc = loc; if (lastLocation) { var polyLine = new PolylineC({ paths: [[]] }); var point0 = new PointC({ longitude: lastLocation.Longitude, latitude: lastLocation.Latitude }); polyLine.insertPoint(0, polyLine.paths[0].length, point0); polyLine.insertPoint(0, polyLine.paths[0].length, point); locationHistoryPolylines["l" + lastLocation.LogId] = polyLine; polyLine.StartTime = lastLocation.LocationTime; polyLine.EndTime = loc.LocationTime; var lineGraphic = this.createLocationHistoryLineGraphic(polyLine); locationLineGraphics["l" + lastLocation.LogId] = lineGraphic; mapObj.BaseMapLayer.add(lineGraphic); } else { var level = mapObj.MyMap.getLevel(); if (level < 12) level = 12 mapObj.MyMap.setLevel(level); } lastLocation = loc; var gpoint = this.createLocationHistoryPoint(m, point); mapObj.HisptoryPointLayer.add(gpoint); locationHistoryPointGraphics.push(gpoint); if (needCenter) mapObj.MyMap.centerAt(point); return point; } this.clearLocationHistory = function () { lastLocation = null; locationHistoryPolylines = []; for (var i in locationLineGraphics) { mapObj.BaseMapLayer.remove(locationLineGraphics[i]); } locationLineGraphics = []; for (var i in locationHistoryPointGraphics) { mapObj.HisptoryPointLayer.remove(locationHistoryPointGraphics[i]); } locationHistoryPointGraphics = []; } var lastRouteLine; var routeLinePolylines = []; var routeLineGraphics = []; var routeHistoryPointGraphics = []; var routePoints; this.showSelection = function (stops) { if (stops == null) { return; } mapObj.RouteSelectionPointLayer.clear(); for (var i = 0; i < stops.length; i++) { var stop = stops[i]; var point = new PointC([stop.x, stop.y]); var pointSymbol = new SimpleMarkerSymbolC(SimpleMarkerSymbolC.STYLE_CIRCLE, 12, null, new ColorC('black')); var g = new GraphicC(point, pointSymbol); mapObj.RouteSelectionPointLayer.add(g); pointSymbol = new SimpleMarkerSymbolC(SimpleMarkerSymbolC.STYLE_CIRCLE, 9, null, new ColorC('white')); g = new GraphicC(point, pointSymbol); mapObj.RouteSelectionPointLayer.add(g); } }; this.clearPlaces = function () { mapObj.SearchPointLayer.clear(); }; this.searchPlaces = function (name, next) { var center = mapObj.MyMap.extent.getCenter(); var params = { 'address': { 'address': name }, 'location': new PointC([center.getLongitude(), center.getLatitude()]), 'outFields': ['PlaceName', 'Place_addr'], 'maxLocations': 10, 'langCode': _fleet.currentMapLang }; mapObj.Locator.addressToLocations(params).then(function (results) { next(results); }); }; this.showPlaces = function (addrs) { mapObj.SearchPointLayer.clear(); for (var i = 0; i < addrs.length; i++) { var addr = addrs[i]; var point = this.createPlacePinPoint( new PointC([addr.location.x, addr.location.y]), addr ); mapObj.SearchPointLayer.add(point); } }; this.getRouteLocationFromAsset = function (id) { var asset = allAssets.filter(function (a) { return a.ID == id })[0]; if (asset != null) { return { 'x': asset.Longitude, 'y': asset.Latitude }; } return null; }; this.getRouteFromPosition = function (pos) { if (window.currentRouteStop != null) { var stop = { 'x': pos.longitude, 'y': pos.latitude }; stop.name = stop.x.toFixed(6) + ', ' + stop.y.toFixed(6); window.currentRouteStop.data('stop', stop); window.currentRouteStop.val(stop.name).trigger('change'); window.currentRouteStopName = window.currentRouteStop; var point = new PointC([stop.x, stop.y]); mapObj.Locator.locationToAddress(point, 100); window.currentRouteStop.removeClass('focusing'); delete window.currentRouteStop; } }; this.getRouteFromPositionAsync = function (pos) { var point = new PointC([pos.x, pos.y]); return mapObj.LocatorAsync.locationToAddress(point, 100); }; this.showRouteFromStart = function (locs, start, recenter) { if (start == 0) { this.clearRouteHistory(); mapObj.RouteSelectionPointLayer.clear(); routePoints = new MultipointC(); } for (var i = 0; i < locs.length; i++) { var loc = locs[i]; routePoints.addPoint(new PointC({ longitude: loc[0], latitude: loc[1] })); this.showRoute({ 'Index': start + i, 'Longitude': loc[0], 'Latitude': loc[1] }, i == 0, i == locs.length - 1, start == 0, recenter); } if (recenter) { mapObj.MyMap.setExtent(routePoints.getExtent()); } } this.showRoute = function (loc, firstOne, lastOne, start, end) { var point = new PointC({ longitude: loc.Longitude, latitude: loc.Latitude }); point.loc = loc; if (lastRouteLine == null) { lastRouteLine = { type: 'polyline', paths: [[]] }; routeLinePolylines.push(lastRouteLine); } lastRouteLine.paths[0].push([loc.Longitude, loc.Latitude]); if (lastOne) { var polyline = new PolylineC({ paths: lastRouteLine.paths }); var symbol = new SimpleLineSymbolC({ color: [47, 99, 209], width: 5 }); var lineGraphic = new GraphicC(polyline, symbol); routeLineGraphics.push(lineGraphic); mapObj.BaseMapLayer.add(lineGraphic); symbol = new SimpleLineSymbolC({ color: [110, 154, 245], width: 3 }); lineGraphic = new GraphicC(polyline, symbol); routeLineGraphics.push(lineGraphic); mapObj.BaseMapLayer.add(lineGraphic); lastRouteLine = null; } var gpoint; if ((start && firstOne) || lastOne) { gpoint = this.createRouteHistoryPoint(point, 12, 'black'); mapObj.RoutePointLayer.add(gpoint); routeHistoryPointGraphics.push(gpoint); gpoint = this.createRouteHistoryPoint(point, 7, 'white'); mapObj.RoutePointLayer.add(gpoint); routeHistoryPointGraphics.push(gpoint); //} else { // gpoint = this.createRouteHistoryPoint(point, 6, 'black'); // mapObj.RoutePointLayer.add(gpoint); // routeHistoryPointGraphics.push(gpoint); // gpoint = this.createRouteHistoryPoint(point, 5, 'white'); // mapObj.RoutePointLayer.add(gpoint); // routeHistoryPointGraphics.push(gpoint); } if (lastOne) { gpoint = this.createRouteHistoryPoint(point, 3, 'black'); mapObj.RoutePointLayer.add(gpoint); routeHistoryPointGraphics.push(gpoint); if (end) { gpoint = this.createRoutePinPoint(point); mapObj.RoutePointLayer.add(gpoint); routeHistoryPointGraphics.push(gpoint); } } return point; } this.clearRouteHistory = function () { lastRouteLine = null; routeLinePolylines = []; for (var i = 0; i < routeLineGraphics.length; i++) { mapObj.BaseMapLayer.remove(routeLineGraphics[i]); } routeLineGraphics = []; for (var i in routeHistoryPointGraphics) { mapObj.RoutePointLayer.remove(routeHistoryPointGraphics[i]); } routeHistoryPointGraphics = []; }; this.createRouteHistoryPoint = function (point, size, color) { var pointSymbol = new SimpleMarkerSymbolC(SimpleMarkerSymbolC.STYLE_CIRCLE, size, null, new ColorC(color)); var g = new GraphicC(point, pointSymbol); //g.setAttributes({ "infoContent": popContent, "name": htmlencode(shape.Name), "Type": 3 }); return g; } this.createRoutePinPoint = function (point) { var picSymbol = new PictureMarkerSymbolC('img/pin.png', 23, 34);//url,width,height var g = new GraphicC(point, picSymbol); return g; } this.createPlacePinPoint = function (point, place) { var picSymbol = new PictureMarkerSymbolC('https://static.arcgis.com/images/Symbols/Shapes/RedPin1LargeB.png', 30, 34);//url,width,height var g = new GraphicC(point, picSymbol); g.setAttributes({ "name": place.attributes.Place_addr || place.address }); return g; }; this.changeLineColor = function (from, to, color) {//color:[0,0,0] rgb if (Object.keys(locationHistoryPolylines).length == 0) return; if (!from) from = "1900-1-1"; if (!to) to = "2099-12-31"; var temp = null; var dtfrom = new Date(from.replace(/-/g, "/").replace("T", " ")) var dtto = new Date(to.replace(/-/g, "/").replace("T", " ")) for (var i in locationHistoryPolylines) { var polyLine = locationHistoryPolylines[i]; var ldtstart = new Date(polyLine.StartTime.replace(/-/g, "/").replace("T", " ")); var ldtend = new Date(polyLine.EndTime.replace(/-/g, "/").replace("T", " ")); if (ldtstart >= dtfrom && ldtend <= dtto) { var lineGraphic = this.createLocationHistoryLineGraphic(polyLine, color); var oldLineGraphic = locationLineGraphics[i]; mapObj.BaseMapLayer.remove(oldLineGraphic); locationLineGraphics[i] = lineGraphic; mapObj.BaseMapLayer.add(lineGraphic); temp = lineGraphic; } } if (temp && color) mapObj.MyMap.setExtent(temp.geometry.getExtent()); } this.createLocationHistoryPoint = function (m, point) { var picSymbol = new PictureMarkerSymbolC(point.loc.IconURL, 14, 14);//url,width,height var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(m.Name) + "
"; popContent += "" + GetTextByKey("P_MV_NAMECUSTOM_COLON", "Name (Custom):") + " " + htmlencode(m.Name2) + "
"; popContent += "" + GetTextByKey("P_MV_SN_COLON", "SN:") + " " + m.VIN + "
"; popContent += "" + GetTextByKey("P_MV_LATITUDE_COLON", "Latitude:") + " " + point.loc.Latitude + "
"; popContent += "" + GetTextByKey("P_MV_LONGITUDE_COLON", "Longitude:") + " " + point.loc.Longitude + "
"; var speed = ""; if (point.loc.Speed >= 0) speed = point.loc.Speed.toLocaleString() + " " + point.loc.SpeedUnit; if (speed !== "") popContent += "" + GetTextByKey("P_MV_CURRENTSPEED_COLON", "Current Speed:") + " " + speed + "
"; var postedspeed = ""; if (point.loc.PostedSpeed > 0) postedspeed = point.loc.PostedSpeed.toLocaleString() + " " + (point.loc.PostedSpeedUnit === "mi/h" ? "mph" : point.loc.PostedSpeedUnit); if (postedspeed !== "") popContent += "" + GetTextByKey("P_MV_POSTEDSPEED_COLON", "Posted Speed:") + " " + postedspeed + "
"; if (point.loc.Street !== "") popContent += "" + GetTextByKey("P_MV_STREET_COLON", "Street:") + "" + point.loc.Street + "
"; if (point.loc.LocationTimeText !== "") popContent += "" + GetTextByKey("P_MV_TIME_COLON", "Time:") + " " + point.loc.LocationTimeText + "
"; if (point.loc.SmartWitnessVideoUrl && point.loc.SmartWitnessVideoUrl.length > 0) { for (var i = 0; i < point.loc.SmartWitnessVideoUrl.length; i++) { var v = point.loc.SmartWitnessVideoUrl[i]; popContent += "
" + htmlencode(v.Key) + ""; } popContent += "
"; } if (point.loc.FromSmartWitness && enableSmartWitness) { popContent += "
"; assetHisLocations[point.loc.LogId] = point.loc;//assetHisLocations定义在asset.js中 } var harshDriving = ""; if (point.loc.HarshDringEvent === 1) harshDriving = GetTextByKey("P_MV_HARDACCELERATION", "Hard Acceleration"); else if (point.loc.HarshDringEvent === 2) harshDriving = GetTextByKey("P_MV_HARDBRAKE", "Hard Brake"); else if (point.loc.HarshDringEvent === 3) harshDriving = GetTextByKey("P_MV_HARDBTURN", "Hard Turn"); var speeding = ""; if (point.loc.SpeedingBehavior === 1) speeding = GetTextByKey("P_MV_SPEEDINGLOWSEVERITY", "Speeding: Low Severity"); else if (point.loc.SpeedingBehavior === 2) speeding = GetTextByKey("P_MV_SPEEDINGHIGHSEVERITY", "Speeding: High Severity"); if (speeding !== "" || harshDriving !== "") { popContent += "
"; if (harshDriving !== "") popContent += harshDriving + "
"; if (speeding !== "") popContent += speeding + "
"; } var g = new GraphicC(point, picSymbol); g.setAttributes({ "infoContent": popContent, "name": htmlencode(m.DisplayName), "Type": 2 }); return g; } this.createLocationHistoryLineGraphic = function (polyline, color) { if (!color) color = [225, 95, 72]; var lineSymbol = new SimpleLineSymbolC({ color: color, width: 5 }); if (lineSymbol.width == 0) //在单独Location History页面中,width设置可能无效,原因不详 lineSymbol.width = 5; var g = new GraphicC(polyline, lineSymbol); return g; } this.showLocation = function (loc) { this.removeLocation(loc); if (loc.Longitude == 0 && loc.Latitude == 0) return; var point = new PointC({ longitude: loc.Longitude, latitude: loc.Latitude }); point.z = 10; var picSym = new PictureMarkerSymbolC(loc.IconUrl, 20, 20); //picSym.setOffset(0, 25); var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(loc.LocationName) + "
"; popContent += "" + GetTextByKey("P_MV_LATITUDE_COLON", "Latitude:") + " " + loc.Latitude + "
"; popContent += "" + GetTextByKey("P_MV_LONGITUDE_COLON", "Longitude:") + " " + loc.Longitude + "
"; popContent += "" + GetTextByKey("P_MV_NOTES_COLON", "Notes:") + " " + loc.Notes + "
"; var g = new GraphicC(point, picSym); g.setAttributes({ "infoContent": popContent, "name": htmlencode(loc.LocationName) }); mapObj.BaseMapLayer.add(g); machineGraphics["LocationID" + loc.ID] = g; } this.removeLocation = function (loc) { var g = machineGraphics["LocationID" + loc.ID]; if (g) { mapObj.BaseMapLayer.remove(g); //machineGraphics.splice("LocationID" + loc.ID, 1); delete machineGraphics["LocationID" + loc.ID]; } } this.showShape = function (shape) { this.removeShape(shape); if (!shape || !shape.Shape) return; var color = "#FFA500"; var gs = []; var popContent = "" + GetTextByKey("P_MV_NAME_COLON", "Name:") + " " + htmlencode(shape.Name) + "
"; var reg = new RegExp("\r\n", "g"); shape.Notes = shape.Notes.replace(reg, "
"); reg = new RegExp("\n", "g"); shape.Notes = shape.Notes.replace(reg, "
"); popContent += "" + GetTextByKey("P_MV_NOTES_COLON", "Notes:") + " " + htmlencode(shape.Notes) + "
"; if (shape.Shape.Points && shape.Shape.Points.length > 0) { var pointSymbol = new SimpleMarkerSymbolC(SimpleMarkerSymbolC.STYLE_CIRCLE, 6, null, new ColorC(color)); var sPoints = new MultipointC(); for (var i = 0; i < shape.Shape.Points.length; i++) { var p = shape.Shape.Points[i]; var point = new PointC({ longitude: p.Longitude, latitude: p.Latitude }); sPoints.addPoint(point); //var g = new GraphicC(point, pointSymbol); //g.setAttributes({ "infoContent": popContent, "name": htmlencode(shape.Name), "Type": 1 }); //mapObj.BasePolygonLayer.add(g); //gs.push(g); } var g = new GraphicC(sPoints, pointSymbol); g.setAttributes({ "infoContent": popContent, "name": htmlencode(shape.Name), "Type": 3 }); mapObj.BasePolygonLayer.add(g); gs.push(g); } if (shape.Shape.Polylines && shape.Shape.Polylines.length > 0) { var line = new PolylineC({ paths: [] }); for (var i = 0; i < shape.Shape.Polylines.length; i++) { var l = shape.Shape.Polylines[i]; line.addPath([]); for (var j = 0; j < l.Points.length; j++) { var p = l.Points[j]; var point = new PointC({ longitude: p.Longitude, latitude: p.Latitude }); line.insertPoint(line.paths.length - 1, j, point); } } var lineSymbol = new SimpleLineSymbolC({ color: [255, 165, 0],//[225, 95, 72], width: 2 }); var g = new GraphicC(line, lineSymbol); g.setAttributes({ "infoContent": popContent, "name": htmlencode(shape.Name), "Type": 3 }); mapObj.BasePolygonLayer.add(g); gs.push(g); } if (shape.Shape.Polygons && shape.Shape.Polygons.length > 0) { var polygon = new PolygonC({ rings: [] }); for (var i = 0; i < shape.Shape.Polygons.length; i++) { var pl = shape.Shape.Polygons[i]; polygon.addRing([]); for (var j = 0; j < pl.Points.length; j++) { var p = pl.Points[j]; var point = new PointC({ longitude: p.Longitude, latitude: p.Latitude }); polygon.insertPoint(polygon.rings.length - 1, j, point); } } // Create a symbol for rendering the graphic var fillSymbol = new SimpleFillSymbolC({ color: [255, 165, 0, 51], outline: { // autocasts as new SimpleLineSymbol() color: [255, 165, 0] } }); fillSymbol.setStyle(SimpleFillSymbolC.STYLE_SOLID); var g = new GraphicC(polygon, fillSymbol); g.setAttributes({ "infoContent": popContent, "name": htmlencode(shape.Name), "Type": 3 }); mapObj.BasePolygonLayer.add(g); gs.push(g); } machineGraphics["ShapeID" + shape.ID] = gs; } this.removeShape = function (shape) { var gs = machineGraphics["ShapeID" + shape.ID]; if (gs) { for (var i = 0; i < gs.length; i++) { var g = gs[i]; mapObj.BasePolygonLayer.remove(g); //machineGraphics.splice("ShapeID" + shape.ID, 1); delete machineGraphics["ShapeID" + shape.ID]; } } } this.locateShape = function (shape) { var gs = machineGraphics["ShapeID" + shape.ID]; if (gs && gs.length > 0) { var level = mapObj.MyMap.getLevel(); if (level < 6) level = 6 mapObj.MyMap.setLevel(level); if (gs[0].geometry.type == "point") mapObj.MyMap.centerAt(gs[0].geometry); else mapObj.MyMap.setExtent(gs[0].geometry.getExtent()); } } } }