Newer
Older
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Created by gavorhes on 12/7/2015.
*/
var LayerBase_1 = require("./LayerBase");
var esriToOl = require("../olHelpers/esriToOlStyle");
var mapPopup_1 = require("../olHelpers/mapPopup");
var provide_1 = require("../util/provide");
var ol = require("custom-ol");
var $ = require("jquery");
var nm = provide_1.default('layers');
/**
* Helper to return the url to the service on the production server
* @param {string} folder
* @param {string} service
* @returns {string}
*/
function makeServiceUrl(folder, service) {
return "https://transportal.cee.wisc.edu/applications/arcgis2/rest/services/" + folder + "/" + service + "/MapServer";
}
exports.makeServiceUrl = makeServiceUrl;
function localCacheUrl(folder, service) {
var windowLocation = window.location;
var loc = windowLocation.href;
var url = "/mapserver/" + folder + "/" + service;
if (loc.indexOf('transportal.cee.wisc.edu') > -1) {
if (loc.toLowerCase().indexOf('webmapsstage') > -1) {
url = 'https://transportal.cee.wisc.edu/gis/webmapsstage' + url;
}
else {
url = 'https://transportal.cee.wisc.edu/gis/webmaps' + url;
}
}
else if (parseInt(windowLocation.port) !== 8081) {
url = 'https://transportal.cee.wisc.edu/gis/webmaps' + url;
}
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
return url;
}
exports.localCacheUrl = localCacheUrl;
/**
* esri mapserver layer
* @augments LayerBase
*/
var LayerEsriMapServer = (function (_super) {
__extends(LayerEsriMapServer, _super);
/**
* The base layer for all others
* @param {string} url - resource url
* @param {object} [options] - config
* @param {string} [options.id] - layer id
* @param {string} [options.name=Unnamed Layer] - layer name
* @param {number} [options.opacity=1] - opacity
* @param {boolean} [options.visible=true] - default visible
* @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28
* @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28
* @param {object} [options.params={}] the get parameters to include to retrieve the layer
* @param {number} [options.zIndex=0] the z index for the layer
* @param {function} [options.loadCallback] function to call on load, context this is the layer object
* @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed
* @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility
* @param {boolean} [options.legendContent] additional content to add to the legend
* @param {boolean} [options.addPopup=false] if a popup should be added
* @param {undefined|Array<number>} [options.showLayers=undefined] if a popup should be added
*/
function LayerEsriMapServer(url, options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, url, options) || this;
_this._source = new ol.source.TileArcGISRest({
url: _this.url == '' ? undefined : _this.url,
params: typeof options.showLayers == 'undefined' ? undefined : { layers: 'show:' + options.showLayers.join(',') }
});
_this._showLayers = options.showLayers || [];
_this._olLayer = new ol.layer.Tile({
source: _this._source,
visible: _this.visible,
opacity: _this.opacity,
minResolution: _this._minResolution,
maxResolution: _this._maxResolution
});
_this._olLayer.setZIndex(_this._zIndex);
options.addPopup = typeof options.addPopup == 'boolean' ? options.addPopup : false;
_this._esriFormat = new ol.format.EsriJSON();
_this._popupRequest = null;
options.getLegend = typeof options.getLegend === 'boolean' ? options.getLegend : true;
if (options.getLegend) {
_this.addLegendContent();
}
if (options.addPopup) {
mapPopup_1.default.addMapServicePopup(_this);
}
return _this;
}
/**
* add additional content to the legend
* @param {string} [additionalContent=''] additional content for legend
*/
LayerEsriMapServer.prototype.addLegendContent = function (additionalContent) {
var _this = this;
var urlCopy = this.url;
if (urlCopy[urlCopy.length - 1] !== '/') {
urlCopy += '/';
}
urlCopy += 'legend?f=pjson&callback=?';
$.get(urlCopy, {}, function (d) {
var newHtml = esriToOl.makeMapServiceLegend(d, _this._showLayers);
_super.prototype.addLegendContent.call(_this, newHtml);
}, 'json');
};
LayerEsriMapServer.prototype.getPopupInfo = function (queryParams) {
if (!this.visible) {
return;
}
var urlCopy = this.url;
if (urlCopy[urlCopy.length - 1] != '/') {
urlCopy += '/';
}
urlCopy += 'identify?callback=?';
var __this = this;
if (this._popupRequest != null) {
this._popupRequest.abort();
}
this._popupRequest = $.get(urlCopy, queryParams, function (d) {
for (var _i = 0, _a = d['results']; _i < _a.length; _i++) {
var r = _a[_i];
var popupHtml = '<table class="esri-popup-table">';
for (var a in r['attributes']) {
if (r['attributes'].hasOwnProperty(a)) {
var attrVal = r['attributes'][a];
if (attrVal == null || attrVal.toString().toLowerCase() == 'null') {
continue;
}
var attr = a;
if (attr.length > 14) {
attr = attr.slice(0, 11) + '...';
}
popupHtml += "<tr><td>" + attr + "</td><td>" + attrVal + "</td></tr>";
}
}
popupHtml += '</table>';
mapPopup_1.default.addMapServicePopupContent(__this._esriFormat.readFeature(r), __this, popupHtml, r['layerName']);
}
}, 'json');
this._popupRequest.always(function () {
__this._popupRequest = null;
});
};
Object.defineProperty(LayerEsriMapServer.prototype, "source", {
/**
*
* @returns {ol.source.TileArcGISRest} the vector source
*/
get: function () {
return _super.prototype.getSource.call(this);
},
enumerable: true,
configurable: true
});
Object.defineProperty(LayerEsriMapServer.prototype, "olLayer", {
/**
*
* @returns the ol layer
*/
get: function () {
return _super.prototype.getOlLayer.call(this);
},
enumerable: true,
configurable: true
});
return LayerEsriMapServer;
}(LayerBase_1.LayerBase));
exports.LayerEsriMapServer = LayerEsriMapServer;
nm.LayerEsriMapServer = LayerEsriMapServer;
exports.default = LayerEsriMapServer;
//# sourceMappingURL=LayerEsriMapServer.js.map