├── README ├── auth.css ├── auth.html ├── color.html ├── colors.css ├── create.html ├── distancecalculator.html ├── drawingtools.html ├── examples.css ├── examples.js ├── expose.html ├── farbtastic.css ├── farbtastic.js ├── featureInput.html ├── featurefilter.html ├── getcoordinates.html ├── graphicfeature.html ├── index.html ├── jquery.jsoneditor.min.js ├── layerstyles.html ├── mapsnlayers.html ├── marker.png ├── markermethods.html ├── markers.html ├── mask.png ├── multiselectfeature.html ├── polygonarea.html ├── ready.html ├── selectfeature.html ├── signin-bt.jpg ├── signin.png ├── simplemap.html ├── spatialfilter.html ├── toolbar.html └── wheel.png /README: -------------------------------------------------------------------------------- 1 | -- GIS Cloud JavaScript API examples -- 2 | 3 | See here: http://dev.giscloud.com/JavaScriptApi/GettingStarted#Examples_and_demos -------------------------------------------------------------------------------- /auth.css: -------------------------------------------------------------------------------- 1 | .gc-auth-button { 2 | width: 150px; 3 | height: 22px; 4 | background-image: url("images/signin-bt.jpg"); 5 | background-repeat: no-repeat; 6 | background-position: top; 7 | color: #666; 8 | font-family: Tahoma; 9 | font-size: 11px; 10 | cursor: pointer; 11 | text-align: center; 12 | } 13 | 14 | div.gc-auth-button:hover { 15 | background-position: bottom; 16 | } 17 | 18 | .gc-authorized { 19 | background-image: none; 20 | } 21 | 22 | .gc-redirect-uri-mismatch { 23 | background-image: none; 24 | cursor: default; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /auth.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
78 | This example shows how to use GIS Cloud Authorization to access your private data. 79 |
80 | 81 |82 |
83 | 84 | 85 |86 |
87 | 88 | 89 |90 | List private maps 91 |
92 | 93 |96 | The code: 97 |
98 |// once the page is ready 99 | giscloud.ready(function() { 100 | 101 | // check token every second 102 | setInterval(displayStatus, 1000); 103 | 104 | // authorize with this app's client id, which is "ccb0db2768b14d7da0d6" 105 | giscloud.oauth2.authorize("ccb0db2768b14d7da0d6", function() { 106 | 107 | // create the sign in button 108 | giscloud.oauth2.button("authButton"); 109 | 110 | }); 111 | 112 | }); 113 | 114 | ... 115 | 116 | // get token 117 | var token = giscloud.oauth2.token(); 118 | 119 | ... 120 | 121 | // get maps - if there's a token available it will be used to 122 | // access private data 123 | giscloud.maps.list({ type: "private" }) 124 | .done(onMapsLoadingDone) 125 | .fail(onMapsLoadingFailed); 126 |127 | 128 | 129 | -------------------------------------------------------------------------------- /color.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
347 | This example uses the 348 | 349 | Farbtastic jQuery colorpicker plugin 350 | made by Steven Wittens. 351 |
352 |200 | This example shows you how to create some of the basic GIS objects. 201 |
202 | 203 |First thing you'll need is a map. Set a name for it and press create.
206 |207 | 208 |
209 |Next, a table is required to hold feature data. Name will be converted to alphanumeric lowercase.
214 |215 | 216 |
217 |A layer is defined with the table as the datasource, and the map as its parent. Set a name for it.
222 |Another layer, the OSM basemap, will be added to the map as well.
223 |224 | 225 |
226 |232 | Set a latitude and a longitude using GPS coordinates for a new point feature. 233 | You can also set some values for the new feature. 234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
114 | Draw a line by clicking a few points on the map. 115 | As a result, you will get a distance that is calculated using Haversine formula. 116 |
117 | 118 | 119 | 120 |121 | The code: 122 |
123 |124 | // start with line drawing 125 | viewer.graphic.draw("line").progress(onDraw).then(onFinish); 126 | 127 | // Haversine formula 128 | function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { 129 | var R = 6371, // Radius of the earth in km 130 | dLat = deg2rad(lat2-lat1), // deg2rad below 131 | dLon = deg2rad(lon2-lon1), 132 | // Haversine formula 133 | a = 134 | Math.sin(dLat/2) * Math.sin(dLat/2) + 135 | Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 136 | Math.sin(dLon/2) * Math.sin(dLon/2), 137 | c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)), 138 | d = R * c; // Distance in km 139 | return d; 140 | } 141 | 142 | // inside onDraw function calculate distance using Haversine formula 143 | distance += getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2); 144 | 145 | // show the distance in marker with two decimal places 146 | distanceKm = parseFloat(distance).toFixed(2); 147 |148 | 149 | 150 | -------------------------------------------------------------------------------- /drawingtools.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
171 | With the aid of the viewer's graphic object, you can have users 172 | drawing graphic features directly on the viewer. 173 |
174 |175 | In this example four custom tools are created and added to the viewer's toolbar. 176 | The tools are used to draw points, lines, polygons and to clear the graphic layer. 177 |
178 |179 | Additionally, after the feature has been drawn, its 180 | OGC Simple Feature WKT 181 | (well-known text) is displayed in the box below the map. 182 |
183 | 184 | 185 | 186 | 187 | 188 |189 | The code: 190 |
191 |// point tool 192 | new giscloud.ui.Toolbar.Tool("pointTool", { 193 | instant: true, 194 | styles: { 195 | caption: "Point", 196 | showCaption: true, 197 | cssClass: "mytool", 198 | active: "mytool-active", 199 | hover: "mytool-hover" 200 | }, 201 | actions: { 202 | activation: function (viewer) { 203 | 204 | // start drawing 205 | viewer.graphic.draw("point", 206 | function (feat) { 207 | 208 | // output wkt 209 | outputOgcWkt(feat.geometry().toOGC()); 210 | 211 | } 212 | ); 213 | 214 | } 215 | } 216 | } 217 | ) 218 | 219 | 220 | // line tool 221 | ... 222 | viewer.graphic.draw("line", ... 223 | 224 | // polygon tool 225 | ... 226 | viewer.graphic.draw("polygon", ... 227 | 228 | 229 | // clear tool 230 | ... 231 | viewer.graphic.clear(); 232 | ...233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /examples.css: -------------------------------------------------------------------------------- 1 | body { width: 600px; font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 0.8em } 2 | 3 | h1 { font-size: 1.2em } 4 | 5 | pre { 6 | background-color: #EEEEEE; 7 | border: thin solid #CCCCCC; 8 | font-size: 1.2em; 9 | padding: 2em; 10 | overflow-x: auto; 11 | } 12 | 13 | #mapViewer { 14 | width: 598px; 15 | height: 370px; 16 | border: thin solid #CCCCCC; 17 | } 18 | 19 | #toolbar { 20 | background-color: #f0f0f0; 21 | border: thin solid #CCCCCC; 22 | } 23 | 24 | #list { 25 | background-color: #fafafa; 26 | border: thin solid #CCCCCC; 27 | padding-left: 1em; padding-bottom: 1em; 28 | margin-bottom: 5em; 29 | height: 300px; 30 | overflow: auto; 31 | } 32 | 33 | #list li { 34 | margin: 1em; 35 | } 36 | -------------------------------------------------------------------------------- /examples.js: -------------------------------------------------------------------------------- 1 | var mapId = 7022, layerId = 28098; 2 | 3 | (function () { 4 | var m, s = document.location.search, $ = giscloud.exposeJQuery(); 5 | 6 | m = (s && s.match && s.match(/mid\=(\d+)/i)); 7 | if (m && m[1]) { 8 | mapId = parseInt(m[1], 10); 9 | } 10 | 11 | m = (s && s.match && s.match(/lid\=(\d+)/i)); 12 | if (m && m[1]) { 13 | layerId = parseInt(m[1], 10); 14 | } 15 | 16 | $(function() { 17 | $("body").append( 18 | '' + 19 | '
33 | This is an example of the giscloud.exposeJQuery() method. 34 |
35 |36 | This method exposes jQuery internally used by the GIS Cloud JavaScript API. 37 |
38 | 39 |175 | Try adding some features into the Cloud! 176 |
177 |178 |
58 | This example shows the filterFeatures method of the Viewer. 59 |
60 |61 | Select a filter: 62 |
84 | 85 | 86 | 87 | 88 | 89 |90 | The code: 91 |
92 |93 | // these are the three filter definitions 94 | var filters = { 95 | nameA: { 96 | attributes: "name", 97 | filter: function (obj) { 98 | return obj.name[0] === "A"; 99 | } 100 | }, 101 | tropicals: { 102 | attributes: "lat", 103 | filter: function (obj) { 104 | return Math.abs(obj.lat) < 23; 105 | } 106 | }, 107 | highPopulation: { 108 | attributes: "pop2005", 109 | filter: function (obj) { 110 | return obj.pop2005 > 10000000; 111 | } 112 | } 113 | }; 114 | 115 | // one of these is chosen when a radio button is selected 116 | function setFilter() { 117 | var filter = filters[$("form input:checked").val()]; 118 | viewer.filterFeatures(layerId, filter); 119 | } 120 |121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /getcoordinates.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
94 | In this example, we create an instant tool which will draw a point feature on a desired location 95 | and display the location's coordinates. 96 |
97 | 98 | 99 | 100 | 101 | 102 |103 | The code: 104 |
105 |// create the tool 106 | tool = new giscloud.ui.Toolbar.Tool("pointTool", { 107 | 108 | // instant tools don' stay activated 109 | instant: true, 110 | 111 | styles: { 112 | caption: "Get coordinates", 113 | showCaption: true, 114 | cssClass: "mytool", 115 | active: "mytool-active", 116 | hover: "mytool-hover" 117 | }, 118 | 119 | actions: { 120 | 121 | // since this is a instant tool, only the activation action is needed 122 | activation: function (viewer) { 123 | 124 | // clear previously added graphic features 125 | viewer.graphic.clear(); 126 | 127 | // start drawing 128 | viewer.graphic.draw("point", 129 | function (point) { 130 | 131 | // when done, show coordinates 132 | showCoordinates(point.geometry()); 133 | 134 | } 135 | ); 136 | 137 | } 138 | } 139 | } 140 | );141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /graphicfeature.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
113 | The viewer's graphic object allows us to add custom graphic elements to the map. 114 |
115 |116 | Pressing the button below will take some random points inside the current bounds, 117 | create a polygon, and put the graphic feature to the map. 118 |
119 |120 | 121 |
122 | 123 | 124 | 125 |126 | The code: 127 |
128 |// create polygon geometry 129 | geometry = new giscloud.geometry.Polygon([new giscloud.geometry.Line(points)]); 130 | 131 | // create a style 132 | style = new giscloud.GraphicStyle("polygon"); 133 | style.color = giscloud.Color.randomHue(100, 60); 134 | 135 | // create the graphic feature 136 | polygonGraphic = new giscloud.GraphicFeature(geometry, style); 137 | 138 | // add the feature to the map 139 | viewer.graphic.add(polygonGraphic); 140 |141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
These are examples of GIS Cloud Javascript API usage.
10 |258 | Click on buttons to modify layer styles. 259 |
260 | 261 |263 |
266 | | Gallery icons, expressions 1-3 visible | 267 |
270 | | Custom icon, only last expression visible | 271 |
277 |
280 | | Blue colour scheme, thicker border | 281 |
284 | | Brown colour scheme, thinner border | 285 |
291 |
294 | | Without labels | 295 |
298 | | With labels | 299 |
304 |
121 | This example shows how to retrieve public map data from GIS Cloud. You'll see 20 most visited maps in GIS Cloud. 122 |
123 | 124 |
125 | Once loaded, maps are displayed in the list below. You can see their names and ids.
126 | Clicking on the Get layers links will retrieve layer data for each map.
127 |
132 | The code: 133 |
134 |135 | function getMapsData() { 136 | 137 | // get public maps 138 | giscloud.maps.list({ perPage: 20, sort: "visited:desc" }) 139 | .done(function(mapdata) { 140 | var i, k, map; 141 | 142 | // mapdata contains an array of giscloud.Map objects 143 | for (i = 0, k = mapdata.length; i < k; i++) { 144 | 145 | map = mapdata[i]; 146 | 147 | // show map data on the page 148 | showMapData(map.id, map.name); 149 | 150 | } 151 | }); 152 | } 153 | 154 | 155 | function getLayersData(mapId) { 156 | 157 | // get layers data 158 | giscloud.layers.byMapId(mapId) 159 | .done(function(layerdata) { 160 | var i, k, layer; 161 | 162 | // layerdata contains an array of giscloud.Layer objects 163 | for (i = 0, k = mapdata.length; i < k; i++) { 164 | 165 | layer = layerdata[i]; 166 | 167 | // show map data on the page 168 | showLayersData(mapId, layer.id, layer.name); 169 | 170 | } 171 | 172 | }); 173 | } 174 |175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giscloud/GIS-Cloud-Examples/e3c70be987e346c04c1840fef5ec7ed442d31ff3/marker.png -------------------------------------------------------------------------------- /markermethods.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
139 | This example demonstrates use of viewer flag markers.
140 | Follow the six steps and learn how to use the FlagMarker object and its methods.
141 |
261 | All of the code used in the 6 steps: 262 |
263 |264 | // create marker 265 | marker = new giscloud.FlagMarker( 266 | new giscloud.LonLat(2300000, 6200000), 267 | "London", 268 | "London, UK... , 269 | new giscloud.Color(255, 150, 0) 270 | ); 271 | 272 | // add marker to viewer 273 | viewer.addMarker(marker); 274 | 275 | // change color 276 | marker.color( 277 | new giscloud.Color(0, 40, 200) 278 | ); 279 | 280 | // toggle marker visibility 281 | marker.visible( 282 | !marker.visible() 283 | ); 284 | 285 | // change marker position 286 | marker.position( 287 | new giscloud.LonLat(-8226405, 4966405) 288 | ); 289 | 290 | // change marker title 291 | marker.title("New York"); 292 | 293 | // change marker content 294 | marker.content( 295 | "New York, USA<br/>New York <a target='_blank' " + 296 | "href='http://en.wikipedia.org/wiki/New_York_City'>Wikipedia article</a>." 297 | ); 298 | 299 | // remove the marker 300 | viewer.removeMarker(marker); 301 | 302 |303 |
125 | This example demonstrates use of viewer flag markers.
126 | Features data is loaded and a flag marker is created for each feature.
127 |
129 | Markers are positioned at the center of the feature's bounds. The title and the content of the markers are 130 | filled with some feature data. All the markers are initially hidden, and you can display them by clicking 131 | through the index above the map viewer. 132 |
133 |134 | Methods of 135 | jQuery promise objects are used for synchronisation. 136 |
137 | 138 | 139 | 140 | 141 |142 | The code: 143 |
144 |145 | // create a hidden marker with a random color 146 | m = new giscloud.FlagMarker( 147 | f.bounds.center(), 148 | title, 149 | content, 150 | giscloud.Color.randomHue(70, 50) 151 | ).visible(false); 152 | 153 | 154 | // show the marker 155 | m.visible(true); 156 | 157 | 158 | // 159 | // synchronization 160 | // 161 | 162 | // start loading features and save data to a variable when done 163 | var featuresLoading = giscloud.features.byLayer(4) 164 | .done(function() { 165 | // save loaded features 166 | features = arguments[0]; 167 | }); 168 | 169 | // create a viewer 170 | viewer = new giscloud.Viewer("mapViewer", 1); 171 | 172 | // after both the viewer and the features have been loaded, 173 | // create the markers and the index 174 | $.when(viewer.loading, featuresLoading) 175 | .done(createMarkers) 176 | .done(createIndex); 177 |178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giscloud/GIS-Cloud-Examples/e3c70be987e346c04c1840fef5ec7ed442d31ff3/mask.png -------------------------------------------------------------------------------- /multiselectfeature.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
135 | If you want to enable multiple selection without using the keyboard and the ctrl button, you can do it like this. 136 |
137 |138 | After the viewer has finished loading, bind an event handler to the featureClick event which will add or remove 139 | clicked features to an array. Pass that array as a parameter to the viewer.selection.selected() method to set 140 | the selected features. 141 |
142 | 143 |Selected features:
144 |
145 |
149 |
150 | The code:
151 |
153 | var selection = []; 154 | 155 | function onFeatureClick(feature) { 156 | // see if the clicked feature is already a part of the selection 157 | var i = inSelection(feature); 158 | 159 | // if it is, i is the index, -1 otherwise 160 | if (i === -1) { 161 | // add to selection 162 | selection.push({ 163 | featureId: feature.featureId, 164 | layerId: feature.layerId 165 | }); 166 | } else { 167 | // remove from selection 168 | selection.splice(i, 1); 169 | } 170 | 171 | // apply selection 172 | viewer.selection.selected(selection); 173 | 174 | // show a list of selected features 175 | showFeaturesInList(); 176 | } 177 |178 | 179 | 180 | -------------------------------------------------------------------------------- /polygonarea.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
155 | Polygon coordinates are expressed using WGS84, but it will be projected into Google Web Mercator for the area calculation. 156 |
You can either type in a polygon in the WKT format or you can create a random polygon. 157 |
158 |159 | Pressing the button Create a random polygon will take some random points inside the current bounds and 160 | create a polygon. 161 |
162 |163 | The Draw polygon on map button draws the graphic feature on the map. 164 | The Calculate area button calculates the polygon area in the EPSG:900913 projection. 165 |
166 |177 | The code: 178 |
179 |// get a giscloud geometry polygon object from WKT 180 | var polygonGeometry = giscloud.geometry.fromOGC(polygonWkt); 181 | 182 | // get the result container 183 | var resultContainer = $("#result"); 184 | 185 | // calculate the area of the polygonGeometry 186 | // the geometry srid is 4326, output srid is 900913 187 | giscloud.geoutils.area(polygonGeometry, 4326, 900913, function(result){ 188 | resultContainer.text(result + " m"); 189 | }) 190 |191 | 192 | 193 | -------------------------------------------------------------------------------- /ready.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
23 | This is an example of the giscloud.ready() method. 24 |
25 |26 | The ready method is passed an anonymous function as a 27 | parameter which is executed once the DOM and the API are loaded by the browser. 28 |
29 | 30 |31 | giscloud.ready(function() { 32 | 33 | alert("Giscloud is loaded and ready!"); 34 | 35 | }); 36 |37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /selectfeature.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
81 | The most common thing somebody expects when clicking on a feature on a map is to find out stuff about it. 82 | Here's a short example of how you can get that with the GIS Cloud JS API. 83 |
84 |85 | We'll use the default select tool combined with the viewer's selectionChange event to get 86 | the feature id. Then, through the giscloud.features object, we'll get the data and display it in 87 | a table. 88 |
89 | 90 | 91 | 92 |Property | 96 |Value | 97 |
---|---|
102 | |
106 | The code: 107 |
108 |109 | // bind a handler for the selectionChange event 110 | viewer.selectionChange(function (evt) { 111 | if (evt.action === "add") { 112 | // get feature data 113 | giscloud.features.byId(evt.feature.layerId, evt.feature.featureId) 114 | .done(displayFeatureData); 115 | } 116 | }); 117 |118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /signin-bt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giscloud/GIS-Cloud-Examples/e3c70be987e346c04c1840fef5ec7ed442d31ff3/signin-bt.jpg -------------------------------------------------------------------------------- /signin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giscloud/GIS-Cloud-Examples/e3c70be987e346c04c1840fef5ec7ed442d31ff3/signin.png -------------------------------------------------------------------------------- /simplemap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
31 | This is an example of a simple mapping app created with the GIS Cloud JS API. 32 |
33 | 34 | 35 | 36 | 37 |38 | The code: 39 |
40 |41 | giscloud.ready(function() { 42 | 43 | // create a viewer 44 | var viewer = new giscloud.Viewer("mapViewer", 1); 45 | 46 | // create a toolbar 47 | var toolbar = new giscloud.ui.Toolbar({ 48 | viewer: viewer, 49 | container: "toolbar", 50 | defaultTools: ["pan", "zoom", "full", "measure"] 51 | }); 52 | 53 | }); 54 |55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /spatialfilter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
92 | Draw a polygon by clicking a few points on the map. After that, pick a spatial filter operation to be executed on the layer. 93 | As a result, you will get feature IDs that are returned from the spatial filter request. 94 |
95 |You can reset the polygon you drew and draw a new one by clicking the "Draw new polygon" button.
96 | 97 | 98 | 106 |113 | The code: 114 |
115 |116 | // geometryObject is a giscloud.geometry object. See more 117 | // it is the polygon we drew on the map 118 | // it can be created from wkt by calling giscloud.geometry.fromOGC(polygonWkt) 119 | 120 | giscloud.geoutils.spatialFilter(geometryObject, [layerId], {srid: 900913, operation: operation}) 121 | .done(function(result) { 122 | displayFeatures(result) 123 | }); 124 |125 | 126 | 127 | -------------------------------------------------------------------------------- /toolbar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
146 | Tools are an efficient way to communicate with the viewer. Additionally, 147 | tools can be placed on a toolbar which then takes care of the tools being active 148 | only one at a time. 149 |
150 |151 | This example shows you how to make custom tools and add them to a toolbar. 152 |
153 |154 | The tools are very simple. One will make current coordinates be displayed in a <div> 155 | element placed under the map, and the other will make coordinates be dispalyed as a map tip. 156 |
157 |158 | The currently active tool is . 159 |
160 | 161 | 162 | 163 | 164 | 165 |166 | The code: 167 |
168 |// create the first tool which shows coordinates in a <div> 169 | tool1 = new giscloud.ui.Toolbar.Tool( 170 | 171 | // tool name 172 | "tool1", 173 | 174 | // tool options 175 | { 176 | styles: { 177 | caption: "Coords in div", 178 | showCaption: true, 179 | cssClass: "mytool", 180 | active: "mytool-active", 181 | hover: "mytool-hover" 182 | }, 183 | actions: { 184 | activation: function (viewer) { 185 | // attach event handler 186 | viewer.mouseMove(showInDiv); 187 | // or viewer.bind("mouseMove", showInDiv); 188 | }, 189 | deactivation: function (viewer) { 190 | // detach event handler 191 | // --> note that in order to detach an event handler it is 192 | // necessary to keep a reference to the function originally 193 | // passed to the event binding method 194 | viewer.unbind("mouseMove", showInDiv); 195 | 196 | // clear the div 197 | $("#coords").html(""); 198 | } 199 | } 200 | } 201 | ); 202 | 203 | 204 | // create the second tool which will display coordinates in a map tip 205 | tool2 = new giscloud.ui.Toolbar.Tool( 206 | 207 | // tool name 208 | "tool2", 209 | 210 | // tool options 211 | { 212 | styles: { 213 | caption: "Coords in map tip", 214 | showCaption: true, 215 | cssClass: "mytool", 216 | active: "mytool-active", 217 | hover: "mytool-hover" 218 | }, 219 | actions: { 220 | activation: function (viewer) { 221 | // attach event handler 222 | viewer.mouseMove(showInMapTip); 223 | }, 224 | deactivation: function (viewer) { 225 | // detach event handler 226 | viewer.unbind("mouseMove", showInMapTip); 227 | // hide map tip 228 | viewer.hideTip(); 229 | } 230 | } 231 | } 232 | ); 233 | 234 | 235 | // create the toolbar 236 | myToolbar = new giscloud.ui.Toolbar( 237 | 238 | // options 239 | { 240 | viewer: viewer, 241 | container: "toolbar" 242 | } 243 | ); 244 | 245 | 246 | // add some tools 247 | myToolbar.add(tool1, tool2); 248 | 249 | 250 | // bind a handler to the toolbar's toolChange event 251 | myToolbar.toolChange(function (oldTool, newTool) { 252 | 253 | $("#activeTool").html(newTool.name); 254 | 255 | }); 256 | 257 | 258 | // activate the first tool 259 | myToolbar.tools["tool1"].activate();260 | 261 | 262 | 263 | -------------------------------------------------------------------------------- /wheel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/giscloud/GIS-Cloud-Examples/e3c70be987e346c04c1840fef5ec7ed442d31ff3/wheel.png --------------------------------------------------------------------------------