UNPKG

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