Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

iShare GIS has a plugin system which allows you to add buttons and dialogues which you can use for custom functionality. This guide describes that system and takes you through the steps for creating a custom plugin.

Prerequisites

  • An understanding of how to write and debug JavaScript

Overview

The plugin system is already used to add the Standard and Advanced toolbars into iShare GIS, but can be customised to add/remove buttons as required. It accomplishes this by reading a specific XML file for a Map Source, or if one isn't specified, the default one. This XML file describes which plugin to add, each of which is a sub-folder of the folder containing the XML file.

Default Plugins

The default plugins XML file (/web/plugins/iShareGIS.xml) contains the following:

...

FilenameDescription
Layers.cssThis file contains any CSS required for the plugin.
Layers.xml This file contains the metadata about the plugin.
Layers.jsThis is the code for the plugin itself.

Custom Plugins

In order to prevent your custom plugins being lost when you upgrade your version of iShare GIS, custom plugins are kept under the \web\custom\plugins folder This folder must contain at least one XML file defining however many custom plugins are required.

...

Info

The PluginView value (custom/plugins/CustomPlugins) is the path the to XML file (without the .xml extension) which will be read in and added to iShare GIS for this Map Source.

Anchor
pluginxml
pluginxml
The Plugin XML

Code Block
<Plugin>
	<Name>drilldown</Name>
	<Description>Enables Enables interactive selecting of features from pre-defined layers via the map</Description>
	<Category>advanced</Category>
</Plugin>

...

This can be either "standard" or "advanced" and determines whether the button is positioned on the iShare GIS toolbar to the right or left respectively.

Anchor
pluginjs
pluginjs
The Plugin JavaScript

The commands for adding components are fairly straightforward, and can be broken into three main commands; installButton, installDialog and installPanel.

Anchor
name
name
installButton(config, category, profile);

This adds a button to iShare GIS.

ObjectPropertyDescription
config  JavaScript object which contains configuration properties about the button. Commonly used properties are:
 
Anchor
configname
configname
name:
The name of the button
 type:What type of dialog to display when the button is clicked (or an empty string for no dialog) [ quickdialog | modaldialog ]
 dialog;The name of the dialog to show when the button is clicked e.g. Astun.JS.Plugins.dialogs.mydialogs where mydialogs is the name of the dialog.
 hideOnEmptyDialog:Should the button be hidden if the dialog is empty  [ true | false ]
 text:The text to go in the button
 tooltip:The tooltip text that is shown when you hover over the button
 tooltipTitle:The title of the tooltip that is shown when you hover over the button
 click:A function which will be called when the button is clicked
category Optional - Usually, this can be ignored, but the default uses standard and advanced for the different tool bars.
profile Optional - Again, this can usually be ignored.

InstallDialog(name, config, category, profile);

This adds a dialog to iShare GIS which can be referenced by a button - using the dialog property of the installButton object.

ObjectDescription
Anchor
dialogname
dialogname
name
The name of the dialog so that it can be referenced. A dialog called mydialog would be referenced by Astun.JS.Plugins.dialogs.mydialogs
configUsually a function which accepts two parameters which in turn would return a standard JavaScript object which would be used to render the dialog. (See the Examples for more information)
categoryOptional - Usually, this can be ignored, but the default uses standard and advanced for the different toolbars.
profileOptional - Again, this can usually be ignored.

installPanel(name, config, category, profile);

This adds a panel to iShare GIS which can be referenced by a button.

ObjectDescription
nameThe name of the panel so that it can be referenced. A panel called mypanel would be referenced by Astun.JS.Plugins.panels.mypanel.
configUsually a function which accepts three parameters which in turn would return  a standards JavaScript object which would be used to render the dialog. (See the Examples for more information)
categoryOptional - Usually, this can be ignored, but the default uses standard and advanced for the different toolbars.
profileOptional - Again, this can usually be ignored.

Anchor
examples
examples
Examples

Hello World!

This simple example will display a windows alert with the words "Hello World!" in it.

Code Block
languagejs
firstline1
titleHelloWorld.js
linenumberstrue
Astun.JS.Plugins.installButton(
	{
		name: "helloWorldButton",
		type: "",
		dialog: null,
		hideOnEmptyDialog: false,
		text: 'My Button',
		tooltipTitle: 'Hello world!',
		tooltip: 'This shows the Hello World dialogue',
		click: function() {
			// This function is called when the button is clicked
			window.alert('Hello World!');
		}
	}
);

Active Layers

This plugin will display a dialog which lists all of the active layers and shows the layers legend image.

...

Code Block
languagecss
firstline1
titleActiveLayers.css
linenumberstrue
collapsetrue
div.ishare-layerquery li {
	list-style:none;
	padding-bottom:16px;
}

div.ishare-layerquery img {
	display:block;
}

Result

This produces the following output in a dialog:

CurrentView

This plugin will produce an image of the current view of the map.

...

Code Block
languagecss
firstline1
titleCurrentView.css
linenumberstrue
div.ishare-currentview img {
    max-width: 800px;
}
div.ishare-currentview {
    text-align: center;
}

Result

This produces the following output in a dialog:

ViewQuery

The new plugin we are going to create is called ViewQuery and will by a mixture of what was covered in the examples and also new topics. The plugin will take your current view and output the following:

...

Code Block
languagecss
firstline1
titleViewQuery.css
linenumberstrue
collapsetrue
div.ishare-viewquery {
	text-align: center;
}
div.ishare-viewquery table {
	border: 1px solid #666;
	border-collapse: collapse;
	margin-bottom: 16px;
}
div.ishare-viewquery td, 
div.ishare-viewquery th {
	border: 1px solid #666;
	padding: 8px;
}
div.ishare-viewquery th {
	background-color: #ccc;
}
div.ishare-viewquery .sitereport-mapcontainer {
	margin-bottom: 16px;
	text-align: center;
}
div.ishare-viewquery img {
	border: 1px solid #666;
	max-height:600px;
}
div.ishare-viewquery caption {
	font-weight: bold;
	margin-bottom: 8px;
}

Result

This produces the following output in a dialog:

...