/******************************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 + "