From 78fdb4733c68134df936f1addc0c5f0d51e95e59 Mon Sep 17 00:00:00 2001 From: David Spriggs Date: Wed, 6 Aug 2014 19:58:58 -0500 Subject: [PATCH 1/2] Added map right click menu to controller and can be passed into any asking widget. See Directions widget config in viewer.js and Directions.js for example on how to create a menu. --- viewer/js/config/viewer.js | 1 + viewer/js/gis/dijit/Directions.js | 91 ++++++++++++++++++++++++------- viewer/js/viewer/Controller.js | 14 ++++- 3 files changed, 83 insertions(+), 23 deletions(-) diff --git a/viewer/js/config/viewer.js b/viewer/js/config/viewer.js index 346336bd5..10af30b36 100644 --- a/viewer/js/config/viewer.js +++ b/viewer/js/config/viewer.js @@ -308,6 +308,7 @@ define([ position: 7, options: { map: true, + mapRightClickMenu: true, options: { routeTaskUrl: 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route', routeParams: { diff --git a/viewer/js/gis/dijit/Directions.js b/viewer/js/gis/dijit/Directions.js index 43355ffb3..35920e95d 100644 --- a/viewer/js/gis/dijit/Directions.js +++ b/viewer/js/gis/dijit/Directions.js @@ -7,8 +7,12 @@ define([ 'dojo/_base/lang', 'dijit/Menu', 'dijit/MenuItem', - 'dijit/MenuSeparator' -], function(declare, _WidgetBase, _TemplatedMixin, Directions, template, lang, Menu, MenuItem, MenuSeparator) { + 'dijit/PopupMenuItem', + 'dijit/MenuSeparator', + 'esri/geometry/Point', + 'esri/SpatialReference', + 'dojo/topic' +], function(declare, _WidgetBase, _TemplatedMixin, Directions, template, lang, Menu, MenuItem, PopupMenuItem, MenuSeparator, Point, SpatialReference, topic) { return declare([_WidgetBase, _TemplatedMixin], { templateString: template, @@ -24,25 +28,37 @@ define([ this.mapRightClickPoint = evt.mapPoint; })); - // create right-click menu - this.menu = new Menu({ - targetNodeIds: [this.map.root], - selector: '.layersDiv' // restrict to map only - }); - this.menu.addChild(new MenuItem({ - label: 'Directions from here', - onClick: lang.hitch(this, 'directionsFrom') - })); - this.menu.addChild(new MenuItem({ - label: 'Directions to here', - onClick: lang.hitch(this, 'directionsTo') - })); - this.menu.addChild(new MenuSeparator()); - this.menu.addChild(new MenuItem({ - label: 'Add stop', - onClick: lang.hitch(this, 'addStop') - })); - this.menu.startup(); + if (this.mapRightClickMenu) { + this.menu = new Menu(); + this.menu.addChild(new MenuItem({ + label: 'Directions from here', + onClick: lang.hitch(this, 'directionsFrom') + })); + this.menu.addChild(new MenuItem({ + label: 'Directions to here', + onClick: lang.hitch(this, 'directionsTo') + })); + this.menu.addChild(new MenuSeparator()); + this.menu.addChild(new MenuItem({ + label: 'Add stop', + onClick: lang.hitch(this, 'addStop') + })); + this.menu.addChild(new MenuSeparator()); + this.menu.addChild(new MenuItem({ + label: 'Use my location as start point', + onClick: lang.hitch(this, 'getGeoLocation', 'directionsFrom') + })); + this.menu.addChild(new MenuItem({ + label: 'Use my location as end point', + onClick: lang.hitch(this, 'getGeoLocation', 'directionsTo') + })); + + // add this widgets menu as a sub menu to the map right click menu + this.mapRightClickMenu.addChild(new PopupMenuItem({ + label: 'Directions', + popup: this.menu + })); + } }, clearStops: function() { this.directions.reset(); @@ -63,6 +79,39 @@ define([ if (this.directions.stops[0] && this.directions.stops[1]) { this.directions.getDirections(); } + }, + getGeoLocation: function(leg) { + if (navigator && navigator.geolocation) { + navigator.geolocation.getCurrentPosition(lang.hitch(this, 'locationSuccess', leg), lang.hitch(this, 'locationError')); + } else { + topic.publish('growler/growl', { + title: 'Error', + message: 'Geolocation not supported by your browser.', + level: 'default', + timeout: 10000, + opacity: 1.0 + }); + } + }, + locationSuccess: function(leg, event) { + this.mapRightClickPoint = new Point(event.coords.longitude, event.coords.latitude, new SpatialReference({ + wkid: 4326 + })); + this[leg](); + // var wmPoint = esri.geometry.geographicToWebMercator(point); + }, + locationError: function(error) { + this.growler.growl({ + title: 'Error', + message: 'There was a problem with getting your location: ' + error.message + }); + topic.publish('growler/growl', { + title: 'Error', + message: 'There was a problem with getting your location: ' + error.message, + level: 'default', + timeout: 10000, + opacity: 1.0 + }); } }); }); \ No newline at end of file diff --git a/viewer/js/viewer/Controller.js b/viewer/js/viewer/Controller.js index 74d8f363a..9a5094d17 100644 --- a/viewer/js/viewer/Controller.js +++ b/viewer/js/viewer/Controller.js @@ -16,8 +16,9 @@ define([ 'put-selector', 'dojo/aspect', 'dojo/has', - 'esri/dijit/PopupMobile' -], function(declare, Map, domStyle, domGeom, domClass, on, array, BorderContainer, ContentPane, FloatingTitlePane, lang, mapOverlay, IdentityManager, FloatingWidgetDialog, put, aspect, has, PopupMobile) { + 'esri/dijit/PopupMobile', + 'dijit/Menu' +], function(declare, Map, domStyle, domGeom, domClass, on, array, BorderContainer, ContentPane, FloatingTitlePane, lang, mapOverlay, IdentityManager, FloatingWidgetDialog, put, aspect, has, PopupMobile, Menu) { return { legendLayerInfos: [], @@ -133,6 +134,12 @@ define([ this.config.mapOptions.infoWindow = new PopupMobile(null, put('div')); } this.map = new Map('mapCenter', this.config.mapOptions); + // create right-click menu + this.mapRightClickMenu = new Menu({ + targetNodeIds: [this.map.root], + selector: '.layersDiv' // restrict to map only + }); + this.mapRightClickMenu.startup(); if (this.config.mapOptions.basemap) { this.map.on('load', lang.hitch(this, 'initLayers')); @@ -398,6 +405,9 @@ define([ if (options.map) { options.map = this.map; } + if (options.mapRightClickMenu) { + options.mapRightClickMenu = this.mapRightClickMenu; + } if (options.mapClickMode) { options.mapClickMode = this.mapClickMode; } From 750ba9f862ced397860edf898df308ac9ab2dedc Mon Sep 17 00:00:00 2001 From: David Spriggs Date: Wed, 6 Aug 2014 20:49:37 -0500 Subject: [PATCH 2/2] Fixed growler for Directions.js --- viewer/js/gis/dijit/Directions.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/viewer/js/gis/dijit/Directions.js b/viewer/js/gis/dijit/Directions.js index 35920e95d..fce289fc7 100644 --- a/viewer/js/gis/dijit/Directions.js +++ b/viewer/js/gis/dijit/Directions.js @@ -98,13 +98,8 @@ define([ wkid: 4326 })); this[leg](); - // var wmPoint = esri.geometry.geographicToWebMercator(point); }, locationError: function(error) { - this.growler.growl({ - title: 'Error', - message: 'There was a problem with getting your location: ' + error.message - }); topic.publish('growler/growl', { title: 'Error', message: 'There was a problem with getting your location: ' + error.message,