Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/map right click menu #143

Merged
merged 2 commits into from
Aug 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions viewer/js/config/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
86 changes: 65 additions & 21 deletions viewer/js/gis/dijit/Directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -63,6 +79,34 @@ 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]();
},
locationError: function(error) {
topic.publish('growler/growl', {
title: 'Error',
message: 'There was a problem with getting your location: ' + error.message,
level: 'default',
timeout: 10000,
opacity: 1.0
});
}
});
});
14 changes: 12 additions & 2 deletions viewer/js/viewer/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
}
Expand Down