UNPKG

123 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var React = _interopDefault(require('react'));
8var async = require('async');
9var async__default = _interopDefault(async);
10var ReactDOM = _interopDefault(require('react-dom'));
11var reactArcgis = require('react-arcgis');
12var arcgisToGeojsonUtils = require('@esri/arcgis-to-geojson-utils');
13
14function styleInject(css, ref) {
15 if ( ref === void 0 ) ref = {};
16 var insertAt = ref.insertAt;
17
18 if (!css || typeof document === 'undefined') { return; }
19
20 var head = document.head || document.getElementsByTagName('head')[0];
21 var style = document.createElement('style');
22 style.type = 'text/css';
23
24 if (insertAt === 'top') {
25 if (head.firstChild) {
26 head.insertBefore(style, head.firstChild);
27 } else {
28 head.appendChild(style);
29 }
30 } else {
31 head.appendChild(style);
32 }
33
34 if (style.styleSheet) {
35 style.styleSheet.cssText = css;
36 } else {
37 style.appendChild(document.createTextNode(css));
38 }
39}
40
41var css = ".ArcticMap_simple-form-group__1NBSl {\n margin-bottom: 1rem;\n }\n .ArcticMap_simple-text-label__sb2Ru {\n display: block;\n color: red;\n }\n .ArcticMap_simple-text-input__2vXLO {\n display: inline-block;\n margin-bottom: 0.5rem;\n font-size: 16px;\n font-weight: 400;\n color: rgb(33, 37, 41);\n }\n\n#ArcticMap_bottomleftbar__m8-8e{\n background: #fff;\n position: absolute;\n bottom: 30px;\n left: 15px;\n padding: 0px;\n font-family: 'Avenir Next W00\",\"Helvetica Neue\",Helvetica,Arial,sans-serif'\n}\n\n#ArcticMap_bottomleftbar__m8-8e p{\n padding-left: 12px;\n padding-right: 12px;\n}\n \n#ArcticMap_bottombar__2nOal {\n background: #fff;\n position: absolute;\n bottom: 30px;\n right: 15px;\n padding: 0;\n }\n\n .ArcticMap_action-button__2k3Yr {\n font-size: 16px;\n background-color: transparent;\n border: 1px solid #D3D3D3;\n color: #6e6e6e;\n height: 32px;\n width: 32px;\n text-align: center;\n box-shadow: 0 0 1px rgba(0, 0, 0, 0.3);\n }\n\n .ArcticMap_action-button__2k3Yr:hover,\n .ArcticMap_action-button__2k3Yr:focus {\n background: #0079c1;\n color: #e4e4e4;\n }\n\n .ArcticMap_active__2g4Ex {\n background: #0079c1;\n color: #e4e4e4;\n }";
42var styles = { "simple-form-group": "ArcticMap_simple-form-group__1NBSl", "simple-text-label": "ArcticMap_simple-text-label__sb2Ru", "simple-text-input": "ArcticMap_simple-text-input__2vXLO", "bottomleftbar": "ArcticMap_bottomleftbar__m8-8e", "bottombar": "ArcticMap_bottombar__2nOal", "action-button": "ArcticMap_action-button__2k3Yr", "active": "ArcticMap_active__2g4Ex" };
43styleInject(css);
44
45var classCallCheck = function (instance, Constructor) {
46 if (!(instance instanceof Constructor)) {
47 throw new TypeError("Cannot call a class as a function");
48 }
49};
50
51var createClass = function () {
52 function defineProperties(target, props) {
53 for (var i = 0; i < props.length; i++) {
54 var descriptor = props[i];
55 descriptor.enumerable = descriptor.enumerable || false;
56 descriptor.configurable = true;
57 if ("value" in descriptor) descriptor.writable = true;
58 Object.defineProperty(target, descriptor.key, descriptor);
59 }
60 }
61
62 return function (Constructor, protoProps, staticProps) {
63 if (protoProps) defineProperties(Constructor.prototype, protoProps);
64 if (staticProps) defineProperties(Constructor, staticProps);
65 return Constructor;
66 };
67}();
68
69var inherits = function (subClass, superClass) {
70 if (typeof superClass !== "function" && superClass !== null) {
71 throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
72 }
73
74 subClass.prototype = Object.create(superClass && superClass.prototype, {
75 constructor: {
76 value: subClass,
77 enumerable: false,
78 writable: true,
79 configurable: true
80 }
81 });
82 if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
83};
84
85var possibleConstructorReturn = function (self, call) {
86 if (!self) {
87 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
88 }
89
90 return call && (typeof call === "object" || typeof call === "function") ? call : self;
91};
92
93var slicedToArray = function () {
94 function sliceIterator(arr, i) {
95 var _arr = [];
96 var _n = true;
97 var _d = false;
98 var _e = undefined;
99
100 try {
101 for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
102 _arr.push(_s.value);
103
104 if (i && _arr.length === i) break;
105 }
106 } catch (err) {
107 _d = true;
108 _e = err;
109 } finally {
110 try {
111 if (!_n && _i["return"]) _i["return"]();
112 } finally {
113 if (_d) throw _e;
114 }
115 }
116
117 return _arr;
118 }
119
120 return function (arr, i) {
121 if (Array.isArray(arr)) {
122 return arr;
123 } else if (Symbol.iterator in Object(arr)) {
124 return sliceIterator(arr, i);
125 } else {
126 throw new TypeError("Invalid attempt to destructure non-iterable instance");
127 }
128 };
129}();
130
131var ArcticMapButton = function (_React$Component) {
132 inherits(ArcticMapButton, _React$Component);
133
134 function ArcticMapButton(props) {
135 classCallCheck(this, ArcticMapButton);
136
137 var _this = possibleConstructorReturn(this, (ArcticMapButton.__proto__ || Object.getPrototypeOf(ArcticMapButton)).call(this, props));
138
139 _this.state = {
140 enabled: true,
141 useEsriIcon: props.esriicon !== null,
142 active: props.showactive !== undefined && props.showactive === true
143
144 };
145
146 _this.fireclick = function (e) {
147 if (this.props.onclick) {
148 this.props.onclick(e);
149 }
150 };
151
152 return _this;
153 }
154
155 createClass(ArcticMapButton, [{
156 key: 'render',
157 value: function render() {
158
159 var style = {
160 arcticButton: {
161 padding: "5px",
162 height: "32px",
163 width: "32px",
164 backgroundColor: "#fff",
165 color: '#6e6e6e',
166 border: 'none',
167 display: 'flex',
168 flexFlow: 'row nowrap',
169 justifyContent: 'center',
170 alignItems: 'center',
171 cursor: 'pointer',
172 '&:hover': {
173 backgroundColor: "#ccc"
174 }
175 }
176 };
177
178 if (this.props.padtop) {
179 style.arcticButton.marginTop = '10px';
180 }
181 if (this.props.padbottom) {
182 style.arcticButton.marginBOttom = '10px';
183 }
184
185 if (this.state.useEsriIcon) {
186 if (this.props.showactive && this.props.showactive === true) {
187 style.arcticButton.backgroundColor = "#d4d1d1";
188 } else {
189 style.arcticButton.backgroundColor = "#fff";
190 }
191
192 var esriClassName = 'esri-icon esri-icon-' + this.props.esriicon;
193
194 return React.createElement(
195 'button',
196 { style: style.arcticButton, onClick: this.fireclick.bind(this), title: this.props.title },
197 React.createElement('span', { style: { height: "15px", width: "15px" }, 'aria-hidden': true, className: esriClassName })
198 );
199 } else {
200 return React.createElement('div', null);
201 }
202 }
203 }]);
204 return ArcticMapButton;
205}(React.Component);
206
207ArcticMapButton.displayName = 'ArcticMapButton';
208
209var style = {
210 bg: {
211 zIndex: "100",
212 position: "absolute",
213 top: 0,
214 width: '100%',
215 height: '100%',
216 backgroundColor: '#5856569e'
217
218 }
219
220};
221var loadingtext = {
222 position: "absolute",
223 top: '50%',
224 left: '50%',
225 transform: 'translate(-50%, -50%)',
226 color: 'white'
227};
228
229var ArcticMapLoader = function (_React$Component) {
230 inherits(ArcticMapLoader, _React$Component);
231
232 function ArcticMapLoader(props) {
233 classCallCheck(this, ArcticMapLoader);
234 return possibleConstructorReturn(this, (ArcticMapLoader.__proto__ || Object.getPrototypeOf(ArcticMapLoader)).call(this, props));
235 }
236
237 createClass(ArcticMapLoader, [{
238 key: 'render',
239 value: function render() {
240
241 if (this.props.loading === true) {
242
243 return React.createElement(
244 'div',
245 { style: style.bg },
246 React.createElement(
247 'h1',
248 { style: loadingtext },
249 'Working...'
250 )
251 );
252 }
253 return null;
254 }
255 }]);
256 return ArcticMapLoader;
257}(React.Component);
258
259ArcticMapLoader.displayName = 'ArcticMapLoader';
260
261var styles$1 = {
262 rightWidgetFull: {
263 "position": "absolute",
264 "right": "2px",
265 "top": "2px",
266 "bottom": "2px",
267 "zIndex": "100",
268
269 "minWidth": '30%',
270 paddingTop: '20px'
271 },
272 widgetContainer: {
273 position: 'realative',
274 "paddingRight": "20px",
275 "paddingLeft": "20px",
276
277 "overflowY": 'auto',
278 "maxHeight": '100%'
279 }
280
281};
282
283var ArcticMapPanel = function (_React$Component) {
284 inherits(ArcticMapPanel, _React$Component);
285
286 function ArcticMapPanel(props) {
287 classCallCheck(this, ArcticMapPanel);
288
289 var _this = possibleConstructorReturn(this, (ArcticMapPanel.__proto__ || Object.getPrototypeOf(ArcticMapPanel)).call(this, props));
290
291 _this.toggle = function () {
292
293 var currvalue = this.state.open;
294 this.setState({ open: !currvalue });
295 };
296 _this.toggle = _this.toggle.bind(_this);
297
298 _this.mapFrame = document.getElementsByClassName('esri-view-root')[0];
299 _this.renderEle = document.createElement("span");
300 _this.mapFrame.appendChild(_this.renderEle);
301 _this.state = {
302 hidden: !_this.props.hidden ? false : true,
303 open: _this.props.open || false
304 };
305
306 if (props.map) {
307 _this.map = props.map;
308 }
309 if (props.view) {
310 _this.view = props.view;
311 _this.view.on('click', function (e) {
312 _this.setState({ open: false });
313 });
314 }
315
316 return _this;
317 }
318
319 createClass(ArcticMapPanel, [{
320 key: 'componentDidMount',
321 value: function componentDidMount() {
322
323 // console.log(self.props);
324 // self.props.view.on('click', (event) => {
325
326 // self.setState({ open: false });
327
328 // });
329 }
330 }, {
331 key: 'componentDidUpdate',
332 value: function componentDidUpdate() {
333 this.renderPanel();
334 }
335 }, {
336 key: 'render',
337 value: function render() {
338
339 return React.createElement(
340 'span',
341 { visibility: this.state.hidden },
342 React.createElement(ArcticMapButton, { padtop: this.props.padtop, padbottom: this.props.padbottom, esriicon: this.props.esriicon, onclick: this.toggle.bind(this), title: this.props.title })
343 );
344 }
345 }, {
346 key: 'renderPanel',
347 value: function renderPanel() {
348 // refactor this
349 if (this.state.open) {
350 var ele = React.createElement('div', { className: 'esri-widget', style: styles$1.rightWidgetFull }, React.createElement('h2', { style: { "paddingLeft": "20px", marginTop: '6px', fontSize: '28px', marginBottom: '10px' } }, this.props.title), React.createElement('span', { style: { position: 'absolute', top: '20px', right: '20px' } }, React.createElement('button', {
351 onClick: this.toggle,
352 title: 'Close',
353 style: { border: 'none', background: 'transparent', cursor: 'pointer' }
354 }, React.createElement('span', {
355 style: { fontSize: '28px' },
356 'aria-hidden': true,
357 className: 'esri-icon esri-icon-close'
358 }))
359 //React.createElement(ArcticMapButton, { esriicon: 'close', onclick: this.toggle, style : { fontSize : '28px'} })
360 ), React.createElement('div', { style: styles$1.widgetContainer }, React.createElement('div', null, this.props.children)));
361
362 // <button style={style.arcticButton} onClick={this.fireclick.bind(this)} title={this.props.title} >
363 // <span style={{ height: "15px", width: "15px" }} aria-hidden className={esriClassName} ></span>
364 // </button>
365
366 ReactDOM.render(ele, this.renderEle);
367 } else {
368 var eleempty = React.createElement('span', null);
369 ReactDOM.render(eleempty, this.renderEle);
370 }
371 }
372 }]);
373 return ArcticMapPanel;
374}(React.Component);
375
376ArcticMapPanel.displayName = 'ArcticMapPanel';
377
378var style$1 = document.createElement('style');
379style$1.id = "esri-overrides";
380style$1.innerHTML = '.esri-ui-bottom-right {' + 'flex-flow: column;' + '}' + '.esri-ui-bottom-right .esri-component {' + 'margin-top: 10px;' + '}' + '.esri-layer-list { background-color: transparent; padding: 1px; }' + '.esri-layer-list__item--has-children .esri-layer-list__item { box-shadow: none; }' + '.esri-layer-list__item--has-children { border-bottom: none; box-shadow: 0px 0px 3px 0px black; border-radius: 4px; margin-bottom: 10px; }' + '.esri-basemap-gallery { position: absolute; bottom: 0; right: 0; }';
381document.head.appendChild(style$1);
382
383var ArcticMap = function (_React$Component) {
384 inherits(ArcticMap, _React$Component);
385
386 function ArcticMap(props) {
387 classCallCheck(this, ArcticMap);
388
389 var _this = possibleConstructorReturn(this, (ArcticMap.__proto__ || Object.getPrototypeOf(ArcticMap)).call(this, props));
390
391 _this.state = {
392 map: null,
393 view: null,
394 hideBasemapButton: false,
395 loading: false,
396 lat: props.lat,
397 lng: props.lng,
398 mode: props.mode || "view",
399 basemap: props.basemap || "hybrid",
400 sr: Number.parseInt(props.sr || "102100")
401 };
402
403 _this.handleMapLoad = _this.handleMapLoad.bind(_this);
404 _this.handleMapClick = _this.handleMapClick.bind(_this);
405 _this.layers = [];
406 return _this;
407 }
408
409 createClass(ArcticMap, [{
410 key: 'render',
411 value: function render() {
412 var self = this;
413 var index = 0;
414 this.layers = [];
415
416 self.childrenElements = [];
417
418 var children = React.Children.map(this.props.children, function (child) {
419 if (child.type.displayName === 'ArcticMapLayer') {
420 return React.cloneElement(child, {
421 ref: function ref(c) {
422 if (c) {
423 self.layers.push(c);
424 }
425 }
426 });
427 } else if (child.type.displayName === 'ArcticMapEdit') {
428 // console.log(self.refs);
429 return React.cloneElement(child, {
430 am: self
431 // ref: 'editor'
432
433 });
434 }
435
436 // else if (child.type.name === 'ArcticMapLLDSearch') {
437
438 // return React.cloneElement(child, {
439 // })
440
441 // }
442
443 else {
444 return React.cloneElement(child, {
445 am: self,
446
447 map: self.state.map,
448 view: self.state.view,
449 //ref: 'child-' + (index++)
450 ref: function ref(c) {
451 if (c) {
452 self.childrenElements.push(c);
453 }return 'child-' + index++;
454 }
455 });
456 }
457 });
458
459 if (children) {
460 children = children.sort(function (l) {
461 return l.type.displayName === 'ArcticMapEdit';
462 }).reverse();
463 } else {
464 children = React.createElement('div', null);
465 }
466
467 // console.log(this.props.children);
468 // this.props.children.forEach((child) =>{
469 // child.ref = (c) => {this.layers.push(c) };
470 // });
471
472
473 return React.createElement(
474 reactArcgis.Map,
475 { 'class': 'full-screen-map',
476 mapProperties: { basemap: this.state.basemap }, onLoad: this.handleMapLoad, onClick: this.handleMapClick },
477 children,
478 React.createElement(ArcticMapLoader, { loading: this.state.loading })
479 );
480 }
481 }, {
482 key: 'handleShowBasemaps',
483 value: function handleShowBasemaps(event) {
484 this.state.view.ui.add(this.basemapGallery, {
485 position: 'bottom-right'
486 });
487
488 this.setState({ hideBasemapButton: true });
489 }
490 }, {
491 key: 'handleMapClick',
492 value: function handleMapClick(event) {
493 // console.log(event);
494 }
495 }, {
496 key: 'createElementFromHTML',
497 value: function createElementFromHTML(htmlString) {
498 var div = document.createElement('div');
499 div.innerHTML = htmlString.trim();
500
501 // Change this to div.childNodes to support multiple top-level nodes
502 return div.firstChild;
503 }
504 }, {
505 key: 'setEdit',
506 value: function setEdit(json, nofire, type) {
507 if (nofire === null) {
508 nofire = false;
509 }
510
511 if (type === null) {
512 type = "polygon";
513 }
514
515 if (this.state.map.editor) {
516 this.state.map.editor.setEditFeature(json, nofire, type);
517 }
518 }
519 }, {
520 key: 'setMode',
521 value: function setMode(val) {
522 this.setState({ mode: val });
523 if (val === "identify") {
524 this.state.view.cursor = "help";
525 }
526 if (val === "view") {
527 this.state.view.cursor = "grab";
528 }
529 if (val === "select") {
530 this.state.view.cursor = "auto";
531 }
532 if (val === "edit") {
533 this.state.view.cursor = "crosshairs";
534 }
535 }
536 }, {
537 key: 'setJson',
538 value: function setJson(json) {
539 if (this.state.map.editor) {
540 this.state.map.editor.setEditFeature(json, true);
541 }
542 }
543 }, {
544 key: 'handleMapLoad',
545 value: function handleMapLoad(map, view) {
546 var _this2 = this;
547
548 this.setState({ map: map, view: view });
549
550 var self = this;
551 self.state.map.amlayers = [];
552 var centerSplit = this.props.center.split('|');
553 view.center = [parseFloat(centerSplit[1]), parseFloat(centerSplit[0])];
554 view.zoom = parseInt(centerSplit[2]);
555 self.cntrlIsPressed = false;
556
557 reactArcgis.loadModules(['esri/widgets/Locate', 'esri/widgets/BasemapGallery', 'esri/widgets/Home', 'esri/widgets/Search', 'esri/layers/FeatureLayer',
558 // 'esri/tasks/Locator',
559 'esri/geometry/geometryEngine', "esri/request"]).then(function (_ref) {
560 var _ref2 = slicedToArray(_ref, 7),
561 Locate = _ref2[0],
562 BasemapGallery = _ref2[1],
563 Home = _ref2[2],
564 Search = _ref2[3],
565 FeatureLayer = _ref2[4],
566
567 // Locator,
568 geometryEngine = _ref2[5],
569 Request = _ref2[6];
570
571 window._request = Request;
572 window._map = self;
573 self.request = Request;
574
575 if (self.state.mode === "identify") {
576 self.state.view.cursor = "help";
577 }
578 if (self.state.mode === "view") {
579 self.state.view.cursor = "grab";
580 }
581 if (self.state.mode === "edit") {
582 self.state.view.cursor = "crosshairs";
583 }
584
585 if (self.state.mode === "select") {
586 self.state.view.cursor = "auto";
587 }
588
589 // self.state.view.spatialReference = {
590 // wkid: self.state.sr,
591 // };
592
593 // var layerList = new LayerList({
594 // view: self.state.view,
595 // listItemCreatedFunction: function (event) {
596 // const item = event.item
597 // item.panel = {
598 // content: 'legend',
599 // open: false
600 // }
601 // }
602 // })
603
604
605 view.popup.dockEnabled = true;
606 view.popup.dockOptions.position = 'bottom-left';
607 //var layers = React.Children.toArray(this.props.children).filter((ele) => ele.type.name === "ArcticMapLayer");
608
609
610 // console.log(layers);
611 view.popup.watch("visible", function (visible) {
612
613 if (!visible) {
614 view.graphics.removeAll();
615 }
616 });
617
618 view.popup.watch('selectedFeature', function (graphic) {
619 view.graphics.removeAll();
620 if (graphic) {
621 var graphicTemplate = graphic.getEffectivePopupTemplate();
622 graphicTemplate.actions = [{
623 id: 'select-item',
624 title: 'Select',
625 image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyhpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMDE0IDc5LjE1Njc5NywgMjAxNC8wOC8yMC0wOTo1MzowMiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTQgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NTQyREM3RDkwQzVGMTFFNTk4QkI4OTBEOTYzQTg5MzEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTQyREM3REEwQzVGMTFFNTk4QkI4OTBEOTYzQTg5MzEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo1NDJEQzdENzBDNUYxMUU1OThCQjg5MEQ5NjNBODkzMSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo1NDJEQzdEODBDNUYxMUU1OThCQjg5MEQ5NjNBODkzMSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Prb3PqgAAACTSURBVHjaYvz//z8DJYCJgVJAjgsiIyMFQBjEZgQZwMjISJJmILUXynVmIdVmqGZ9qFAe0S7AonnR8uXLk5jItBmsGSUWgIriSdUMNwCoaB6QmgulidaM7AKYgjiYIcRohkdjVFQUhmIoG69mlHSAxUYGQppRAhGo6AMoYQDxRWI1Y02JSC65SEgz3IABzY0AAQYAhIhWWCl3Pj0AAAAASUVORK5CYII="
626
627 }];
628
629 graphicTemplate.actions.items[0].visible = self.state.map.editor !== undefined; // graphic.attributes.website ? true : false;
630 reactArcgis.loadModules(['esri/symbols/SimpleFillSymbol']).then(function (_ref3) {
631 var _ref4 = slicedToArray(_ref3, 1),
632 SimpleFillSymbol = _ref4[0];
633
634 var symbol = new SimpleFillSymbol({
635 color: [135, 206, 235, 0.5],
636 style: "solid",
637 outline: {
638 color: [0, 191, 255],
639 width: 1
640 }
641 });
642 if (graphic) {
643 graphic.symbol = symbol;
644 var popupGraphic = graphic;
645 view.graphics.add(popupGraphic);
646 } else {
647 view.graphics.removeAll();
648 view.popup.content.graphic = null;
649 }
650 });
651 //self.state.view.goTo(graphic);
652 }
653 });
654 view.popup.viewModel.on('trigger-action', function (event) {
655 //var target = event.target || window.event.target || window.event.srcElement;
656 if (event.action.id === 'select-item') {
657 self.state.map.editor.setEditFeature(view.popup.selectedFeature, null, null, false, true);
658 view.popup.close();
659 }
660 });
661
662 window.addEventListener("keydown", function (event) {
663 if (event.which == "17") self.cntrlIsPressed = true;
664 });
665
666 window.addEventListener("contextmenu", function (event) {
667 self.contextmenuPressed = true;
668 });
669
670 window.addEventListener("keyup", function (event) {
671 self.cntrlIsPressed = false;
672 });
673
674 view.on('click', function (event) {
675 if (event.button == 0) {
676 self.contextmenuPressed = false;
677 }
678
679 //console.log(event);
680
681 //hide stuff
682
683
684 if (self.state.hideBasemapButton && self.state.hideBasemapButton === true) {
685 self.state.view.ui.remove(self.basemapGallery);
686 self.setState({ hideBasemapButton: false });
687 return;
688 }
689
690 if (self.state.mode === "view") {
691 return;
692 }
693
694 if (event.button == 0) {
695 if (self.state.map.editor && self.state.map.editor.state.editing === true) {
696 return;
697 }
698 }
699
700 var currentmode = self.state.mode;
701 if (currentmode !== 'select') {
702 self.setMode("view");
703 }
704
705 // console.log(event);
706 // need to work on identify and add to a single popup
707 // https://developers.arcgis.com/javascript/latest/sample-code/sandbox/index.html?sample=tasks-identify
708
709 var identresults = [];
710 //document.getElementsByClassName('esri-view-root')[0].style.cursor = 'wait';
711 self.setState({ loading: true });
712
713 var identLayers = self.layers.filter(function (layer) {
714 var mapzoom = view.zoom;
715
716 if (layer.props.identMaxZoom !== undefined) {
717 if (Number.parseInt(layer.props.identMaxZoom, 10) > mapzoom) {
718 return layer;
719 } else {
720 return;
721 }
722 }
723
724 return layer;
725 });
726
727 identLayers = identLayers.concat(self.state.map.amlayers);
728
729 async__default.eachSeries(identLayers, function (layer, cb) {
730 if (!layer.state.disablePopup) {
731 layer.identify(event, function (results) {
732 if (results) {
733 results.layer = layer;
734 identresults.push(results);
735 }
736 cb();
737 });
738 }
739 }, function (err) {
740 var results = identresults.map(function (ir) {
741 ir.results.forEach(function (res) {
742 res.layer = ir.layer;
743 res.acres = -1;
744 if (res.feature.geometry) {
745 res.acres = geometryEngine.geodesicArea(res.feature.geometry, 'acres');
746 }
747 });
748 return ir.results;
749 }) || [].reduce(function (a, b) {
750 return a.concat(b);
751 });
752 self.setState({ loading: false });
753
754 results = results.flat();
755
756 results = results.sort(function (r1, r2) {
757 if (r1.acres > r2.acres) {
758 return 1;
759 }
760 return -1;
761 //r.feature.attributes.Shape_Area
762 });
763
764 if (currentmode === "identify") {
765
766 //results = results.reverse();
767 var popupresults = results.map(function (result) {
768 var feature = result.feature;
769 var layerName = result.layerName;
770
771 feature.attributes.layerName = layerName;
772
773 if (result.layer.layerRenderers) {
774 //console.log("result.layer this.layerRenderers", result);
775 var popupDisable = result.layer.layerRenderers.find(function (l) {
776 return l.props.layerid === result.layerId.toString();
777 });
778 //console.log("result.layer popupDisable", popupDisable.props);
779 if (popupDisable && result.layerId == popupDisable.props.layerid) {
780 //console.log("result.layer popupDisable", popupDisable.props);
781 if (popupDisable.props.disabled == "true") {
782 return null;
783 }
784 }
785 }
786 feature.popupTemplate = { // autocasts as new PopupTemplate()
787 //title: layerName,
788 title: result.layer.renderPopupTitle(feature, result),
789 content: result.layer.renderPopup(feature, result),
790 actions: [{ title: "Select", id: "select-action" }]
791 };
792
793 return feature;
794 });
795
796 // remove the disabled popup layer
797 popupresults.forEach(function (result) {
798 if (result == null) {
799 popupresults.pop();
800 }
801 });
802
803 if (popupresults.length > 0) {
804 view.popup.close();
805 view.popup.currentSearchResultFeature = null;
806 self.state.view.popup.open({
807 features: popupresults,
808 location: event.mapPoint
809 });
810 // popupresults[0].setCurrentPopup();
811
812 self.state.view.popup.on('trigger-action', function (e) {
813 if (e.action.id === 'select-action') ;
814 });
815 }
816 self.setState({ loading: false });
817 }
818
819 if (currentmode === "select") {
820 if (self.contextmenuPressed === true) {
821
822 self.state.map.editor.setEditFeature(results[0].feature, null, null, false, true, true);
823 } else {
824
825 self.state.map.editor.setEditFeature(results[0].feature, null, null, false, true);
826 }
827 }
828
829 //document.getElementsByClassName('esri-view-root')[0].style.cursor = 'auto';
830 });
831
832 // self.layers.forEach(layer => {
833 // layer.identify(event);
834 // })
835 //}, 100);
836 });
837
838 // Add widget to the top right corner of the view
839 // self.state.view.ui.add(layerList, 'top-left')
840
841
842 if (_this2.props.locate) {
843 var locateBtn = new Locate({
844 view: self.state.view
845 });
846
847 self.state.view.ui.add(locateBtn, {
848 position: 'top-right'
849 });
850 }
851
852 _this2.basemapGallery = new BasemapGallery({
853 view: self.state.view
854 });
855
856 _this2.basemapGallery.watch('activeBasemap', function (newValue, oldValue, property, object) {
857 self.state.view.ui.remove(self.basemapGallery);
858 self.setState({ hideBasemapButton: false });
859 });
860
861 map.on("basemap-change", function (a) {
862 //this.basemapGallery.on('click', function () {
863
864 alert("BM CHanegd");
865 });
866
867 // Add the widget to the top-right corner of the view
868
869 if (_this2.props.home) {
870 var homeBtn = new Home({
871 view: view
872 });
873
874 // Add the home button to the top left corner of the view
875 view.ui.add(homeBtn, 'top-right');
876 }
877
878 view.ui.remove('zoom');
879
880 _this2.getEditFeature = function () {
881 _this2.state.map.editor.state.tempGraphicsLayer.graphics.items[0];
882 };
883
884 setTimeout(function () {
885 var evt = new Event('mapready', { bubbles: true });
886 Object.defineProperty(evt, 'target', { value: self, enumerable: true });
887
888 if (self.props.onmapready) {
889 self.props.onmapready(evt);
890 }
891 }, 500);
892 });
893 }
894 }]);
895 return ArcticMap;
896}(React.Component);
897
898ArcticMap.displayName = 'ArcticMap';
899
900var ArcticMapLayer = function (_React$Component) {
901 inherits(ArcticMapLayer, _React$Component);
902
903 function ArcticMapLayer(props) {
904 classCallCheck(this, ArcticMapLayer);
905
906 var _this = possibleConstructorReturn(this, (ArcticMapLayer.__proto__ || Object.getPrototypeOf(ArcticMapLayer)).call(this, props));
907
908 _this.state = {
909 map: props.map,
910 view: props.view,
911 graphic: null,
912 title: props.title,
913 blockSelect: props.blockIdentSelect !== undefined,
914 disablePopup: props.disablePopup !== undefined
915 };
916 return _this;
917 }
918
919 createClass(ArcticMapLayer, [{
920 key: 'componentWillUnmount',
921 value: function componentWillUnmount() {
922 this.props.view.graphics.remove(this.state.graphic);
923 }
924 }, {
925 key: 'componentDidMount',
926 value: function componentDidMount() {
927 var _this2 = this;
928
929 var self = this;
930 reactArcgis.loadModules(['esri/Graphic', "esri/layers/FeatureLayer", "esri/layers/MapImageLayer", "esri/layers/ImageryLayer", "esri/layers/GraphicsLayer", "esri/tasks/IdentifyTask", "esri/tasks/support/IdentifyParameters", "esri/geometry/Point", "esri/symbols/SimpleMarkerSymbol", "esri/layers/GroupLayer", "esri/renderers/Renderer"]).then(function (_ref) {
931 var _ref2 = slicedToArray(_ref, 11),
932 Graphic = _ref2[0],
933 FeatureLayer = _ref2[1],
934 MapImageLayer = _ref2[2],
935 ImageryLayer = _ref2[3],
936 GraphicsLayer = _ref2[4],
937 IdentifyTask = _ref2[5],
938 IdentifyParameters = _ref2[6],
939 Point = _ref2[7],
940 SimpleMarkerSymbol = _ref2[8],
941 GroupLayer = _ref2[9],
942 Renderer = _ref2[10];
943
944 // Create a polygon geometry
945
946
947 var children = React.Children.map(_this2.props.children, function (child) {
948 if (child.type.displayName === 'ArcticMapLayerPopup') {
949 return child;
950 // return React.cloneElement(child, {
951 // // ref: 'editor'
952 // })
953 }
954 });
955
956 self.layerRenderers = children;
957
958 var childrenEles = [];
959 if (self.props.children) {
960 if (Array.isArray(self.props.children)) {
961 childrenEles = self.props.children;
962 } else {
963 childrenEles.push(self.props.children);
964 }
965 }
966
967 var renderers = childrenEles.filter(function (child) {
968 if (child.type.displayName === 'ArcticMapLayerRenderer') {
969 return child;
970 }
971 });
972
973 // this.setState({ graphic });
974
975 if (self.props.type === "feature") {
976
977 var featureLayer = new FeatureLayer({
978 url: self.props.src,
979 outFields: ["*"]
980 });
981 self.layerRef = featureLayer;
982 self.state.map.add(featureLayer);
983 }
984
985 if (self.props.type === "group") {
986 var gtrans = 1;
987 if (self.props.transparency) {
988 gtrans = Number.parseFloat(self.props.transparency);
989 }
990 var srcsplit = self.props.src.split(',');
991
992 var gmaplayer = new GroupLayer({
993 //url: self.props.src,
994 opacity: gtrans
995
996 });
997 if (self.props.title) {
998
999 gmaplayer.title = self.props.title;
1000 }
1001
1002 var idx = 0;
1003 srcsplit.forEach(function (src) {
1004 var glayer = new MapImageLayer({
1005 url: src,
1006 opacity: gtrans
1007
1008 });
1009
1010 if (self.props.sublayers && self.props.sublayers.length > idx) {
1011 glayer.sublayers = self.props.sublayers[idx];
1012 idx++;
1013 }
1014
1015 gmaplayer.layers.add(glayer);
1016
1017 glayer.when(function () {
1018
1019 var layerids = [];
1020
1021 //console.log("Maplayer: ", maplayer);
1022 glayer.allSublayers.items.forEach(function (sublayer) {
1023 layerids.push(sublayer.id);
1024 //console.log("Sublayer:", sublayer);
1025
1026 var renderer = renderers.find(function (r) {
1027 if (r.props.layer === sublayer.title || r.props.layer === '' + sublayer.id) {
1028 return r;
1029 }
1030 });
1031 if (renderer !== undefined) {
1032 //console.log("Sublayer renderer:", renderer.props.style);
1033 sublayer.renderer = renderer.props.style;
1034 }
1035 //sublayer.renderer = Renderer.fromJSON(renderer);
1036 });
1037 layerids.reverse();
1038
1039 self.identifyTask = new IdentifyTask(self.props.src);
1040 self.params = new IdentifyParameters();
1041 self.params.tolerance = 3;
1042 self.params.layerIds = layerids;
1043 self.params.layerOption = "visible";
1044 self.params.width = self.state.view.width;
1045 self.params.height = self.state.view.height;
1046 self.params.returnGeometry = true;
1047 self.params.returnGeometry = self.state.blockSelect;
1048
1049 // console.log(self.params);
1050 });
1051 });
1052
1053 self.layerRef = gmaplayer;
1054 self.state.map.add(gmaplayer);
1055 }
1056
1057 if (self.props.type === "dynamic") {
1058
1059 var trans = 1;
1060 if (self.props.transparency) {
1061 trans = Number.parseFloat(self.props.transparency);
1062 }
1063
1064 var maplayer = new MapImageLayer({
1065 url: self.props.src,
1066 opacity: trans
1067 //sublayers: []
1068
1069 });
1070
1071 if (self.props.sublayers) {
1072 maplayer.sublayers = self.props.sublayers;
1073 }
1074
1075 if (self.props.childsrc) ;
1076
1077 if (self.props.title) {
1078
1079 maplayer.title = self.props.title;
1080 }
1081
1082 maplayer.on("layerview-create", function (event) {
1083 // console.lof("Layerview:" , event)
1084 });
1085
1086 maplayer.when(function () {
1087
1088 var layerids = [];
1089 //console.log("Maplayer: ", maplayer);
1090 maplayer.allSublayers.items.forEach(function (sublayer) {
1091 layerids.push(sublayer.id);
1092 //console.log("Sublayer:", sublayer);
1093
1094 var renderer = renderers.find(function (r) {
1095 if (r.props.layer === sublayer.title || r.props.layer === '' + sublayer.id) {
1096 return r;
1097 }
1098 });
1099 if (renderer !== undefined) {
1100 //console.log("Sublayer renderer:", renderer.props.style);
1101 sublayer.renderer = renderer.props.style;
1102 }
1103 //sublayer.renderer = Renderer.fromJSON(renderer);
1104 });
1105 layerids.reverse();
1106
1107 self.identifyTask = new IdentifyTask(self.props.src);
1108 self.params = new IdentifyParameters();
1109 self.params.tolerance = 3;
1110 self.params.layerIds = layerids;
1111 self.params.layerOption = "visible";
1112 self.params.width = self.state.view.width;
1113 self.params.height = self.state.view.height;
1114 self.params.returnGeometry = true;
1115 self.params.returnGeometry = self.state.blockSelect;
1116
1117 // console.log(self.params);
1118 });
1119
1120 self.layerRef = maplayer;
1121 self.state.map.add(maplayer);
1122 }
1123
1124 if (self.props.type === "image") {
1125
1126 var imagelayer = new ImageryLayer({
1127 url: self.props.src,
1128 format: "jpgpng" // server exports in either jpg or png format
1129 });
1130 self.layerRef = imagelayer;
1131 self.state.map.add(imagelayer);
1132 }
1133
1134 // if (self.props.type === "geojson") {
1135
1136 // var geojsonLayer = new GraphicsLayer({ title: 'GeoJSON Layer', listMode: "hide" });
1137 // // var geojsonLayer = new GeoJSONLayer({
1138 // // //source: self.props.src,
1139 // // //copyright: "USGS Earthquakes",
1140 // // //popupTemplate: template
1141 // // });
1142 // var dataarr = [];
1143
1144 // if (typeof self.props.src === 'object') {
1145 // if (self.props.src.features) {
1146 // dataarr = self.props.src.features;
1147 // }
1148 // else {
1149 // dataarr = self.props.src;
1150 // }
1151 // }
1152
1153 // if (self.props.title) {
1154
1155 // geojsonLayer.title = self.props.title;
1156 // }
1157
1158
1159 // dataarr.forEach(obj => {
1160 // //var esrijson = geojsonToArcGIS(obj);
1161 // if (obj.geometry.type === "Point") {
1162
1163 // var popupTemplate = {
1164 // title: "{Name}",
1165 // content: self.props.template,
1166 // };
1167
1168
1169 // var point = new Point({
1170 // longitude: obj.geometry.coordinates[1],
1171 // latitude: obj.geometry.coordinates[0],
1172
1173 // });
1174
1175 // // Create a symbol for drawing the point
1176 // var markerSymbol = new SimpleMarkerSymbol({
1177 // color: [226, 119, 40],
1178 // outline: {
1179 // color: [255, 255, 255],
1180 // width: 1
1181 // }
1182 // });
1183
1184 // // Create a graphic and add the geometry and symbol to it
1185 // var pointGraphic = new Graphic({
1186 // geometry: point,
1187 // symbol: markerSymbol,
1188 // attributes: obj.properties,
1189 // popupTemplate: popupTemplate,
1190 // // extent : new Extent().centerAt(point)
1191 // });
1192
1193 // // Add the graphic to the view
1194 // geojsonLayer.graphics.add(pointGraphic);
1195 // }
1196
1197
1198 // })
1199
1200
1201 // self.layerRef = geojsonLayer;
1202 // self.state.map.add(geojsonLayer);
1203 // // var imagelayer = new ImageryLayer({
1204 // // url: self.props.src,
1205 // // format: "jpgpng" // server exports in either jpg or png format
1206 // // });
1207 // // self.layerRef = imagelayer;
1208 // // self.state.map.add(imagelayer);
1209
1210 // }
1211
1212
1213 self.layerRef.when(function () {
1214 setTimeout(function () {
1215 var evt = new Event('ready', { bubbles: true });
1216 Object.defineProperty(evt, 'target', { value: self, enumerable: true });
1217
1218 if (self.props.onready) {
1219 self.props.onready(evt);
1220 }
1221 }, 500);
1222 });
1223
1224 //this.state.view.graphics.add(graphic);
1225 }); //.catch ((err) => console.error(err));
1226 }
1227 }, {
1228 key: 'zoomto',
1229 value: function zoomto() {
1230 if (this.layerRef.graphics) {
1231 this.state.view.goTo(this.layerRef.graphics.items);
1232 }
1233 }
1234 }, {
1235 key: 'renderPopupTitle',
1236 value: function renderPopupTitle(feature, result) {
1237 if (result.layerId !== undefined && this.layerRenderers) {
1238 var popupTitle = this.layerRenderers.find(function (l) {
1239 return l.props.layerid === result.layerId.toString();
1240 });
1241 if (popupTitle && result.layerId == popupTitle.props.layerid) {
1242 return popupTitle.props.popuptitle;
1243 } else {
1244 return result.layerName;
1245 }
1246 } else {
1247 return result.layerName;
1248 }
1249 }
1250 }, {
1251 key: 'renderPopup',
1252 value: function renderPopup(feature, result) {
1253
1254 if (result.layerId !== undefined && this.layerRenderers) {
1255 var popuprender = this.layerRenderers.find(function (l) {
1256 return l.props.layerid === result.layerId.toString();
1257 });
1258 if (popuprender && popuprender.props.popup !== undefined) {
1259 var ele = popuprender.props.popup(feature, result);
1260
1261 if (ele) {
1262 var workingdiv = document.createElement('div');
1263 ReactDOM.render(ele, workingdiv);
1264 return workingdiv;
1265 }
1266 }
1267 }
1268
1269 var popupText = "";
1270 var atts = Object.getOwnPropertyNames(feature.attributes);
1271 atts.forEach(function (att) {
1272 if (att === 'layerName') ; else {
1273 popupText += '<b>' + att + '</b> : ' + feature.attributes[att] + '<br/>';
1274 }
1275 });
1276
1277 return popupText;
1278 }
1279 }, {
1280 key: 'render',
1281 value: function render() {
1282 return null;
1283 }
1284 }, {
1285 key: 'identify',
1286 value: function identify(event, callback) {
1287
1288 var self = this;
1289 if (this.props.type === "geojson") {
1290
1291 this.state.view.hitTest(event).then(function (htresponse) {
1292
1293 // console.log("Identify on geojson");
1294 //console.log(htresponse);
1295 var mapPoint = event.mapPoint;
1296 var response = {
1297 layer: self.layerRef,
1298 results: htresponse.results.map(function (r) {
1299 return { feature: r.graphic, layerName: self.layerRef.title };
1300 })
1301 };
1302 callback(response);
1303 });
1304 } else {
1305
1306 if (!this.params) {
1307 callback(null);return;
1308 }
1309
1310 this.params.geometry = event.mapPoint;
1311 this.params.mapExtent = this.state.view.extent;
1312 this.params.returnGeometry = true;
1313 //document.getElementById("viewDiv").style.cursor = "wait";
1314 this.identifyTask.execute(this.params).then(function (response) {
1315
1316 callback(response);
1317 });
1318 }
1319 }
1320 }]);
1321 return ArcticMapLayer;
1322}(React.Component);
1323
1324ArcticMapLayer.displayName = "ArcticMapLayer";
1325
1326var css$1 = "\n#ArcticMapEdit_topbar__1GWR4 {\n background: #fff;\n \n \n padding: 2px;\n }\n\n .ArcticMapEdit_action-button__2EIsV {\n display: block;\n font-size: 16px;\n background-color: transparent;\n border: 1px solid #D3D3D3;\n color: #6e6e6e;\n height: 40px;\n width: 125px;\n text-align: center;\n box-shadow: 0 0 1px rgba(0, 0, 0, 0.3);\n padding: 2px;\n }\n\n .ArcticMapEdit_action-button__2EIsV:hover,\n .ArcticMapEdit_action-button__2EIsV:focus {\n background: #0079c1;\n color: #e4e4e4;\n }\n\n .ArcticMapEdit_active__rGKFh {\n background: #0079c1;\n color: #e4e4e4;\n }\n\n .ArcticMapEdit_infoarea__2vzls {\n width: 300px;\n word-wrap: break-word;\n margin: 0px;\n }\n\n .ArcticMapEdit_hide_input__1Pm3t {\n width:0px;\n }\n /* .btm_primary_file {\n background-color: #005a70;\n padding: 7px;\n border: 1px solid #D3D3D3;\n color: #D3D3D3;\n height: 40px;\n width: 125px;\n text-align: center;\n box-shadow: 0 0 1px rgba(0, 0, 0, 0.3);\n border-radius: 5px;\n } */\n .ArcticMapEdit_btm_primary_file__1ypOM {\n background-color: #005a70;\n padding: 5px 10px 5px 10px;\n border-width: 1px;\n border-style: solid;\n border-color: #dadbdd;\n color: #e0ebeb;\n \n width: 125px;\n border-radius: 5px;\n\n fill-opacity: 100;\n margin-bottom: 5px;\n margin-top: 10px;\n font: 400 13.3333px Arial;\n }\n input[type=\"file\"]\n {\n display: none;\n }\n .ArcticMapEdit_fileUpload__r84Hl .ArcticMapEdit_upload__3WWMG \n {\n display: inline-block;\n background-color: #005a70;\n color: #e0ebeb;\n }";
1327var style$2 = { "topbar": "ArcticMapEdit_topbar__1GWR4", "action-button": "ArcticMapEdit_action-button__2EIsV", "active": "ArcticMapEdit_active__rGKFh", "infoarea": "ArcticMapEdit_infoarea__2vzls", "hide_input": "ArcticMapEdit_hide_input__1Pm3t", "btm_primary_file": "ArcticMapEdit_btm_primary_file__1ypOM", "fileUpload": "ArcticMapEdit_fileUpload__r84Hl", "upload": "ArcticMapEdit_upload__3WWMG" };
1328styleInject(css$1);
1329
1330var ArcticMapEdit = function (_React$Component) {
1331 inherits(ArcticMapEdit, _React$Component);
1332
1333 function ArcticMapEdit(props) {
1334 classCallCheck(this, ArcticMapEdit);
1335
1336 var _this = possibleConstructorReturn(this, (ArcticMapEdit.__proto__ || Object.getPrototypeOf(ArcticMapEdit)).call(this, props));
1337
1338 props.map.editor = _this;
1339 _this.state = {
1340 map: props.map,
1341 view: props.view,
1342 graphic: null,
1343 hideEditors: false,
1344 editing: false,
1345 showUploading: false,
1346 hidden: !_this.props.hidden ? false : true
1347 };
1348
1349 _this.uploadPanel = React.createRef();
1350 return _this;
1351 }
1352
1353 createClass(ArcticMapEdit, [{
1354 key: "componentWillUnmount",
1355 value: function componentWillUnmount() {
1356 this.props.view.graphics.remove(this.state.graphic);
1357 }
1358 }, {
1359 key: "componentDidMount",
1360 value: function componentDidMount() {
1361 var _this2 = this;
1362
1363 var self = this;
1364 reactArcgis.loadModules(["esri/Graphic", "esri/layers/GraphicsLayer", "esri/widgets/Sketch/SketchViewModel", "esri/geometry/Geometry", "esri/geometry/Polygon", "esri/geometry/geometryEngine"]).then(function (_ref) {
1365 var _ref2 = slicedToArray(_ref, 6),
1366 Graphic = _ref2[0],
1367 GraphicsLayer = _ref2[1],
1368 SketchViewModel = _ref2[2],
1369 Geometry = _ref2[3],
1370 Polygon = _ref2[4],
1371 geometryEngine = _ref2[5];
1372
1373 var tempGraphicsLayer = new GraphicsLayer({ title: 'Edit Layer', listMode: "hide" });
1374 self.setState({ tempGraphicsLayer: tempGraphicsLayer });
1375
1376 self.state.map.add(tempGraphicsLayer);
1377
1378 var sketchViewModel = new SketchViewModel({
1379 view: self.state.view,
1380 layer: tempGraphicsLayer,
1381 defaultUpdateOptions: {
1382 // toggleToolOnClick : false
1383 },
1384 pointSymbol: {
1385 type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
1386 style: "circle",
1387 color: "yellow",
1388 size: "3px",
1389 outline: { // autocasts as new SimpleLineSymbol()
1390 color: [255, 255, 255],
1391 width: 3
1392 }
1393 },
1394 polylineSymbol: {
1395 type: "simple-line", // autocasts as new SimpleLineSymbol()
1396 color: "yellow",
1397 width: "3",
1398 style: "solid"
1399 },
1400 polygonSymbol: {
1401 type: "simple-fill", // autocasts as new SimpleFillSymbol()
1402 color: "rgba(224, 206, 69, 0.8)",
1403 style: "solid",
1404 outline: {
1405 color: "yellow",
1406 width: 3
1407 }
1408 }
1409 });
1410
1411 self.setState({ tempGraphicsLayer: tempGraphicsLayer, sketchViewModel: sketchViewModel });
1412
1413 self.setUpClickHandler.bind(_this2);
1414
1415 sketchViewModel.on("create", function (event) {
1416
1417 if (event.state === 'complete') {
1418
1419 tempGraphicsLayer.graphics = [event.graphic];
1420 if (_this2.props.single) {
1421
1422 _this2.setState({ hideEditors: true });
1423 }
1424
1425 setTimeout(function () {
1426
1427 self.setState({ geojson: arcgisToGeojsonUtils.arcgisToGeoJSON(event.graphic.geometry.toJSON()), datajson: event.graphic.toJSON(), editing: false });
1428 self.firenewfeature();
1429 }, 1000);
1430 }
1431 });
1432
1433 sketchViewModel.on("update", function (event) {
1434 self.setState({ editing: true });
1435 if (event.state === 'start' && self.state.mode === 'select') {
1436 return false;
1437 }
1438 if (event.state === 'complete' || event.state === 'cancel') {
1439 // const graphic = new Graphic({
1440 // geometry: event.graphic.geometry,
1441 // symbol: event.graphic.symbol
1442 // });
1443 //tempGraphicsLayer.add(event.graphic);
1444 // if (this.props.single) {
1445 // console.log("Added one feature");
1446 // this.setState({ hideEditors: true });
1447 // }
1448
1449 setTimeout(function () {
1450 self.setState({ geojson: arcgisToGeojsonUtils.arcgisToGeoJSON(event.graphics[0].geometry.toJSON()), datajson: event.graphics[0].toJSON() });
1451 //this.geojson = event.geometry;
1452 self.firenewfeature();
1453 }, 1000);
1454 }
1455 });
1456
1457 // Listen the sketchViewModel's update-complete and update-cancel events
1458 sketchViewModel.on("update-complete", function (event) {
1459 event.graphic.geometry = event.geometry;
1460 tempGraphicsLayer.graphics = [event.graphic];
1461 //tempGraphicsLayer.add(event.graphic);
1462
1463 // set the editGraphic to null update is complete or cancelled.
1464 self.state.editGraphic = null;
1465 });
1466
1467 _this2.top_right_node = document.createElement("div");
1468 self.state.view.ui.add(_this2.top_right_node, "top-right");
1469
1470 self.setState({ loaded: true });
1471
1472 //self.setUpClickHandler();
1473
1474
1475 // scoped methods
1476 self.setEditFeature = function (feature, nofire, type, zoomto, addto, trim) {
1477
1478 if (nofire === null) {
1479 nofire = false;
1480 }
1481
1482 if (type === null) {
1483 type = "polygon";
1484 }
1485
1486 if (zoomto === null) {
1487 zoomto = true;
1488 }
1489
1490 if (addto === null) {
1491 addto = false;
1492 }
1493 if (trim === null) {
1494 trim = false;
1495 }
1496
1497 if (feature.attributes.layerName) {
1498 feature.sourceLayer = feature.attributes.layerName.trim();
1499 } else {
1500 feature.sourceLayer = 'PLSS';
1501 }
1502
1503 if (!feature.geometry.type) {
1504 if (type === "polygon") {
1505
1506 feature.geometry = new Polygon(feature.geometry);
1507 feature.geometry.type = "polygon";
1508 }
1509 }
1510
1511 _this2.state.sketchViewModel.cancel();
1512 if (!addto) {
1513 _this2.state.tempGraphicsLayer.removeAll();
1514 }
1515 _this2.setState({ hideEditors: false, geojson: null });
1516
1517 var graphic = null;
1518 if (!feature.geometry.toJSON && feature.symbol) {
1519 graphic = Graphic.fromJSON(feature);
1520 } else {
1521
1522 graphic = new Graphic({
1523 geometry: feature.geometry,
1524 symbol: _this2.state.sketchViewModel.polygonSymbol
1525 });
1526 }
1527
1528 if (graphic.geometry === null) {
1529 graphic.geometry = feature.geometry;
1530 }
1531
1532 if (trim) {
1533 if (_this2.state.tempGraphicsLayer.graphics.items.length > 0) {
1534
1535 var geometrys = _this2.state.tempGraphicsLayer.graphics.items.map(function (i) {
1536 return i.geometry;
1537 });
1538
1539 var merge = geometryEngine.union(geometrys);
1540 var isEqual = geometryEngine.equals(merge, graphic.geometry);
1541 if (!isEqual) {
1542 merge = geometryEngine.difference(merge, graphic.geometry);
1543 graphic = new Graphic({
1544 geometry: merge,
1545 symbol: _this2.state.sketchViewModel.polygonSymbol
1546 });
1547 graphic.geometry.sourceLayer = feature.sourceLayer;
1548 _this2.state.tempGraphicsLayer.graphics = [graphic];
1549 } else {
1550 _this2.state.tempGraphicsLayer.graphics = null;
1551 }
1552 }
1553 } else {
1554 _this2.state.tempGraphicsLayer.add(graphic);
1555
1556 if (_this2.state.tempGraphicsLayer.graphics.items.length > 0) {
1557
1558 var geometrys = _this2.state.tempGraphicsLayer.graphics.items.map(function (i) {
1559 return i.geometry;
1560 });
1561
1562 var merge = geometryEngine.union(geometrys);
1563
1564 graphic = new Graphic({
1565 geometry: merge,
1566 symbol: _this2.state.sketchViewModel.polygonSymbol
1567 });
1568 graphic.geometry.sourceLayer = feature.sourceLayer;
1569 _this2.state.tempGraphicsLayer.graphics = [graphic];
1570 }
1571 }
1572 //this.state.tempGraphicsLayer.graphics = [graphic];
1573 if (_this2.props.single) {
1574
1575 _this2.setState({ hideEditors: true });
1576 }
1577
1578 if (zoomto) {
1579
1580 self.state.view.goTo(graphic);
1581 }
1582
1583 var geometry = feature.geometry;
1584 if (geometry && !geometry.toJSON) {
1585 geometry = Geometry.fromJSON(geometry);
1586 }
1587
1588 _this2.setState({ geojson: arcgisToGeojsonUtils.arcgisToGeoJSON(geometry.toJSON()), datajson: graphic.toJSON() });
1589
1590 if (nofire === true) ; else {
1591 self.firenewfeature();
1592 }
1593 };
1594
1595 self.setEditFeature = self.setEditFeature.bind(self);
1596
1597 self.setGeoJson = function (geojson) {
1598 //var esrijson = geojsonToArcGIS(geojson);
1599
1600
1601 };
1602 self.setGeoJson = self.setGeoJson.bind(self);
1603 }); //.catch ((err) => console.error(err));
1604
1605 }
1606 }, {
1607 key: "firenewfeature",
1608 value: function firenewfeature() {
1609 var self = this;
1610 var evt = new Event('newfeature', { bubbles: true });
1611 Object.defineProperty(evt, 'target', { value: this, enumerable: true });
1612 evt.data = self.state.datajson;
1613
1614 if (self.props.onnewfeature) {
1615 self.props.onnewfeature(evt);
1616 }
1617
1618 setTimeout(function () {
1619 self.setState({ editing: false });
1620 }, 200);
1621 }
1622 }, {
1623 key: "addPointClick",
1624 value: function addPointClick() {
1625 this.state.sketchViewModel.create("point", { mode: "click" });
1626 this.setState({ editing: true });
1627 }
1628 }, {
1629 key: "addLineClick",
1630 value: function addLineClick() {
1631 this.state.sketchViewModel.create("polyline", { mode: "click" });
1632 this.setState({ editing: true });
1633 }
1634 }, {
1635 key: "addPolyClick",
1636 value: function addPolyClick() {
1637 this.state.sketchViewModel.create("polygon", { mode: "click" });
1638 this.setState({ editing: true });
1639 }
1640 }, {
1641 key: "addRecClick",
1642 value: function addRecClick() {
1643 this.state.sketchViewModel.create("rectangle", { mode: "click" });
1644 this.setState({ editing: true });
1645 }
1646 }, {
1647 key: "addCircleClick",
1648 value: function addCircleClick() {
1649 this.state.sketchViewModel.create("circle", { mode: "click" });
1650 this.setState({ editing: true });
1651 }
1652 }, {
1653 key: "fileUploaded",
1654 value: function fileUploaded(evt) {
1655 var self = this;
1656 var fileName = evt.target.value.toLowerCase();
1657 if (fileName.indexOf(".zip") !== -1) {
1658 // console.log("addEventListener", self);
1659 self.processShapeFile(fileName, evt.target);
1660 } else if (fileName.indexOf(".kml") !== -1) {
1661 // console.log("addEventListener", self);
1662 self.processKMLFile(fileName, evt.target);
1663 } else if (fileName.indexOf(".geojson") !== -1) {
1664 // console.log("addEventListener", self);
1665
1666 self.processGeojsonFile(fileName, evt.target);
1667 } else if (fileName.indexOf(".gml") !== -1) {
1668 // console.log("addEventListener", self);
1669
1670 self.processGMLFile(fileName, evt.target);
1671 } else if (fileName.indexOf(".gpx") !== -1) {
1672 // console.log("addEventListener", self);
1673
1674 self.processGPXFile(fileName, evt.target);
1675 } else {
1676 document.getElementById("upload-status").innerHTML = '<p style="color:red">Only shapefile(.zip), .gml, .gpx, .kml, or .geojson are supported</p>';
1677 }
1678 }
1679 }, {
1680 key: "readTextFile",
1681 value: function readTextFile(file) {
1682 return new Promise(function (res, rej) {
1683 var fr = new FileReader();
1684 fr.onload = function (evt) {
1685 res(evt.target.result);
1686 };
1687 fr.readAsText(file);
1688 });
1689 }
1690 }, {
1691 key: "kmlColor",
1692 value: function kmlColor(v) {
1693 var color, opacity;
1694 v = v || '';
1695 if (v.substr(0, 1) === '#') {
1696 v = v.substr(1);
1697 }
1698 if (v.length === 6 || v.length === 3) {
1699 color = v;
1700 }
1701 if (v.length === 8) {
1702 opacity = parseInt(v.substr(0, 2), 16) / 255;
1703 color = '#' + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
1704 }
1705 return [color, isNaN(opacity) ? undefined : opacity];
1706 }
1707 }, {
1708 key: "processGPXFile",
1709 value: function processGPXFile(fileName, form) {
1710 var file = fileName.replace(/^.*[\\\/]/, '');
1711 var self = this;
1712 this.readTextFile(form.files[0]).then(function (text) {
1713 var parser = new DOMParser();
1714 var gj = self.fc();
1715 var xmlDoc = parser.parseFromString(text, "text/xml");
1716 var trkMember = self.get(xmlDoc, "trk");
1717 for (var j = 0; j < trkMember.length; j++) {
1718 gj.features = gj.features.concat(self.getTRKMember(trkMember[j]));
1719 }
1720 var features = [];
1721 gj.features.forEach(function (f) {
1722 var esrijson = arcgisToGeojsonUtils.geojsonToArcGIS(f);
1723 features.push(esrijson);
1724 });
1725 self.addGeojsonToMap(features, file, "GPX");
1726 self.uploadPanel.current.toggle();
1727 });
1728 }
1729 }, {
1730 key: "getTRKMember",
1731 value: function getTRKMember(root) {
1732 var geometryProperty = this.get(root, "trkseg");
1733 var geomsCoord = this.getGeometry(geometryProperty[0]);
1734 var feature = {
1735 type: 'Feature',
1736 geometry: geomsCoord.geoms.length === 1 ? geomsCoord.geoms[0] : {
1737 type: 'GeometryCollection',
1738 geometries: geomsCoord.geoms
1739 }
1740 //properties: properties
1741 };
1742 if (this.attr(root, 'id')) feature.id = this.attr(root, 'id');
1743 return [feature];
1744 }
1745 }, {
1746 key: "processGMLFile",
1747 value: function processGMLFile(fileName, form) {
1748 var file = fileName.replace(/^.*[\\\/]/, '');
1749 var self = this;
1750 this.readTextFile(form.files[0]).then(function (text) {
1751 var parser = new DOMParser();
1752 var gj = self.fc();
1753 var xmlDoc = parser.parseFromString(text, "text/xml");
1754 var Polygon = self.get(xmlDoc, "gml:Polygon");
1755 var featureMember = self.get(xmlDoc, "gml:featureMember");
1756 for (var j = 0; j < featureMember.length; j++) {
1757 gj.features = gj.features.concat(self.getFeatureMember(featureMember[j]));
1758 }
1759 var features = [];
1760
1761 gj.features.forEach(function (f) {
1762 var esrijson = arcgisToGeojsonUtils.geojsonToArcGIS(f);
1763 features.push(esrijson);
1764 });
1765 self.addGeojsonToMap(features, file, "GML");
1766 self.uploadPanel.current.toggle();
1767 });
1768 }
1769 }, {
1770 key: "getFeatureMember",
1771 value: function getFeatureMember(root) {
1772 var geometryProperty = this.get(root, "ogr:geometryProperty");
1773 var geomsCoord = this.getGeometry(geometryProperty[0]);
1774 var feature = {
1775 type: 'Feature',
1776 geometry: geomsCoord.geoms.length === 1 ? geomsCoord.geoms[0] : {
1777 type: 'GeometryCollection',
1778 geometries: geomsCoord.geoms
1779 }
1780 //properties: properties
1781 };
1782 if (this.attr(root, 'id')) feature.id = this.attr(root, 'id');
1783 return [feature];
1784 }
1785 }, {
1786 key: "getGeometry",
1787 value: function getGeometry(root) {
1788
1789 var geotypes = ['LineString', 'Polygon', 'Point', 'Track', 'gx:Track', 'gml:Polygon', 'trkpt'];
1790 var geomNode,
1791 geomNodes,
1792 i,
1793 j,
1794 k,
1795 geoms = [],
1796 coordTimes = [];
1797 if (this.get1(root, 'MultiGeometry')) {
1798 return this.getGeometry(this.get1(root, 'MultiGeometry'));
1799 }
1800 if (this.get1(root, 'MultiTrack')) {
1801 return this.getGeometry(this.get1(root, 'MultiTrack'));
1802 }
1803 if (this.get1(root, 'gx:MultiTrack')) {
1804 return this.getGeometry(this.get1(root, 'gx:MultiTrack'));
1805 }
1806 if (this.get1(root, 'trkpt')) {
1807 geomNodes = this.get(root, 'trkpt');
1808 coords = [];
1809 for (k = 0; k < geomNodes.length; k++) {
1810 coords.push([parseFloat(geomNodes[k].attributes[1].nodeValue), parseFloat(geomNodes[k].attributes[0].nodeValue)]);
1811 }
1812 geoms.push({
1813 type: 'Polygon',
1814 coordinates: [coords]
1815 });
1816 }
1817 for (i = 0; i < geotypes.length; i++) {
1818 geomNodes = this.get(root, geotypes[i]);
1819 if (geomNodes) {
1820 for (j = 0; j < geomNodes.length; j++) {
1821 geomNode = geomNodes[j];
1822 if (geotypes[i] === 'Point') {
1823 geoms.push({
1824 type: 'Point',
1825 coordinates: this.coord1(this.nodeVal(this.get1(geomNode, 'coordinates')))
1826 });
1827 } else if (geotypes[i] === 'LineString') {
1828 geoms.push({
1829 type: 'LineString',
1830 coordinates: this.coord(this.nodeVal(this.get1(geomNode, 'coordinates')))
1831 });
1832 } else if (geotypes[i] === 'Polygon') {
1833 var rings = this.get(geomNode, 'LinearRing'),
1834 coords = [];
1835 for (k = 0; k < rings.length; k++) {
1836
1837 coords.push(this.coord(this.nodeVal(this.get1(rings[k], 'coordinates'))));
1838 }
1839 geoms.push({
1840 type: 'Polygon',
1841 coordinates: coords
1842 });
1843 } else if (geotypes[i] === 'gml:Polygon') {
1844 var rings = this.get(geomNode, 'gml:LinearRing'),
1845 coords = [];
1846 for (k = 0; k < rings.length; k++) {
1847
1848 coords.push(this.coord(this.nodeVal(this.get1(rings[k], 'gml:coordinates'))));
1849 }
1850 geoms.push({
1851 type: 'Polygon',
1852 coordinates: coords
1853 });
1854 } else if (geotypes[i] === 'Track' || geotypes[i] === 'gx:Track') {
1855 var track = this.gxCoords(geomNode);
1856 geoms.push({
1857 type: 'LineString',
1858 coordinates: track.coords
1859 });
1860 if (track.times.length) coordTimes.push(track.times);
1861 }
1862 }
1863 }
1864 }
1865
1866 return {
1867 geoms: geoms,
1868 coordTimes: coordTimes
1869 };
1870 }
1871 }, {
1872 key: "nodeVal",
1873 value: function nodeVal(x) {
1874 if (x) {
1875 this.norm(x);
1876 }
1877 return x && x.textContent || '';
1878 }
1879 }, {
1880 key: "fc",
1881 value: function fc() {
1882 return {
1883 type: 'FeatureCollection',
1884 features: []
1885 };
1886 }
1887 }, {
1888 key: "xml2str",
1889 value: function xml2str(str) {
1890 var serializer;
1891 if (typeof XMLSerializer !== 'undefined') {
1892 /* istanbul ignore next */
1893 serializer = new XMLSerializer();
1894 }
1895 if (str.xml !== undefined) return str.xml;
1896 return serializer.serializeToString(str);
1897 }
1898 }, {
1899 key: "okhash",
1900 value: function okhash(x) {
1901 if (!x || !x.length) return 0;
1902 for (var i = 0, h = 0; i < x.length; i++) {
1903 h = (h << 5) - h + x.charCodeAt(i) | 0;
1904 }return h;
1905 }
1906 }, {
1907 key: "get",
1908 value: function get$$1(x, y) {
1909 return x.getElementsByTagName(y);
1910 }
1911 }, {
1912 key: "attr",
1913 value: function attr(x, y) {
1914 return x.getAttribute(y);
1915 }
1916 }, {
1917 key: "attrf",
1918 value: function attrf(x, y) {
1919 return parseFloat(this.attr(x, y));
1920 }
1921 }, {
1922 key: "get1",
1923 value: function get1(x, y) {
1924 var n = this.get(x, y);
1925 return n.length ? n[0] : null;
1926 }
1927 }, {
1928 key: "norm",
1929 value: function norm(el) {
1930 if (el.normalize) {
1931 el.normalize();
1932 }return el;
1933 }
1934 }, {
1935 key: "coord1",
1936 value: function coord1(v) {
1937 var removeSpace = /\s*/g;
1938 return this.numarray(v.replace(removeSpace, '').split(','));
1939 }
1940 }, {
1941 key: "coord",
1942 value: function coord(v) {
1943 var trimSpace = /^\s*|\s*$/g;
1944 var splitSpace = /\s+/;
1945 var coords = v.replace(trimSpace, '').split(splitSpace),
1946 o = [];
1947
1948 for (var i = 0; i < coords.length; i++) {
1949 o.push(this.coord1(coords[i]));
1950 }
1951
1952 return o;
1953 }
1954 }, {
1955 key: "gxCoord",
1956 value: function gxCoord(v) {
1957 return this.numarray(v.split(' '));
1958 }
1959 }, {
1960 key: "numarray",
1961 value: function numarray(x) {
1962
1963 for (var j = 0, o = []; j < x.length; j++) {
1964 o[j] = parseFloat(x[j]);
1965 }
1966 return o;
1967 }
1968 }, {
1969 key: "gxCoords",
1970 value: function gxCoords(root) {
1971 var elems = this.get(root, 'coord', 'gx'),
1972 coords = [],
1973 times = [];
1974 if (elems.length === 0) elems = this.get(root, 'gx:coord');
1975 for (var i = 0; i < elems.length; i++) {
1976 coords.push(this.gxCoord(this.nodeVal(elems[i])));
1977 }var timeElems = this.get(root, 'when');
1978 for (var j = 0; j < timeElems.length; j++) {
1979 times.push(this.nodeVal(timeElems[j]));
1980 }return {
1981 coords: coords,
1982 times: times
1983 };
1984 }
1985 }, {
1986 key: "processKMLFile",
1987 value: function processKMLFile(fileName, form) {
1988 var file = fileName.replace(/^.*[\\\/]/, '');
1989 var self = this;
1990
1991 this.readTextFile(form.files[0]).then(function (text) {
1992 var parser = new DOMParser();
1993 var gj = self.fc();
1994 var xmlDoc = parser.parseFromString(text, "text/xml");
1995 var placemarks = self.get(xmlDoc, "Placemark");
1996 var styles = self.get(xmlDoc, "Style");
1997 var styleMaps = self.get(xmlDoc, "StyleMap");
1998 var styleIndex = {};
1999 var styleByHash = {};
2000 var styleMapIndex = {};
2001 for (var k = 0; k < styles.length; k++) {
2002 var hash = self.okhash(self.xml2str(styles[k])).toString(16);
2003 styleIndex['#' + self.attr(styles[k], 'id')] = hash;
2004 styleByHash[hash] = styles[k];
2005 }
2006 for (var l = 0; l < styleMaps.length; l++) {
2007 styleIndex['#' + self.attr(styleMaps[l], 'id')] = self.okhash(self.xml2str(styleMaps[l])).toString(16);
2008 var pairs = self.get(styleMaps[l], 'Pair');
2009 var pairsMap = {};
2010 for (var m = 0; m < pairs.length; m++) {
2011 pairsMap[self.nodeVal(self.get1(pairs[m], 'key'))] = self.nodeVal(self.get1(pairs[m], 'styleUrl'));
2012 }
2013 styleMapIndex['#' + self.attr(styleMaps[l], 'id')] = pairsMap;
2014 }
2015 for (var j = 0; j < placemarks.length; j++) {
2016 gj.features = gj.features.concat(self.getPlacemark(placemarks[j]));
2017 }
2018
2019 var features = [];
2020
2021 gj.features.forEach(function (f) {
2022 var esrijson = arcgisToGeojsonUtils.geojsonToArcGIS(f);
2023
2024 features.push(esrijson);
2025 });
2026 self.addGeojsonToMap(features, file, "KML");
2027 self.uploadPanel.current.toggle();
2028 });
2029 }
2030 }, {
2031 key: "getPlacemark",
2032 value: function getPlacemark(root) {
2033 var geomsAndTimes = this.getGeometry(root),
2034 i,
2035 properties = {},
2036 name = this.nodeVal(this.get1(root, 'name')),
2037 address = this.nodeVal(this.get1(root, 'address')),
2038 styleUrl = this.nodeVal(this.get1(root, 'styleUrl')),
2039 styleIndex = {},
2040 styleMapIndex = {},
2041 styleByHash = {},
2042 description = this.nodeVal(this.get1(root, 'description')),
2043 timeSpan = this.get1(root, 'TimeSpan'),
2044 timeStamp = this.get1(root, 'TimeStamp'),
2045 extendedData = this.get1(root, 'ExtendedData'),
2046 lineStyle = this.get1(root, 'LineStyle'),
2047 polyStyle = this.get1(root, 'PolyStyle'),
2048 visibility = this.get1(root, 'visibility');
2049
2050 if (!geomsAndTimes.geoms.length) return [];
2051 if (name) properties.name = name;
2052 if (address) properties.address = address;
2053
2054 if (styleUrl) {
2055 if (styleUrl[0] !== '#') {
2056 styleUrl = '#' + styleUrl;
2057 }
2058 properties.styleUrl = styleUrl;
2059 if (styleIndex[styleUrl]) {
2060 properties.styleHash = styleIndex[styleUrl];
2061 }
2062 if (styleMapIndex[styleUrl]) {
2063 properties.styleMapHash = styleMapIndex[styleUrl];
2064 properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
2065 }
2066 var style = styleByHash[properties.styleHash];
2067 if (style) {
2068 if (!lineStyle) lineStyle = this.get1(style, 'LineStyle');
2069 if (!polyStyle) polyStyle = this.get1(style, 'PolyStyle');
2070 var iconStyle = this.get1(style, 'IconStyle');
2071 if (iconStyle) {
2072 var icon = this.get1(iconStyle, 'Icon');
2073 if (icon) {
2074 var href = this.nodeVal(this.get1(icon, 'href'));
2075 if (href) properties.icon = href;
2076 }
2077 }
2078 }
2079 if (description) properties.description = description;
2080 if (timeSpan) {
2081 var begin = this.nodeVal(this.get1(timeSpan, 'begin'));
2082 var end = this.nodeVal(this.get1(timeSpan, 'end'));
2083 properties.timespan = { begin: begin, end: end };
2084 }
2085 if (timeStamp) {
2086 properties.timestamp = this.nodeVal(this.get1(timeStamp, 'when'));
2087 }
2088 if (lineStyle) {
2089 var linestyles = this.kmlColor(this.nodeVal(this.get1(lineStyle, 'color'))),
2090 color = linestyles[0],
2091 opacity = linestyles[1],
2092 width = parseFloat(this.nodeVal(this.get1(lineStyle, 'width')));
2093 if (color) properties.stroke = color;
2094 if (!isNaN(opacity)) properties['stroke-opacity'] = opacity;
2095 if (!isNaN(width)) properties['stroke-width'] = width;
2096 }
2097 if (polyStyle) {
2098 var polystyles = this.kmlColor(this.nodeVal(this.get1(polyStyle, 'color'))),
2099 pcolor = polystyles[0],
2100 popacity = polystyles[1],
2101 fill = this.nodeVal(this.get1(polyStyle, 'fill')),
2102 outline = this.nodeVal(this.get1(polyStyle, 'outline'));
2103 if (pcolor) properties.fill = pcolor;
2104 if (!isNaN(popacity)) properties['fill-opacity'] = popacity;
2105 if (fill) properties['fill-opacity'] = fill === '1' ? properties['fill-opacity'] || 1 : 0;
2106 if (outline) properties['stroke-opacity'] = outline === '1' ? properties['stroke-opacity'] || 1 : 0;
2107 }
2108 if (extendedData) {
2109 var datas = this.get(extendedData, 'Data'),
2110 simpleDatas = this.get(extendedData, 'SimpleData');
2111
2112 for (i = 0; i < datas.length; i++) {
2113 properties[datas[i].getAttribute('name')] = this.nodeVal(this.get1(datas[i], 'value'));
2114 }
2115 for (i = 0; i < simpleDatas.length; i++) {
2116 properties[simpleDatas[i].getAttribute('name')] = this.nodeVal(simpleDatas[i]);
2117 }
2118 }
2119
2120 if (visibility) {
2121 properties.visibility = this.nodeVal(visibility);
2122 }
2123
2124 if (geomsAndTimes.coordTimes.length) {
2125 properties.coordTimes = geomsAndTimes.coordTimes.length === 1 ? geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes;
2126 }
2127
2128 var feature = {
2129 type: 'Feature',
2130 geometry: geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
2131 type: 'GeometryCollection',
2132 geometries: geomsAndTimes.geoms
2133 },
2134 properties: properties
2135 };
2136 if (this.attr(root, 'id')) feature.id = this.attr(root, 'id');
2137 return [feature];
2138 } else {
2139
2140 var feature = {
2141 type: 'Feature',
2142 geometry: geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
2143 type: 'GeometryCollection',
2144 geometries: geomsAndTimes.geoms
2145 },
2146 properties: properties
2147 };
2148 if (this.attr(root, 'id')) feature.id = this.attr(root, 'id');
2149 return [feature];
2150 }
2151 }
2152 }, {
2153 key: "processGeojsonFile",
2154 value: function processGeojsonFile(fileName, form) {
2155
2156 var file = fileName.replace(/^.*[\\\/]/, '');
2157 var self = this;
2158
2159 this.readTextFile(form.files[0]).then(function (text) {
2160
2161 var geojson = JSON.parse(text);
2162 var features = [];
2163
2164 geojson.features.forEach(function (f) {
2165 var esrijson = arcgisToGeojsonUtils.geojsonToArcGIS(f);
2166
2167 features.push(esrijson);
2168 });
2169
2170 self.addGeojsonToMap(features, file, "GEOJSON");
2171 self.uploadPanel.current.toggle();
2172 });
2173 }
2174 }, {
2175 key: "processShapeFile",
2176 value: function processShapeFile(fileName, form) {
2177
2178 var self = this;
2179 self.uploadPanel.current.toggle();
2180 var name = fileName.split(".");
2181 name = name[0].replace("c:\\fakepath\\", "");
2182
2183 var parms = {
2184 name: name,
2185 targetSR: self.state.view.extent.spatialReference,
2186 maxRecordCount: 1000,
2187 enforceInputFileSizeLimit: true,
2188 enforceOutputJsonSizeLimit: true
2189 };
2190
2191 parms.generalize = true;
2192 parms.maxAllowableOffset = 10;
2193 parms.reducePrecision = true;
2194 parms.numberOfDigitsAfterDecimal = 0;
2195 var myContent = {
2196 filetype: "shapefile",
2197 publishParameters: JSON.stringify(parms),
2198 f: "json",
2199 'content-type': 'multipart/form-data'
2200 };
2201
2202 var portalUrl = "https://www.arcgis.com";
2203
2204 var query = Object.keys(myContent).map(function (k) {
2205 return escape(k) + '=' + escape(myContent[k]);
2206 }).join('&');
2207
2208 reactArcgis.loadModules(['esri/request']).then(function (_ref3) {
2209 var _ref4 = slicedToArray(_ref3, 1),
2210 request = _ref4[0];
2211
2212 request(portalUrl + "/sharing/rest/content/features/generate", {
2213 query: myContent,
2214 body: new FormData(form.form),
2215 //body: document.getElementById("uploadForm"),
2216 responseType: "json"
2217 }).then(function (response) {
2218 var layerName = response.data.featureCollection.layers[0].layerDefinition.name;
2219 self.addShapefileToMap(response.data.featureCollection, layerName);
2220 });
2221 });
2222 }
2223 }, {
2224 key: "addShapefileToMap",
2225 value: function addShapefileToMap(featureCollection, layerName) {
2226 var self = this;
2227 reactArcgis.loadModules(['esri/Graphic', 'esri/layers/FeatureLayer', 'esri/layers/support/Field', 'esri/PopupTemplate']).then(function (_ref5) {
2228 var _ref6 = slicedToArray(_ref5, 4),
2229 Graphic = _ref6[0],
2230 FeatureLayer = _ref6[1],
2231 Field = _ref6[2],
2232 PopupTemplate = _ref6[3];
2233
2234 var sourceGraphics = [];
2235 var layers = featureCollection.layers.map(function (layer) {
2236
2237 var graphics = layer.featureSet.features.map(function (feature) {
2238 var gfx = Graphic.fromJSON(feature);
2239 gfx.symbol = {
2240 type: "simple-fill", // autocasts as new SimpleFillSymbol()
2241 color: "rgba(224, 206, 69, 0.8)",
2242 style: "solid",
2243 outline: {
2244 color: "yellow",
2245 width: 3
2246 }
2247 };
2248 return gfx;
2249 });
2250 sourceGraphics = sourceGraphics.concat(graphics);
2251 var featureLayer = new FeatureLayer({
2252 title: "SHP File: " + layerName,
2253 //objectIDField: "FID",
2254 source: graphics,
2255 fields: layer.layerDefinition.fields.map(function (field) {
2256 return Field.fromJSON(field);
2257 })
2258 });
2259 return featureLayer;
2260 });
2261
2262 layers[0].title = layerName;
2263
2264 self.state.map.addMany(layers);
2265
2266 self.state.view.goTo(sourceGraphics);
2267
2268 var props = {
2269 title: "Shape File: " + layerName,
2270 transparency: ".32",
2271 identmaxzoom: "13",
2272 blockidentselect: true,
2273 type: "geojson",
2274 src: "",
2275 map: self.state.map,
2276 view: self.state.view
2277 };
2278
2279 var aml = new ArcticMapLayer(props);
2280 aml.layerRef = layers[0];
2281 aml.context = window._map.layers[0].context;
2282 aml.layerRef.title = props.title;
2283
2284 self.state.map.amlayers.push(aml);
2285 });
2286 }
2287 }, {
2288 key: "addGeojsonToMap",
2289 value: function addGeojsonToMap(featureCollection, layerName, filetype) {
2290 var self = this;
2291 reactArcgis.loadModules(['esri/Graphic', 'esri/layers/FeatureLayer', 'esri/layers/support/Field', 'esri/PopupTemplate', "esri/renderers/SimpleRenderer"]).then(function (_ref7) {
2292 var _ref8 = slicedToArray(_ref7, 5),
2293 Graphic = _ref8[0],
2294 FeatureLayer = _ref8[1],
2295 Field = _ref8[2],
2296 PopupTemplate = _ref8[3],
2297 SimpleRenderer = _ref8[4];
2298 var symbol = {
2299 type: "simple-fill", // autocasts as new SimpleFillSymbol()
2300 color: "rgba(224, 206, 69, 0.8)",
2301 style: "solid",
2302 outline: {
2303 color: "red",
2304 width: 2
2305 }
2306 };
2307
2308 var i = 0;
2309 var graphics = featureCollection.map(function (feature) {
2310
2311 feature.attributes["OBJECTID"] = i++;
2312 var gfx = Graphic.fromJSON(feature);
2313
2314 gfx.symbol = symbol;
2315 return gfx;
2316 });
2317
2318 var featureLayer = new FeatureLayer({
2319 title: filetype + " File: " + layerName,
2320 objectIdField: "OBJECTID",
2321 //renderer : SimpleRenderer.fromJSON(symbol) ,
2322 source: graphics
2323 // fields: layer.layerDefinition.fields.map(function (field) {
2324 // return Field.fromJSON(field);
2325 // })
2326
2327 });
2328
2329 self.state.map.add(featureLayer);
2330 self.state.view.goTo(graphics);
2331
2332 var props = {
2333 title: filetype + " File: " + layerName,
2334 transparency: ".32",
2335 identmaxzoom: "13",
2336 blockidentselect: true,
2337 type: "geojson",
2338 src: "",
2339 map: self.state.map,
2340 view: self.state.view
2341 };
2342
2343 var aml = new ArcticMapLayer(props);
2344 aml.layerRef = featureLayer;
2345 aml.context = window._map.layers[0].context;
2346 aml.layerRef.title = props.title;
2347
2348 self.state.map.amlayers.push(aml);
2349 });
2350 }
2351 }, {
2352 key: "reset",
2353 value: function reset() {
2354 this.state.sketchViewModel.cancel();
2355 this.state.tempGraphicsLayer.removeAll();
2356 this.setState({ hideEditors: false, geojson: null });
2357 }
2358 }, {
2359 key: "setmaptoselect",
2360 value: function setmaptoselect() {
2361
2362 if (this.props.am.state.mode === "select") {
2363 this.props.am.setMode("view");
2364 this.setState({ mode: "view" });
2365 } else {
2366
2367 this.props.am.setMode("select");
2368 this.setState({ mode: "select" });
2369 }
2370 }
2371 }, {
2372 key: "widgetRender",
2373 value: function widgetRender() {
2374
2375 var self = this;
2376 var children = React.Children.map(this.props.children, function (child) {
2377
2378 return React.cloneElement(child, {
2379
2380 map: self.state.map,
2381 view: self.state.view,
2382 //ref: 'child-' + (index++)
2383 hidden: self.state.hideEditors
2384 });
2385 });
2386
2387 if (this.state.hidden === true) {
2388 return React.createElement("div", { id: "topbar" });
2389 }
2390
2391 return React.createElement(
2392 "div",
2393 { id: "topbar" },
2394 this.state.hideEditors === false && React.createElement(
2395 "span",
2396 null,
2397 React.createElement(ArcticMapButton, { showactive: this.props.am.state.mode === "select", esriicon: "cursor", title: "Click to select/ Rightclick to remove", onclick: this.setmaptoselect.bind(this) }),
2398 this.props.point && React.createElement(ArcticMapButton, { esriicon: "blank-map-pin", onclick: this.addPointClick.bind(this), title: "Draw point" }),
2399 this.props.line && React.createElement(ArcticMapButton, { esriicon: "polyline", onclick: this.addLineClick.bind(this), title: "Draw polyline" }),
2400 this.props.polygon && React.createElement(ArcticMapButton, { esriicon: "polygon", onclick: this.addPolyClick.bind(this), title: "Draw polygon" }),
2401 this.props.square && React.createElement(ArcticMapButton, { esriicon: "checkbox-unchecked", onclick: this.addRecClick.bind(this), title: "Draw rectangle" }),
2402 this.props.circle && React.createElement(ArcticMapButton, { esriicon: "radio-unchecked", onclick: this.addCircleClick.bind(this), title: "Draw circle" })
2403 ),
2404 children,
2405 this.props.upload && React.createElement(
2406 ArcticMapPanel,
2407 { hidden: this.state.hideEditors, esriicon: "upload", title: "Upload Polygon", ref: this.uploadPanel },
2408 React.createElement("br", null),
2409 React.createElement(
2410 "p",
2411 { className: style$2.infoarea },
2412 "Do you already have a shape of your plot? Upload your file here. Supported file types: Shapefiles (.zip), kml, gml, gpx, and geojson"
2413 ),
2414 React.createElement(
2415 "form",
2416 { encType: "multipart/form-data", method: "post", id: "uploadForm" },
2417 React.createElement(
2418 "div",
2419 { className: "field" },
2420 React.createElement("br", null),
2421 React.createElement(
2422 "label",
2423 { className: style$2.btm_primary_file },
2424 React.createElement("input", { type: "file", name: "file", id: "inFile", onChange: this.fileUploaded.bind(this) }),
2425 "Upload File"
2426 )
2427 )
2428 ),
2429 React.createElement("br", null),
2430 React.createElement("span", { id: "upload-status" })
2431 ),
2432 React.createElement(ArcticMapButton, { esriicon: "refresh", onclick: this.reset.bind(this), title: "Clear graphics" })
2433 );
2434 }
2435 }, {
2436 key: "componentDidUpdate",
2437 value: function componentDidUpdate() {
2438 if (this.top_right_node) {
2439 ReactDOM.render(this.widgetRender(), this.top_right_node);
2440 }
2441 }
2442 }, {
2443 key: "render",
2444 value: function render() {
2445
2446 //return (<h2>Test</h2>);
2447
2448
2449 return React.createElement(
2450 "span",
2451 null,
2452 this.state.fileLayer
2453 );
2454 }
2455 }, {
2456 key: "addGraphic",
2457 value: function addGraphic(event) {
2458 // Create a new graphic and set its geometry to
2459 // `create-complete` event geometry.
2460 // const graphic = new Graphic({
2461 // geometry: event.geometry,
2462 // symbol: sketchViewModel.graphic.symbol
2463 // });
2464 // tempGraphicsLayer.add(graphic);
2465 }
2466 }, {
2467 key: "updateGraphic",
2468 value: function updateGraphic(event) {
2469 // event.graphic is the graphic that user clicked on and its geometry
2470 // has not been changed. Update its geometry and add it to the layer
2471 // event.graphic.geometry = event.geometry;
2472 // tempGraphicsLayer.add(event.graphic);
2473
2474 // // set the editGraphic to null update is complete or cancelled.
2475 // editGraphic = null;
2476 }
2477 }, {
2478 key: "setUpClickHandler",
2479 value: function setUpClickHandler() {
2480 var self = this;
2481 self.state.view.on("click", function (event) {
2482 event.stopPropagation();
2483
2484 self.state.view.hitTest(event).then(function (response) {
2485 var results = response.results;
2486 // Found a valid graphic
2487 if (results.length && results[results.length - 1].graphic && self.map.mode != 'identify') {
2488 // Check if we're already editing a graphic
2489 // if (!self.state.editGraphic) {
2490 // Save a reference to the graphic we intend to update
2491 self.state.editGraphic = results[results.length - 1].graphic;
2492 // Remove the graphic from the GraphicsLayer
2493 // Sketch will handle displaying the graphic while being updated
2494 // self.state.tempGraphicsLayer.spatialReference = self.state.editGraphic.geometry.spatialReference;
2495 // self.state.view.spatialReference = self.state.editGraphic.geometry.spatialReference;
2496 //self.state.tempGraphicsLayer.remove(self.state.editGraphic);
2497 self.state.tempGraphicsLayer.graphics = [self.state.editGraphic];
2498 //self.state.sketchViewModel.updateGraphics = [self.state.editGraphic];
2499
2500 self.state.sketchViewModel.update([self.state.editGraphic]);
2501
2502 //self.state.tempGraphicsLayer.graphics = [self.state.editGraphic];
2503
2504 //}
2505 }
2506 });
2507 });
2508 }
2509 }, {
2510 key: "setActiveButton",
2511 value: function setActiveButton(selectedButton) {
2512 // focus the view to activate keyboard shortcuts for sketching
2513 // view.focus();
2514 // var elements = document.getElementsByClassName("active");
2515 // for (var i = 0; i < elements.length; i++) {
2516 // elements[i].classList.remove("active");
2517 // }
2518 // if (selectedButton) {
2519 // selectedButton.classList.add("active");
2520 // }
2521 }
2522 }]);
2523 return ArcticMapEdit;
2524}(React.Component);
2525
2526ArcticMapEdit.displayName = 'ArcticMapEdit';
2527
2528var css$2 = ".ArcticMapLLDSearch_lldsearchbar__10QoB {\n background: #fff;\n\n vertical-align: top; \n }\n\n\n .ArcticMapLLDSearch_lldsearchbar__10QoB div{\n display: inline;\n }";
2529var style$3 = { "lldsearchbar": "ArcticMapLLDSearch_lldsearchbar__10QoB" };
2530styleInject(css$2);
2531
2532// WY060140N0660W0SN180ANENE
2533
2534var ArcticMapLLDSearch = function (_React$Component) {
2535 inherits(ArcticMapLLDSearch, _React$Component);
2536
2537 function ArcticMapLLDSearch(props) {
2538 classCallCheck(this, ArcticMapLLDSearch);
2539
2540 var _this = possibleConstructorReturn(this, (ArcticMapLLDSearch.__proto__ || Object.getPrototypeOf(ArcticMapLLDSearch)).call(this, props));
2541
2542 _this.state = {
2543 map: props.map,
2544 view: props.view,
2545 graphic: null
2546 };
2547
2548 _this.handleChange = _this.handleChange.bind(_this);
2549 return _this;
2550 }
2551
2552 createClass(ArcticMapLLDSearch, [{
2553 key: "componentDidMount",
2554 value: function componentDidMount() {
2555 var self = this;
2556 reactArcgis.loadModules(['esri/Graphic', "esri/geometry/geometryEngine", 'esri/geometry/Geometry', 'esri/geometry/Polygon', "esri/widgets/Search/SearchSource", 'esri/request']).then(function (_ref) {
2557 var _ref2 = slicedToArray(_ref, 6),
2558 Graphic = _ref2[0],
2559 geometryEngine = _ref2[1],
2560 Geometry = _ref2[2],
2561 Polygon = _ref2[3],
2562 SearchSource = _ref2[4],
2563 esriRequest = _ref2[5];
2564
2565 //var elestring = this.createElementFromHTML( `<input type="text" placeholder="Find address or place" aria-label="Search" autocomplete="off" tabindex="0" class="esri-input esri-search__input" aria-autocomplete="list" aria-haspopup="true" aria-owns="1687b00a338-widget-1-suggest-menu" role="textbox" data-node-ref="_inputNode" title="Find address or place">`);
2566
2567 self.top_right_node = document.createElement("div");
2568
2569 self.Graphic = Graphic;
2570 self.Geometry = Geometry;
2571 self.Polygon = Polygon;
2572
2573 self.state.view.ui.add(self.top_right_node, {
2574 position: "top-right",
2575 index: 0
2576 });
2577
2578 // ReactDOM.render(
2579 // self.widgetRender(),
2580 // self.top_right_node
2581 // );
2582
2583
2584 var url = "https://gis.blm.gov/arcgis/rest/services/Cadastral/BLM_Natl_PLSS_CadNSDI/MapServer/exts/CadastralSpecialServices/FindLD";
2585
2586 self.search = new SearchSource({
2587 name: 'Legal Land Description',
2588 placeholder: "example: NV 21 T38N R56E SEC 10 ALIQ SESW",
2589
2590 getSuggestions: function getSuggestions(params) {
2591
2592 var serarcParams = params.suggestTerm.replace(/\+/g, ' ');
2593 var options = {
2594 query: {
2595 "legaldescription": serarcParams,
2596 "returnalllevels": "true",
2597 f: "pjson"
2598 },
2599 responseType: "json"
2600 };
2601 return esriRequest(url, options).then(function (results) {
2602
2603 return results.data.features.map(function (feature) {
2604 return {
2605 key: "name",
2606 text: feature.attributes.landdescription,
2607 sourceIndex: params.sourceIndex
2608 };
2609 });
2610 });
2611 },
2612
2613 getResults: function getResults(params) {
2614 var serarchParams = params.suggestResult.text.replace(/\+/g, ' ');
2615 var options = {
2616 query: {
2617 "legaldescription": serarchParams,
2618 "returnalllevels": "true",
2619 f: "pjson"
2620 },
2621 responseType: "json"
2622 };
2623
2624 return esriRequest(url, options).then(function (results) {
2625
2626 var searchResults = results.data.features.map(function (feature) {
2627
2628 var outfeature = Graphic.fromJSON(feature);
2629
2630 var buffer = geometryEngine.geodesicBuffer(outfeature.geometry, 100, "feet");
2631
2632 var searchResult = {
2633 extent: buffer.extent,
2634 feature: outfeature,
2635 name: feature.attributes.landdescription
2636 };
2637 return searchResult;
2638 });
2639 return searchResults;
2640 });
2641 }
2642 });
2643 });
2644 }
2645 }, {
2646 key: "searchLLD",
2647 value: function searchLLD(event) {
2648
2649 var self = this;
2650
2651 fetch("https://gis.blm.gov/arcgis/rest/services/Cadastral/BLM_Natl_PLSS_CadNSDI/MapServer/exts/CadastralSpecialServices/FindLD?legaldescription=" + this.state.searchinput + "+&returnalllevels=&f=json").then(function (r) {
2652 return r.json();
2653 }).then(function (data) {
2654
2655 var popupresults = data.features.map(function (feature) {
2656
2657 feature.geometry = self.Polygon.fromJSON(feature.geometry);
2658
2659 feature = new self.Graphic(feature);
2660
2661 var displayValue = feature.attributes.landdescription;
2662
2663 feature.popupTemplate = { // autocasts as new PopupTemplate()
2664 title: 'Legal Land Description',
2665 content: "<b>LLD</b>: " + displayValue,
2666 actions: [{ title: "Select", id: "select-action" }]
2667 };
2668
2669 return feature;
2670 });
2671
2672 if (popupresults.length > 0) {
2673 self.state.view.popup.open({
2674 features: popupresults,
2675 location: event.mapPoint
2676 });
2677 }
2678 });
2679 }
2680 }, {
2681 key: "handleChange",
2682 value: function handleChange(event) {
2683 this.setState({ searchinput: event.target.value });
2684 }
2685 }, {
2686 key: "widgetRender",
2687 value: function widgetRender() {
2688 return React.createElement(
2689 "div",
2690 { className: style$3.lldsearchbar },
2691 React.createElement(
2692 "div",
2693 { style: { display: 'inline-block', height: '32px', marginTop: '0px' } },
2694 React.createElement("input", { style: { display: 'inline-block', height: '32px', verticalAlign: 'top' }, value: this.state.searchinput, onChange: this.handleChange, type: "text", placeholder: "Find legal land description", "aria-label": "Search", className: "esri-input", title: "Find leagal land desription" }),
2695 React.createElement(
2696 "div",
2697 { style: { display: 'inline-block', width: '32px', height: '32px', verticalAlign: 'top' }, role: "button", title: "Search", className: "esri-search__submit-button esri-widget--button", onClick: this.searchLLD.bind(this) },
2698 React.createElement("span", { style: { display: 'block', paddingTop: '8px' }, "aria-hidden": "true", role: "presentation", className: "esri-icon-search" })
2699 )
2700 )
2701 );
2702 }
2703 }, {
2704 key: "render",
2705 value: function render() {
2706 return null;
2707 }
2708 }]);
2709 return ArcticMapLLDSearch;
2710}(React.Component);
2711
2712ArcticMapLLDSearch.displayName = 'ArcticMapLLDSearch';
2713
2714var ArcticMapLayerPopup = function (_React$Component) {
2715 inherits(ArcticMapLayerPopup, _React$Component);
2716
2717 function ArcticMapLayerPopup(props) {
2718 classCallCheck(this, ArcticMapLayerPopup);
2719 return possibleConstructorReturn(this, (ArcticMapLayerPopup.__proto__ || Object.getPrototypeOf(ArcticMapLayerPopup)).call(this, props));
2720 }
2721
2722 createClass(ArcticMapLayerPopup, [{
2723 key: 'render',
2724 value: function render() {
2725
2726 return React.createElement('span', null);
2727 }
2728 }, {
2729 key: 'renderPopup',
2730 value: function renderPopup(context) {
2731 if (this.props.popup) {
2732 return this.props.popup(context);
2733 }
2734 }
2735 }]);
2736 return ArcticMapLayerPopup;
2737}(React.Component);
2738
2739ArcticMapLayerPopup.displayName = 'ArcticMapLayerPopup';
2740
2741var ArcticMapControlArea = function (_React$Component) {
2742 inherits(ArcticMapControlArea, _React$Component);
2743
2744 function ArcticMapControlArea(props) {
2745 classCallCheck(this, ArcticMapControlArea);
2746
2747 var _this = possibleConstructorReturn(this, (ArcticMapControlArea.__proto__ || Object.getPrototypeOf(ArcticMapControlArea)).call(this, props));
2748
2749 _this.controlNode = document.createElement("div");
2750 _this.props.view.ui.add(_this.controlNode, _this.props.location);
2751
2752 return _this;
2753 }
2754
2755 createClass(ArcticMapControlArea, [{
2756 key: 'componentDidUpdate',
2757 value: function componentDidUpdate() {
2758
2759 if (this.controlNode) {
2760 ReactDOM.render(this.widgetRender(), this.controlNode, function () {});
2761 }
2762 }
2763 }, {
2764 key: 'append',
2765 value: function append(ele) {
2766 this.props.children.push(ele);
2767 }
2768 }, {
2769 key: 'widgetRender',
2770 value: function widgetRender() {
2771
2772 var self = this;
2773
2774 var children = React.Children.map(this.props.children, function (child) {
2775
2776 // else if (child.type.name === 'ArcticMapLLDSearch') {
2777
2778 // return React.cloneElement(child, {
2779 // })
2780
2781 // }
2782
2783
2784 return React.cloneElement(child, {
2785 am: self.props.am,
2786 map: self.props.am.state.map,
2787 view: self.props.am.state.view
2788 //hostDiv : self.controlNode
2789 //ref: 'child-' + (index++)
2790 //ref: (c) => { if (c) { self.childrenElements.push(c); } return 'child-' + (index++) }
2791 });
2792 });
2793
2794 return React.createElement(
2795 'span',
2796 { className: 'arcticmap-area' },
2797 children
2798 );
2799 }
2800 }, {
2801 key: 'render',
2802 value: function render() {
2803 return React.createElement('span', null);
2804 }
2805 }]);
2806 return ArcticMapControlArea;
2807}(React.Component);
2808
2809ArcticMapControlArea.displayName = 'ArcticMapControlArea';
2810
2811var ArcticMapIdentify = function (_React$Component) {
2812 inherits(ArcticMapIdentify, _React$Component);
2813
2814 function ArcticMapIdentify(props) {
2815 classCallCheck(this, ArcticMapIdentify);
2816
2817 var _this = possibleConstructorReturn(this, (ArcticMapIdentify.__proto__ || Object.getPrototypeOf(ArcticMapIdentify)).call(this, props));
2818
2819 _this.state = { mode: 1 };
2820
2821 return _this;
2822 }
2823
2824 createClass(ArcticMapIdentify, [{
2825 key: 'setmaptoidentify',
2826 value: function setmaptoidentify() {
2827 this.props.am.setMode("identify");
2828 this.setState({ mode: "identify" });
2829 }
2830 }, {
2831 key: 'render',
2832 value: function render() {
2833
2834 //cursor
2835
2836 return React.createElement(
2837 'span',
2838 null,
2839 React.createElement(ArcticMapButton, { showactive: this.props.am.state.mode === "description", esriicon: 'description', title: 'Identify', onclick: this.setmaptoidentify.bind(this) })
2840 );
2841 }
2842 }]);
2843 return ArcticMapIdentify;
2844}(React.Component);
2845
2846ArcticMapIdentify.displayName = 'ArcticMapIdentify';
2847
2848var ArcticMapBaseControl = function (_React$Component) {
2849 inherits(ArcticMapBaseControl, _React$Component);
2850
2851 function ArcticMapBaseControl(props) {
2852 classCallCheck(this, ArcticMapBaseControl);
2853
2854 var _this = possibleConstructorReturn(this, (ArcticMapBaseControl.__proto__ || Object.getPrototypeOf(ArcticMapBaseControl)).call(this, props));
2855
2856 _this.state = {
2857 zoomControl: null,
2858 renderElements: [],
2859 canReset: _this.props.reset !== undefined
2860
2861 };
2862 var self = _this;
2863 _this.zoomControlDiv = document.createElement("div");
2864 _this.layersDiv = document.createElement("div");
2865 _this.legendDiv = document.createElement("div");
2866
2867 reactArcgis.loadModules(['esri/widgets/Zoom', 'esri/widgets/LayerList', 'esri/widgets/Legend', 'esri/widgets/BasemapGallery']).then(function (_ref) {
2868 var _ref2 = slicedToArray(_ref, 4),
2869 Zoom = _ref2[0],
2870 LayerList = _ref2[1],
2871 Legend = _ref2[2],
2872 BasemapGallery = _ref2[3];
2873
2874 self.props.view.on('click', function (event) {
2875
2876 self.props.view.ui.remove(self.basemapGallery);
2877 });
2878
2879 self.basemapGallery = new BasemapGallery({
2880 view: props.view
2881 });
2882 self.basemapGallery.watch('activeBasemap', function (newValue, oldValue, property, object) {
2883 self.props.view.ui.remove(self.basemapGallery);
2884 });
2885
2886 var zoom = new Zoom({
2887 view: props.view,
2888 container: self.zoomControlDiv,
2889 position: "top-left"
2890 });
2891 self.state.zoomControl = zoom;
2892
2893 //this.props.hostDiv.appendChild(zoom);
2894 //props.view.ui.add(zoom, props.hostDiv);
2895 //self.state.children.push(self.zoomControlDiv);
2896
2897 var legend = new Legend({
2898 view: props.view,
2899 container: self.legendDiv
2900 });
2901 var layerList = new LayerList({
2902 view: props.view,
2903 container: self.layersDiv,
2904 listItemCreatedFunction: function listItemCreatedFunction(event) {
2905 // only legend if imageFormat exist in TOC
2906 if (event.item.layer.imageFormat) {
2907 var item = event.item;
2908 item.panel = {
2909 content: 'legend',
2910 open: false
2911 };
2912 }
2913 }
2914 });
2915 //self.state.view.ui.add(layerList, 'top-left')
2916 //var joined = self.state.renderElements.concat(self.zoomControlDiv);
2917 _this.setState({ renderElements: self.state.renderElements.concat(self.zoomControlDiv) });
2918 });
2919
2920 return _this;
2921 }
2922
2923 createClass(ArcticMapBaseControl, [{
2924 key: 'handleShowBasemaps',
2925 value: function handleShowBasemaps() {}
2926 }, {
2927 key: 'renderZoomcontrol',
2928 value: function renderZoomcontrol() {
2929
2930 return this.zoomControlDiv;
2931 }
2932 }, {
2933 key: 'basemapclick',
2934 value: function basemapclick() {
2935 this.props.view.ui.add(this.basemapGallery, {
2936 position: 'bottom-right'
2937 });
2938 //this.setState({ hideBasemapButton: true })
2939 // self.state.view.ui.remove(self.basemapGallery);
2940 }
2941 }, {
2942 key: 'render',
2943 value: function render() {
2944 var _this2 = this;
2945
2946 return React.createElement(
2947 'div',
2948 null,
2949 React.createElement(
2950 ArcticMapControlArea,
2951 { am: this.props.am, view: this.props.view, location: 'top-left' },
2952 React.createElement('div', { ref: function ref(e) {
2953 e && e.appendChild(_this2.zoomControlDiv);
2954 } })
2955 ),
2956 React.createElement(
2957 ArcticMapControlArea,
2958 { am: this.props.am, view: this.props.view, location: 'bottom-right', className: styles.ArcticMap },
2959 React.createElement(
2960 ArcticMapPanel,
2961 { esriicon: 'layer-list', title: 'Legend' },
2962 React.createElement('div', { ref: function ref(e) {
2963 e && e.appendChild(_this2.legendDiv);
2964 } })
2965 ),
2966 React.createElement(
2967 ArcticMapPanel,
2968 { esriicon: 'collection', title: 'Data Filters' },
2969 React.createElement(
2970 'p',
2971 null,
2972 'Toggle visibility of each data layer.'
2973 ),
2974 this.state.canReset && React.createElement(
2975 'p',
2976 null,
2977 React.createElement(
2978 'a',
2979 { href: '#', style: { color: '#71A3AF', textDecoration: 'none' }, onClick: this.props.reset },
2980 React.createElement('span', { style: { height: "10px", width: "10px", marginRight: '10px', color: 'black' }, 'aria-hidden': true, className: 'esri-icon esri-icon-trash' }),
2981 'Reset to Default Data Visibility'
2982 )
2983 ),
2984 React.createElement('div', { ref: function ref(e) {
2985 e && e.appendChild(_this2.layersDiv);
2986 } })
2987 ),
2988 React.createElement(ArcticMapButton, { esriicon: 'basemap', title: 'Basemaps', onclick: this.basemapclick.bind(this) })
2989 )
2990 );
2991 }
2992 }]);
2993 return ArcticMapBaseControl;
2994}(React.Component);
2995
2996ArcticMapBaseControl.displayName = "ArcticMapBaseControl";
2997
2998var ArcticMapLayerRenderer = function (_React$Component) {
2999 inherits(ArcticMapLayerRenderer, _React$Component);
3000
3001 function ArcticMapLayerRenderer(props) {
3002 classCallCheck(this, ArcticMapLayerRenderer);
3003
3004 var _this = possibleConstructorReturn(this, (ArcticMapLayerRenderer.__proto__ || Object.getPrototypeOf(ArcticMapLayerRenderer)).call(this, props));
3005
3006 if (props.style === undefined) {
3007 console.log("Missing style: Build Styles @ https://developers.arcgis.com/javascript/latest/sample-code/playground/live/index.html");
3008 }
3009
3010 return _this;
3011 }
3012
3013 createClass(ArcticMapLayerRenderer, [{
3014 key: 'render',
3015 value: function render() {
3016 return React.createElement('span', null);
3017 }
3018 }]);
3019 return ArcticMapLayerRenderer;
3020}(React.Component);
3021
3022ArcticMapLayerRenderer.displayName = 'ArcticMapLayerRenderer';
3023
3024var ArcticMapLocator = function (_React$Component) {
3025 inherits(ArcticMapLocator, _React$Component);
3026
3027 function ArcticMapLocator(props) {
3028 classCallCheck(this, ArcticMapLocator);
3029 return possibleConstructorReturn(this, (ArcticMapLocator.__proto__ || Object.getPrototypeOf(ArcticMapLocator)).call(this, props));
3030 }
3031
3032 createClass(ArcticMapLocator, [{
3033 key: 'componentWillMount',
3034 value: function componentWillMount() {}
3035 }, {
3036 key: 'componentDidMount',
3037 value: function componentDidMount() {
3038 var self = this;
3039 reactArcgis.loadModules(['esri/widgets/Locate', 'esri/widgets/BasemapGallery', 'esri/widgets/Home', 'esri/widgets/Search', 'esri/layers/FeatureLayer', 'esri/tasks/Locator', 'esri/geometry/geometryEngine', "esri/request"]).then(function (_ref) {
3040 var _ref2 = slicedToArray(_ref, 8),
3041 Locate = _ref2[0],
3042 BasemapGallery = _ref2[1],
3043 Home = _ref2[2],
3044 Search = _ref2[3],
3045 FeatureLayer = _ref2[4],
3046 Locator = _ref2[5],
3047 geometryEngine = _ref2[6],
3048 Request = _ref2[7];
3049
3050 var searchsources = [];
3051
3052 var devaultSource = {
3053 locator: new Locator({ url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer" }),
3054 singleLineFieldName: "SingleLine",
3055 name: "Standard Geocoder",
3056 placeholder: "Find address",
3057 maxResults: 3,
3058 maxSuggestions: 6,
3059 suggestionsEnabled: true,
3060 minSuggestCharacters: 0
3061 };
3062 searchsources.push(devaultSource);
3063 var searchitems = self.props.am.childrenElements.filter(function (ele) {
3064
3065 if (ele.search) {
3066 return ele;
3067 }
3068 // if (ele.constructor.name.toLowerCase().includes('search')) {
3069 // return ele;
3070 // }
3071 });
3072
3073 var lldsSarchsources = searchitems.map(function (i) {
3074 if (i.search) {
3075 return i.search;
3076 }
3077 });
3078
3079 searchsources.push(lldsSarchsources[0]);
3080
3081 if (self.props.searchSources) {
3082 self.props.searchSources.map(function (searchSource) {
3083
3084 var searchFeature = new FeatureLayer({
3085 url: searchSource.scr + searchSource.layerid
3086 });
3087 searchSource.layer = searchFeature;
3088
3089 searchsources.push(searchSource);
3090 });
3091 }
3092
3093 var searchWidget2 = new Search({
3094 view: self.props.view,
3095 sources: searchsources,
3096 includeDefaultSources: false // true will include standard locator
3097 });
3098
3099 self.props.view.ui.add(searchWidget2, {
3100 position: "top-right",
3101 index: 1
3102 });
3103
3104 searchWidget2.on('select-result', function (evt) {
3105
3106 self.props.view.popup.currentSearchResultFeature = evt.result.feature;
3107 self.props.view.popup.close();
3108 //self.props.view.popup.close();
3109 // view.popup.open({
3110 // location: evt.result.feature.geometry, // location of the click on the view
3111 // feature: evt.result.feature,
3112 // title: "Search Result", // title displayed in the popup
3113 // content: evt.result.name, // content displayed in the popup
3114 // });
3115 });
3116 });
3117 }
3118 }, {
3119 key: 'render',
3120 value: function render() {
3121 return null;
3122 }
3123 }]);
3124 return ArcticMapLocator;
3125}(React.Component);
3126
3127ArcticMapLocator.displayName = "ArcticMapLocator";
3128
3129exports.ArcticMap = ArcticMap;
3130exports.ArcticMapEdit = ArcticMapEdit;
3131exports.ArcticMapLayer = ArcticMapLayer;
3132exports.ArcticMapLLDSearch = ArcticMapLLDSearch;
3133exports.ArcticMapLayerPopup = ArcticMapLayerPopup;
3134exports.ArcticMapControlArea = ArcticMapControlArea;
3135exports.ArcticMapButton = ArcticMapButton;
3136exports.ArcticMapPanel = ArcticMapPanel;
3137exports.ArcticMapIdentify = ArcticMapIdentify;
3138exports.ArcticMapBaseControl = ArcticMapBaseControl;
3139exports.ArcticMapLayerRenderer = ArcticMapLayerRenderer;
3140exports.ArcticMapLocator = ArcticMapLocator;
3141//# sourceMappingURL=index.js.map