/******************************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; WMSLayerC = undefined; WMSLayerInfoC = 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.44/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.44/esri/images/basemap/streets.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_STREETS", "Streets")); } else { $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.44/esri/images/basemap/topo.jpg')"); $("#basemapTitle").text(GetTextByKey("P_MAP_TOPOGRAPHIC", "Topographic")); } } else { $("#basemapImg").css("background-image", "url('https://js.arcgis.com/3.44/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.44/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.44/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.44/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/layers/WMSLayer", "esri/layers/WMSLayerInfo", "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, WMSLayer, WMSLayerInfo, 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; WMSLayerC = WMSLayer; WMSLayerInfoC = WMSLayerInfo; 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://new.nowcoast.noaa.gov/arcgis/rest/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer"); var layer1 = new WMSLayerInfoC({ name: 'base_reflectivity_mosaic', title: 'Weahter' }); var resourceInfo = { extent: new ExtentC(-126.4, 31.0 - 109.7, 41.5, { wkid: 4326 }), layerInfos: [layer1] }; this.WeatherLayer = new WMSLayerC("https://nowcoast.noaa.gov/geoserver/weather_radar/wms", { resourceInfo: resourceInfo, visibleLayers: ['base_reflectivity_mosaic'] }); } 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; var isHistoryTooltip = false; 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; isHistoryTooltip = false; } } }); 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 && !e.graphic.isHistoryLine) { mapObj.BaseMachineLayer.clearSingles(); e.graphic.getDojoShape().moveToFront(); showInfoWindow(e); alwaysShow = true; isHistoryTooltip = false; } }); 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 && !e.graphic.isCamSymbol) { mapObj.MyMap.infoWindow.clearFeatures(); if (e.graphic.StartOrEndPoint) e.graphic.StartOrEndPoint.getDojoShape().moveToFront(); if (e.graphic.CameraGraphic) e.graphic.CameraGraphic.getDojoShape().moveToFront(); e.graphic.getDojoShape().moveToFront(); //showInfoWindow(e); alwaysShow = true; isHistoryTooltip = 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; isHistoryTooltip = false; 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)); var esripopop = $(".esriPopupWrapper"); $(".maximize").css("display", "none"); esripopop.find(".next").removeAttr("title"); esripopop.find(".prev").removeAttr("title"); esripopop.find(".close").removeAttr("title"); } 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.ViewAlertTypes, 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"); esripopop.find(".next").removeAttr("title"); esripopop.find(".prev").removeAttr("title"); esripopop.find(".close").removeAttr("title"); $(".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.ViewAlertTypes, 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.ViewAlertTypes = attrs.ViewAlertTypes; 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 (typeof clearAssetsummaryCache === "function") clearAssetsummaryCache(); 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) { toolTipAssetSummary.viewalerttypes = machine.ViewAlertTypes; toolTipAssetSummary.alerttips = machine.AlertTips; } } } 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, "ViewAlertTypes": machine.ViewAlertTypes, "AlertTip": 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(), true); 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, noClear, color, width) {//从开始位置显示到指定索引的索引Location if (noClear) { lastLocation = null; } else { this.clearLocationHistory(); } for (var i = 0; i < locs.length && i <= toindex; i++) { var loc = locs[i]; var flag = null; if (noClear) { if (i == 0) { flag = 0; } else if (i == locs.length - 1 || i == toindex) { flag = 1; } } this.showLocationHistory(m, loc, (i == toindex) && needCenter, color, width, flag); } } this.showLocationHistory = function (m, loc, needCenter, color, width, flag) { 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, color, width); locationLineGraphics["l" + lastLocation.LogId] = lineGraphic; lineGraphic.isHistoryLine = true; mapObj.BaseMapLayer.add(lineGraphic); } else { var level = mapObj.MyMap.getLevel(); if (level < 12) { level = 12 mapObj.MyMap.setLevel(level); } } var startOrEndPoint = null; if (flag == 0) { startOrEndPoint = this.createLocationHistorySymbolPoint(point, [34, 139, 34]); } else if (flag == 1) { startOrEndPoint = this.createLocationHistorySymbolPoint(point, [255, 0, 0]); } lastLocation = loc; var gpoint = this.createLocationHistoryPoint(m, point); gpoint.StartOrEndPoint = startOrEndPoint; if (gpoint.StartOrEndPoint) mapObj.HisptoryPointLayer.add(gpoint.StartOrEndPoint); if (gpoint.CameraGraphic) mapObj.HisptoryPointLayer.add(gpoint.CameraGraphic); mapObj.HisptoryPointLayer.add(gpoint); locationHistoryPointGraphics.push(gpoint); if (needCenter) { setTimeout(function () { mapObj.MyMap.centerAt(point) }, 100); } return point; } this.clearLocationHistory = function () { lastLocation = null; locationHistoryPolylines = []; for (var i in locationLineGraphics) { mapObj.BaseMapLayer.remove(locationLineGraphics[i]); } locationLineGraphics = []; for (var i in locationHistoryPointGraphics) { if (locationHistoryPointGraphics[i].StartOrEndPoint) mapObj.HisptoryPointLayer.remove(locationHistoryPointGraphics[i].StartOrEndPoint); if (locationHistoryPointGraphics[i].CameraGraphic) mapObj.HisptoryPointLayer.remove(locationHistoryPointGraphics[i].CameraGraphic); mapObj.HisptoryPointLayer.remove(locationHistoryPointGraphics[i]); } locationHistoryPointGraphics = []; if (isHistoryTooltip) { isHistoryTooltip = false; mapObj.MyMap.infoWindow.hide(); } } 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 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); if (color) lineGraphic.isTrip = true; var oldLineGraphic = locationLineGraphics[i]; mapObj.BaseMapLayer.remove(oldLineGraphic); locationLineGraphics[i] = lineGraphic; mapObj.BaseMapLayer.add(lineGraphic); } } var tempExtent = null; for (var i in locationLineGraphics) { var g = locationLineGraphics[i]; if (g.isTrip) { if (tempExtent == null) tempExtent = g.geometry.getExtent(); else tempExtent = tempExtent.union(g.geometry.getExtent()); } } if (tempExtent && color) mapObj.MyMap.setExtent(tempExtent, true); } this.createLocationHistorySymbolPoint = function (point, color) { var symbol = new SimpleMarkerSymbolC({ color: [255, 255, 255], size: 8, style: 'esriSMSCircle', outline: { color: color, width: 6, style: 'esriSLSSolid' } }); // Location History 中构造设置不生效,原因未知 if (symbol.size == 0) { symbol.setSize(8); } if (symbol.outline.width == 0) { symbol.outline.setWidth(8); } var g = new GraphicC(point, symbol); return g; }; var inMotionIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEySURBVDhPtVItT8RAEB1ZWbnmksrKSmQVGlmJrOw/2BWXQAIhCJIicRjkJeCKQ5w4WbmyAlGBKG6Z3c4c2+1eguElr5vOx5s3ycD/QkK+uduc41tQ5A+QkICCK+SENO2+NfYlPmNeUGUEdpKCnhvErTAW+UPuiwxYV1KHh3my9gpNvaudgHpXvoDluHaioA2KTKc7J9B/9os48ZU6EfN0tzOT7TOCNWZKyFjA7r5Isn1GZA0rcMECdZhk+8PX4N7oGhK/JFD6CbZ/GA4m2SZHsdUaEi5ZIPUT1v44jSa7z9x/ep0aPer1GosDU9Bxwk4sn8pFcfFYOEdeTFMnAc8Wg5O137w1fuGR1Uv1u8aJY6rEjfgOG33aAVjXUEcEs5OPsJF44oxjkHCGrJEK2cQbAX4AQa0yMfhNcXQAAAAASUVORK5CYII="; var inMotionIcon_seatbelt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAI9SURBVDhPvVQhjOJQEK1EInGLRCKRSOTKypVIJK4/gQTEJVtBsgiSIkhAXAKCZBEksEEgEBUnKhBsgkCc6CWIboKYnff5A21hb3PmXvJS/u/M+/NmfrH+OxzHyTPLMRbMq38DJ1aUUj6Tut0u9ft9/cSaGfD7JxP6d3BglhO8TqdDQRAQEPwO6O39jfyDr9fb7ZZ6vR6EXzk+Z1JvgZcctJtMJnSMjlSf1ynTzJClLHrZvOgnaP+06XA80Gq1okaj8Yfz7reBxYbT6VRXUugULgK5HzldWXpvsVvQZrNBpWsjcQWfYsMmKsu7+UsiWJ1WtaBaqsR+tp3VlaK/nF83UmfAKkMnx5NAVAKgl+l3lUGFwjBElaGR0tUVms0mRafo0jOh2BXEbQt34Y5c10WV517yj0dMDb1LB4tdQdo2OA7GNBqNIGiLYBXDiE9SKHbRK+CebWfh0HK5hKASQXswGOjkeKDYReVohYinbXu+R7hqKEwES+12m8IoTATCLvZk6pgq+pW2jQPxFbFOUQsCmBKmVe6XL4GoKL4Gi91iotc47HQ6YcoRC2aMnK5SwTZ6BHuwW5vVEmJCfCliG4fO53MIekbqDKjzps+g4a8hPbgPN0Jx4sDn9TPt93uIHTg/a6SuQA9ardYHPn5UWuqVvhRDZRAz969iJG7BL0t8YoCpRVFE6/1aXydcDVQEIfTM2ERlX4sJOAj2W0z9nc5mM33P8MQa+0yP425tfgdOwr90jamYdbO+TjMBy/oEcsmWzBePQsYAAAAASUVORK5CYII="; var stoppedOnIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADvSURBVDhPnZItD8JADIZfiUQikUgkjiX7wCKRk0gEnjkSBIoEP8NPQILjJyCRSCRupb3rLdtyLNnepLlc7572ei3+iRJMKERAMabqahfNMShi7Nm+DFHViggXPh/p1bokA194NqGqcdC3vEYRK5MxwssHNI0DfGovYMfZHG4DojyzdkjtXlbnk70NcDWg1mlrlAtO+c5mk9VJzsUntsDY1Fo6usAJluBa173gGBm0l33gVGoelo5usB0e/rBbF1jaakCRjKL58WqrtC1eX3NQGF6VLWsxzrpRpC59wcML+UbTJ44+YzsydC9CnPwQ8AONg7vacAr1YwAAAABJRU5ErkJggg=="; var stoppedOnIcon_seatbelt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIYSURBVDhPvZQxaFpRFIYdMzpmzOjY0a1ZAkKXdqpDh9ApUAgpZJAuPtCgdKmlQhwsShDiUiJUqAUhgoQMDnbKGwwE6pAu5RVCscXh7//fd2818aVtHPrD4XrvPed7555zr7H/rmw2u0Zbn7OE3bqbGJjyPG9IQ6VSQb1eN6PmNJ/7m9b1z6JjnAG1crkM3/dh9Jnjp2PgfGimo9EI1WpV4A/0X7Whi9ImnS5arRam36+AtxngwQqwEbtue2ng6yX6/T5yudw3xkWXgbDDdrsdZvI0sQiat8erJuvBYKBMTy1iJn4lrWOazJ6sRUNu2qO4yVT1ZXzGokLpqBTweit03l0HDrzQXm6Gc41uTXP5vUghCAJlGViUyS6Rz+eBn5NZzRTkdJC1axydtK812ZcLlEolZRnWkj8eqmumds7pLsCTIzSbTQHTDrhlmvF+fzkg13u9noCeA6YbjUZ415YBfqxBV02JOWCyWCwCV8FyQJZKr4icewYoqUvq1u/u/SuQV2w6narLEwJXLM5k6Zlj65mp0/PXxn0kao1l6na7AtYsKpToXBxSwPFh9JO7ae9eYTweC3bJ+LhFzaQaFAqFH3r8JtPtZDTIPjvB7P1LWcSiuJnkF311bTLhRT87Bfaf84j3gTfPDEg1s8dUZrfDnOik4xdo5p12Oh1zzzRqrnVajX6Lx/ybGKR/6R2aR8vY+ayb1xSL/QL9uQvrk6zAAAAAAABJRU5ErkJggg=="; var stoppedOffIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADWSURBVDhPjZItFsIwEIRXIpFIZGUlskdAIpFIjlCHrOQIPQKykiMgI5FIHOHbNq/N9gcy781LOpnJbprIErxIBguYB+k3MK4+Ihf4Zu5jotWMm2C1YCHH8IgDY7L+ZCxCpAOCVnSxcYn4XoxDBwjX3lBV3jfNlHUdb3Brg3xo1eGMapyDc304cNue1Yjp4b22fDJierjUynqXg5gePmp4bcT0cPd4aL3pxYQwftcGFQiZ+eP/aR8K4UPKBnjOIWLBonZwHweU6NOnOQeMO6hXWGql+ZDIF0fPnCjLPKZjAAAAAElFTkSuQmCC"; var driverInsightIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFWSURBVDhPY6Ap2FEZqbG9OtxhZ1WoAVSIMNhfH8+xsyqsfUdl2PedVeH/d9fF/AfRILyjKnz5lpJQCahSTACyCaj5OkwDCN/ZuxrOhuLnIFdBtSAA1Ob7aIr///7+5f/epiQUsR2V4e8xXLKzMnw6siIQPj278T8IXFwxEUUcirdDtUJsh/kZGYOcDwJPzx5AEYfh7eXhCmADIH7HVPD23lWwAd/evcKQA2GgpQFgA7ZXhWagS4L8DQI/Pr0H00f6C1HkwbgyvAFiADiuUSXPL+kBB+Ch7hywITe2LESRB+HtVeEJYAP21/sLoEs+OrkLrglk2Murp1DkIRgpgQGjcD+yJLoGEB85UYGiHKoVAkDJFhYTIGefmF6DpDgcHAbIYlgT087KsAiQIegJB4Zh4jsqwgqgWjAByCXA0D2OrhmKsSdjbGBbVZgFOHqBUQWyEbtGBgYAaNW8JHqlggcAAAAASUVORK5CYII="; var driverInsightIcon_seatbelt = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJVSURBVDhPvVQxSBtRGM7o6NjR0bGjY0fHbs3gULro0MFuUkpzmsAFFIwQaMCDpBBswCVDxNhGOIyl1SOEDHrFSBWjFQV7IuKpR/n7fy/vJbm7tKWLH3yc773///L9//+ekQdHLBYbYj7p4bA8+j9w4qimaXUmZTIZyuVy4os10+bz5zL07+DAQU7IptNpsm2bgOvzE7r4vkNXPw7EutlskmEYEF7l+EcyNQwcctBBsVikO/eG9taW6NPbMVp7/azzBRuFBbq9cqharVI8Hr/kvP5tYLEPpVJJONmcf9URAPfXl31rUx8Xri3LgtMvUqIL/pUoyoSzjdmXvmTQc69pfeaFbw9rOEV/OX9KSrWBUhm0WzR8SaC1OC16h1KDZ7WcTo7jwKUjpYS74UQiQb+8e1+vFFEucFIzQ2fgzc9zSqVScNnuJf/xFFND7/oloFcAEvudn+1sU6FQgGBUCU5gGEdbH0PB6BOAXgHBYYH7lWUyTROCmhKM5vN54SQYXM/PiYFgUBD9VnofijnmVuCqwZgSHEkmkyIxGAzXSgTiKC8Yg1bhFbHOYyEIYEqYlmVM+4KDAlj3Dg7OPc/DlF0WHJBywqWGsvHMVAKCv75700kG0cPePbSpUqlAMCul2oA6b9YZdNr4LESDF1lR7R9urlCr1YLYKecPSqku0ANd12/x+OF0K+BOUT07iMn7NyolwuDDEf5FG1NzXZecoz0xGFwNOIIQeibLhLM/iylwEMrXmeKdlstlcc/wxRr7zCzHhcv8FzgJ/6UnmRpzSq670/QhEvkNNxMGho8aL+YAAAAASUVORK5CYII="; var cameraIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAVCAYAAAAnzezqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAC8ElEQVR42uyVb2jUdRzHX5/fvxv73e7WOb3WjbuWLTRTnJZJZLmghAzWsywMrSCiB1GQIIgJghD9gbACgwIHkYtiPTEXQjI0NdzahN2EtE7L7drmzd3d5u5+9/vz7YH3zCiYO33SC77wffDhy5v35/P+fuSzM1kO/jLx2rmJa68USp5CRDFfFJiGGA/caQ+8u6l1T7IxNO54ChH46VKB0aKDLkKgoGtwnE1tMYzBsdn3TmfyOwDE0LgpBFwvYCiTX7Ov788Hd3ekNpq6zBQdn5IXIAi6JhiASPV+6OzkS9GwRc/W+0k0WLjB/A0QAU2ENw//ztF0bk1fKrqqpTF08kKuxGLbpN7SuDLrrj9xqbAvW3Ba0hPXDhvFkqfdF6/n0VQES79JB6o8lGjgaDrHham5EKLQBTQh2j82u+dIOveqW/btugaT/svFbRoaKHX9LBR+9TERUbapU3T8zv2nskM9P2ffikdCdu/r7bywegle2ReDGqIJie/PT3/Rn8m/XKn4vPFUK7s7kjTZJt8MT4JS1ESAVDPRk84dcPKO3d52Bx88s5Qn7mm8obY2DoiAr0QXsd/pbGPHYy2ELf0fS2siQFWH6qvnl9O5fNG/t6kmAqouxMPmf88Jt5n/BWg1i6FS9IxMUSh7t0GACOjC+70Z1n0yyJHzV29xCpQCEZa1RvvGpp3pzZ8Osf3bX7l4tXxrZ+CRZGTX9oebN9+bjGS6jl9m7UcDfHl2EgBdpMYtAPJlt67JNk9vWbV42bPr7vrQBefFg8M83ZVmtOiAJhgE17dXsIACKn4AChpDJqYmTJc8d8PdkbdXxOsPfHdu6vPekdzjKIhFQzPGimY7P/LXbGznDxdZuqgO15//XtZEmHN9ugbGMev0SnsiPNEcthCZo+IrdOG351Y2bcymIlu+Hr6y/sm2WLexbW18694fnUP7j/0RA7wF+IeFkG7t7Eh+vCEVHan4AYmIxZnRGWYcj0BBPGx2hy29u8HS+HsA3l0gQ1y8X+cAAAAASUVORK5CYII="; this.createLocationHistoryPoint = function (m, point) { var picSymbol = null; if (point.loc.Abnormal) picSymbol = new PictureMarkerSymbolC(point.loc.IconURL, 14, 14);//url,width,height else { if (point.loc.DriverInsight != 0)//DriverInsights picSymbol = new PictureMarkerSymbolC(point.loc.SeatBelt == 2 ? driverInsightIcon_seatbelt : driverInsightIcon, 14, 14);//url,width,height else { if (point.loc.MoveStatus == 1)//InMotion picSymbol = new PictureMarkerSymbolC(point.loc.SeatBelt == 2 ? inMotionIcon_seatbelt : inMotionIcon, 14, 14);//url,width,height else if (point.loc.MoveStatus == 2)//StoppedOn picSymbol = new PictureMarkerSymbolC(point.loc.SeatBelt == 2 ? stoppedOnIcon_seatbelt : stoppedOnIcon, 14, 14);//url,width,height else if (point.loc.MoveStatus == 3)//StoppedOff picSymbol = new PictureMarkerSymbolC(stoppedOffIcon, 14, 14);//url,width,height else picSymbol = new PictureMarkerSymbolC(point.loc.IconURL, 14, 14);//url,width,height } picSymbol.setAngle(point.loc.Heading); } var existsurl = false; var divContent = "
"; var urlContent = "
"; if (point.loc.SmartWitnessVideoUrl && point.loc.SmartWitnessVideoUrl.length > 0) { existsurl = true; for (var i = 0; i < point.loc.SmartWitnessVideoUrl.length; i++) { var v = point.loc.SmartWitnessVideoUrl[i]; if (v.Key == "Driver Cam") urlContent += ""; else urlContent += ""; urlContent += "
"; } } if (point.loc.FromSmartWitness && enableSmartWitness) { if (existsurl) urlContent += "
"; existsurl = true; urlContent += ""; assetHisLocations[point.loc.LogId] = point.loc;//assetHisLocations定义在asset.js中 } var popContent = ""; if (existsurl) { urlContent += "
"; divContent += urlContent; popContent += "
"; } else popContent += "
"; 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 + "
"; var driverInsight = ""; if (point.loc.DriverInsight === 1)//ADAS driverInsight = GetTextByKey("P_MV_ADVANCEDDRIVERASSISTANCESYSTEMS", "Advanced Driver Assistance Systems"); else if (point.loc.DriverInsight === 2)//ADAS_LDWL driverInsight = GetTextByKey("P_MV_LANEDEPARTUREWARNINGLEFTSIDE", "Lane Departure Warning (left side)"); else if (point.loc.DriverInsight === 3)//ADAS_LDWR driverInsight = GetTextByKey("P_MV_LANEDEPARTUREWARNINGRIGHTSIDE", "Lane Departure Warning (right side)"); else if (point.loc.DriverInsight === 4)//ADAS_FCW driverInsight = GetTextByKey("P_MV_FORWARDCOLLISIONWARNING", "Forward Collision Warning"); else if (point.loc.DriverInsight === 5)//ADAS_HMW driverInsight = GetTextByKey("P_MV_TAILGATING", "Tailgating"); else if (point.loc.DriverInsight === 6)//ADAS_DISTRACT driverInsight = GetTextByKey("P_MV_DISTRACTIONS", "Distractions"); //GetTextByKey("P_MV_HEADWAYMONITORINGWARNING", "Headway Monitoring Warning"); else if (point.loc.DriverInsight === 7)//ADAS_PHONE driverInsight = GetTextByKey("P_MV_PHONEATEARCALLING", "Phone at Ear (Calling)"); //GetTextByKey("P_MV_DISTRACTIONS", "Distractions"); else if (point.loc.DriverInsight === 20)//DSM driverInsight = GetTextByKey("P_MV_DRIVERSTATEMONITORING", "Driver State Monitoring");// GetTextByKey("P_MV_PHONEATEARCALLING", "Phone at Ear (Calling)"); else if (point.loc.DriverInsight === 21)//DSM_FATIGUE driverInsight = GetTextByKey("P_MV_FATIGUE", "Fatigue"); //GetTextByKey("P_MV_DRIVERSTATEMONITORING", "Driver State Monitoring"); else if (point.loc.DriverInsight === 22)//DSM_DISTRACT driverInsight = GetTextByKey("P_MV_DISTRACTIONS", "Distractions");// GetTextByKey("P_MV_FATIGUE", "Fatigue"); else if (point.loc.DriverInsight === 23)//DSM_PHONE driverInsight = GetTextByKey("P_MV_PHONEATEARCALLING", "Phone at Ear (Calling)"); 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 (driverInsight !== "" || speeding !== "" || harshDriving !== "") { popContent += "
"; if (driverInsight !== "") popContent += driverInsight + "
"; if (harshDriving !== "") popContent += harshDriving + "
"; if (speeding !== "") popContent += speeding + "
"; } popContent += "
"; divContent += popContent; divContent += "
"; var g = new GraphicC(point, picSymbol); g.setAttributes({ "infoContent": divContent, "name": htmlencode(m.DisplayName), "Type": 2 }); if (point.loc.SmartWitnessVideoUrl && point.loc.SmartWitnessVideoUrl.length > 0) { var camSymbol = new PictureMarkerSymbolC(picSymbol.toJson()); camSymbol.setUrl(cameraIcon); camSymbol.setAngle(0); camSymbol.setWidth(24); camSymbol.setHeight(18); camSymbol.setOffset(3, 0); var gcam = new GraphicC(point, camSymbol); gcam.isCamSymbol = true; //gcam.setAttributes({ "infoContent": popContent, "name": htmlencode(m.DisplayName), "Type": 2 }); g.CameraGraphic = gcam; } return g; } this.createLocationHistoryLineGraphic = function (polyline, color, width) { if (!color) color = [225, 95, 72]; var lineSymbol = new SimpleLineSymbolC({ color: color, width: width || 5 }); if (lineSymbol.width == 0) //在单独Location History页面中,width设置可能无效,原因不详 lineSymbol.width = 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(), true); } } } }