Core

$.sMap()

Gets options and returns map object.

Options
Property Type Default Description
before Function function(){} A task to be executed before loading map.
after Function function(){} A task to be executed after loading map.
mode String production Defines app environment. Predefined values are: 'development', 'test' and 'production'
element CSS selector #map A CSS selector to select map element with.
boxZoom Boolean false Whether or not users can be able to use mouse to select a rectangle while holding keyboard Shift in order to zoom.
minZoom Integer 1 Minimum map zoom level.
maxZoom Integer 18 Maximum map zoom level.
presets Object { latlng: { lat: 32, lng: 52 }, zoom: 6 } Map view first load state.
i18n i18n object {} Language key:values for multi-lingual apps. (read more)

var map = $.sMap({
	before: function() {
		console.log('Before');
	},
	after: function() {
		console.log('After');
	},
	mode: 'development',
	element: '#my-map',
	boxZoom: true,
	minZoom: 3,
	maxZoom: 15,
	presets: {
		latlng: {
			lat: 32,
			lng: 52,
		},
		zoom: 8,
	},
	i18n: {
		fa: {
			'custom-site-title': 'نقشه',
		},
		en: {
			'custom-site-title': 'Map',
		},
		ar: {
			'custom-site-title': 'خريطة',
		},
	},
});
									

Fullscreen

$.sMap.fullscreen.implement()

Implements fullscreen button to map view.


$.sMap.fullscreen.implement();
									

Warning:

Fullscreen sub-module uses HTML5 fullscreen API that may not be supported by all browsers.

Stand-alone Demo

Menu

$.sMap.menu.implement()

Appends Menu trigger and panel to the map view.


$.sMap.menu.implement();
									

Warning:

This sub-module should be called before any other sub-modules that add a functionality to Menu.

Stand-alone Demo

Locale

$.sMap.locale.implement()

Gets locale options and adds multi-lingual functionalities for selected languages to app.

Options
Property Type Default Description
locales Array ['fa', 'en', 'ar'] Available languages are fa, en, and ar.

$.sMap.menu.implement();

$.sMap.locale.implement({
	locales: ['fa', 'en'],
});
									

Warning:

  • In order for $.sMap.locale to work, you need to add data-path and data-file attributes to link tags in your document head.
  • $.sMap.menu.implement sub-module must have been called before $.sMap.locale.implement so it can add language options in Menu.
Stand-alone Demo

Static Layers

$.sMap.layers.static.build()

Gets an object of layers and loads up tiles onto map. Also impliments layer management options to menu automatically if $.sMap.menu.implement is already called.

Options
Property Type Default Description
server URL env.url.defaultBaselayer
layers String Shiveh:ShivehGSLD256
format mime type image/png
i18n i18n key site-default

$.sMap.layers.static.build({
	layers: {
		base: {
			default: {
				server: 'https://map.ir/shiveh',
				layers: 'Shiveh:ShivehGSLD256',
				format: 'image/png',
				i18n: 'custom-baselayer-default',
			},
			satellite: {
				server: 'https://demo.boundlessgeo.com/geoserver/ows?',
				layers: 'ne:ne',
				format: 'image/png',
				i18n: 'custom-baselayer-satellite',
			},
			terrain: {
				server: 'https://demo.boundlessgeo.com/geoserver/ows?',
				layers: 'nasa:bluemarble',
				format: 'image/png',
				i18n: 'custom-baselayer-terrain',
			},
		},
		over: {
			boundries: {
				server: 'https://korona.geog.uni-heidelberg.de/tiles/adminb/x={x}&y={y}&z={z}',
				i18n: 'custom-baselayer-boundries',
			},
			states: {
				server: 'https://{s}.tile.openstreetmap.se/hydda/roads_and_labels/{z}/{x}/{y}.png',
				i18n: 'custom-baselayer-states',
			},
		},
	},
});
									
Stand-alone Demo

Zoom Controller

$.sMap.zoomControl.implement()

Appends the map zoom controller to the map view.


$.sMap.zoomControl.implement();
									
Stand-alone Demo

User Location

$.sMap.userLocation()

Appends user location trigger button to the map view.

Options
Property Type Default Description
history Boolean false Whether user location should be added to search history or not.

$.sMap.userLocation.implement({
	history: true,
});
									

warning:

userLocation uses the geolocation API of HTML5 to locate user location and only works on modern browsers that support this feature.

Newer modern browsers require a secure connection for this API to work.

Stand-alone Demo

Dynamic Location

$.sMap.dynamicLocation()

Provides a handy way of accessing map location with a Copy button to save location to clipboard.

Appends sub-module's enterface to the map view.

Options
Property Type Default Description
format String dms Location format. Available values are 'dms' and 'latlng'.
source String center Location source. Available values are 'center', 'mouse', 'click' and 'contextmenu'.

$.sMap.dynamicLocation.implement({
	format: 'latlng',
	source: 'mouse',
});
									
Stand-alone Demo

Dynamic URL

$.sMap.dynamicUrl()

Enables hash url that is updated every time user moves the map or zooms in/out.

Options
Property Type Default Description
marker Boolean false Whether or not center of the map is located with a marker when a map url is opened.

$.sMap.dynamicUrl({
	marker: true,
});
									

warning:

dynamicUrl uses the pushState method of HTML5 history object to update browser's address bar every time users move the map or zoom in/out.
Enabling this feature on a map that is put in a news website, for example, might cause unwanted results. Imagine an article's url changing every time user moves the map!

Stand-alone Demo

Contextmenu

$.sMap.contextmenu.build()

Gets contextmenu options and adds contextmenu functionality to app.

Options
Property Type Default Description
here Boolean true Adds Reverse Geocode item to contextmenu.
distance Boolean true Adds Measurement: Distance item to contextmenu.
area Boolean true Adds Measurement: Area item to contextmenu.
copy Boolean true Adds Coordinations Copy item to contextmenu.
share Boolean true Adds Share URL item to contextmenu.
static Boolean true Adds Static Map item to contextmenu.

$.sMap.contextmenu.build({
	here: true,
	distance: true,
	area: true,
	copy: true,
	share: true,
	static: true,
});
									

Warning:

If you add a functionality to the contextmenu, make sure you call the required sub-module too.

Stand-alone Demo

Reverse Geocode

$.sMap.reverseGeocode.show()

Gets a map state and displays location address in a modal.

Options
Property Type Default Description
state Object Current map center

$.sMap.reverseGeocode.show({
	state: {
		latlng: {
			lat: 32,
			lng: 52,
		},
		zoom: 8,
	},
});
									
Stand-alone Demo

$.sMap.reverseGeocode.mark()

Gets options and displays location address in marker popup.

Options
Property Type Default Description
state Object Current map center
popup Object { title: { html: '', i18n: '', }, }
icon Object icons.default.blue

$.sMap.reverseGeocode.mark({
	latlng: {
		lat: 32,
		lng: 52,
	},
	title: {
		html: 'Reverse Geocode',
		i18n: '',
	},
	icon: icons.default.blue,
});
									
Stand-alone Demo

Measurement

$.sMap.measurement()

Gets no options and enables measurement options in contextmenu.


$.sMap.contextmenu.build({
	here: false,
	distance: true,
	area: true,
	copy: false,
	share: false,
	static: false,
});

$.sMap.measurement();
									
Stand-alone Demo

Static Map

$.sMap.staticMap.get()

Gets options and returns static map url.

Options
Property Type Default Description
state Object Current map state.
width Integer 600
height Integer 400
label String
color String red Marker color.

$.sMap.staticMap.get({
	state: {
		latlng: {
			lat: 32,
			lng: 52,
		},
		zoom: 10,
	},
	width: 800,
	height: 600,
	label: 'My Location',
	color: 'green',
});
									
Stand-alone Demo

$.sMap.staticMap.open()

Options
Property Type Default Description
Property Type Default Description

$.sMap.staticMap.open({
	state: {
		latlng: {
			lat: 35.63665,
			lng: 51.45687,
		},
		zoom: 10,
	},
	width: 800,
	height: 600,
	label: 'My Location',
	color: 'green',
});
									
Stand-alone Demo

Basic Features

Quick access:
  1. Markers
  2. Polylines
  3. Polygons

Markers:

$.sMap.features.marker.create()

Gets marker options, returns a marker object, and displays a marker on map view.

Options
Property Type Default Description
before Function function(){} A task to be executed before marker creation.
after Function function(){} A task to be executed after marker creation.
name String (kebab-case) temp Marker name
popup Object popup: { title: { html: '', i18n: '' }, description: { html: '', i18n: '' }, custom: false } html can either be plain text or contain html tags. i18n is used for multi-lingual apps. If custom is set with a string, it will overwrite the automatically generated popup with your own content. There will be no popup if it's set to false.
class String default A CSS class with the prefix of feature-popup- is created from this value and is applied to marker popup's inner container. feature-popup-default for example if class is not set.
latlng Object {} Marker location.
icon Object icons.default.blue the icons object is defined in s.map.styles.js
popupOpen Boolean false Whether popup should be open when marker is created.
pan Boolean false Whether or not map should pan to marker location upon its creation.
draggable Boolean false Whether marker is or is not draggable.
on Object { click: function(){}, contextmenu: function(){} } Contains callback functions for click and contextmenu.

$.sMap.features();

$.sMap.features.marker.create({
	before: function() {
		console.log('Before');
	},
	after: function() {
		console.log('After');
	},
	name: 'my-marker',
	popup: {
		title: {
			html: 'Title',
			i18n: '',
		},
		description: {
			html: 'Description',
			i18n: '',
		},
		custom: false,
	},
	class: 'default',
	latlng: {lat: 32, lng: 52},
	icon: icons.default.blue,
	popupOpen: true,
	pan: false,
	draggable: true,
	on: {
		click: function(){
			console.log('click callback');
		},
		contextmenu: function(){
			console.log('contextmenu callback');
		},
	},
});
									

Tips:

  • Similar to all features, a marker names is more like a unique id. If a marker with an id already exists, creating a second marker with the same name will remove the previous marker first and then create a new one. If this is not the functionality you want, maybe you better add dynamic indexes to marker names or try the $.sMap.editor.points sub-module instead.
  • You can remove a certain marker using its name with the $.sMap.features.marker.remove method.
Stand-alone Demo

$.sMap.features.marker.remove()

Removes a marker programmatically.


$.sMap.features.marker.remove('my-marker');
									

$.sMap.features.marker.wipe()

Removes all polygons from the map view.


$.sMap.features.marker.wipe();
									

Polylines:

$.sMap.features.polyline.create()

Gets polyline options, returns a polyline object and displays a polyline on map view.

Options
Property Type Default Description
before Function function(){} A task to be executed before polyline creation.
after Function function(){} A task to be executed after polyline creation.
name String (kebab-case) temp Polyline name
popup Object popup: { title: { html: '', i18n: '' }, description: { html: '', i18n: '' }, custom: false } html can either be plain text or contain html tags. i18n is used for multi-lingual apps. If custom is set with a string, it will overwrite the automatically generated popup with your own content. There will be no popup if it's set to false.
class String default A CSS class with the prefix of feature-popup- is created from this value and is applied to polyline popup's inner container. feature-popup-default for example if class is not set.
coordinates Array [] Polyline's set of points.
style Object styles.default.polyline the styles object is defined in s.map.styles.js
popupOpen Boolean false Whether popup should be open when polyline is created.
pan Boolean false Whether or not map should pan to polyline location upon its creation.
measurement Boolean false Whether measurement info should to be displayed on polyline or not.
on Object { click: function(){}, contextmenu: function(){} } Contains callback functions for click and contextmenu.

$.sMap.features();

$.sMap.features.polyline.create({
	before: function() {},
	after: function() {},
	name: 'my-polyline',
	popup: {
		title: {
			html: 'Title',
			i18n: '',
		},
		description: {
			html: 'Description',
			i18n: '',
		},
		custom: false,
	},
	class: 'default',
	style: styles.default.polyline,
	coordinates: [
		[30, 50],
		[40, 57],
	],
	popupOpen: false,
	pan: false,
	measurement: false,
	on: {
		click: function(){
			console.log('click callback');
		},
		contextmenu: function(){
			console.log('contextmenu callback');
		},
	},
});
									

Tips:

  • Similar to all features, a polyline names is more like a unique id. If a polyline with an id already exists, creating a second polyline with the same name will remove the previous polyline first and then create a new one. If this is not the functionality you want, maybe you better add dynamic indexes to polyline names or try the $.sMap.editor.points sub-module instead.
  • You can remove a certain polyline using its name with the $.sMap.features.polyline.remove method.
Stand-alone Demo

$.sMap.features.polyline.remove()

Removes a polyline programmatically.


$.sMap.features.polyline.remove('my-polyline');
									

$.sMap.features.polyline.wipe()

Removes all polygons from the map view.


$.sMap.features.polyline.wipe();
									

Polygons:

$.sMap.features.polygon.create()

Gets polygon options, returns a polygon object and displays a polygon on map view.

Options
Property Type Default Description
before Function function(){} A task to be executed before polygon creation.
after Function function(){} A task to be executed after polygon creation.
name String (kebab-case) temp Polygon name
popup Object popup: { title: { html: '', i18n: '' }, description: { html: '', i18n: '' }, custom: false } html can either be plain text or contain html tags. i18n is used for multi-lingual apps. If custom is set with a string, it will overwrite the automatically generated popup with your own content. There will be no popup if it's set to false.
class String default A CSS class with the prefix of feature-popup- is created from this value and is applied to polygon popup's inner container. feature-popup-default for example if class is not set.
coordinates Array [] Polygon's set of points.
style Object styles.default.polygon the styles object is defined in s.map.styles.js
popupOpen Boolean false Whether popup should be open when polygon is created.
pan Boolean false Whether or not map should pan to polygon location upon its creation.
measurement Boolean false Whether measurement info should to be displayed on polygon or not.
on Object { click: function(){}, contextmenu: function(){} } Contains callback functions for click and contextmenu.

$.sMap.features();

$.sMap.features.polygon.create({
	before: function() {},
	after: function() {},
	name: 'my-polygon',
	popup: {
		title: {
			html: 'Title',
			i18n: '',
		},
		description: {
			html: 'Description',
			i18n: '',
		},
		custom: false,
	},
	class: 'default',
	style: styles.default.polygon,
	coordinates: [
		[35, 55],
		[35, 45],
		[30, 55],
	],
	popupOpen: false,
	pan: false,
	measurement: false,
	on: {
		click: function(){
			console.log('click callback');
		},
		contextmenu: function(){
			console.log('contextmenu callback');
		},
	},
});
									

Tips:

  • Similar to all features, a polygon names is more like a unique id. If a polygon with an id already exists, creating a second polygon with the same name will remove the previous polygon first and then create a new one. If this is not the functionality you want, maybe you better add dynamic indexes to polygon names or try the $.sMap.editor.points sub-module instead.
  • You can remove a certain polygon using its name with the $.sMap.features.polygon.remove method.
Stand-alone Demo

$.sMap.features.polygon.remove()

Removes a polygon programmatically.


$.sMap.features.polygon.remove('my-polygon');
									

$.sMap.features.polygon.wipe()

Removes all polygons from the map view.


$.sMap.features.polygon.wipe();
									

Feature Editor

Quick access:
  1. Points
  2. Polylines
  3. Polygons

$.sMap.editor.implement()

This sub-module must be called before using either of $.sMap.editor.points, $.sMap.editor.polylines, $.sMap.editor.polygons sub-modules.

Tips:

  • Unlike $.sMap.features, $.sMap.editor has a collective view towards features.
  • You can either start up the map with a bunch of features, or add a drawing handler to the map view to allow users to do it using a graphical enterface.
  • Unlike $.sMap.features, features' coordinations here must be in geoJSON format.
Options
Property Type Default Description
renderer string 'svg' Whether to use the canvas or svg tag to render shapes. Available values are 'canvas' and 'svg'

$.sMap.editor.implement();
									

Points:

$.sMap.editor.points.start()

Gets an options object including a geoJSON, displays the set on the map upon start, and returns the points geoJSON.

Options
Property Type Default Description
geoJSON geoJSON { "type": "FeatureCollection", "features": [] }
modules Object { create: false, edit: false, delete: false, get: false, editText: false, } Choose which options are enabled/disabled for the set.
on Object { click: false, contextmenu: false, create: function(){}, edit: function(){}, delete: function(){}, get: function(){}, editText: function(){}, } An object of callback functions.
icons Array [ { name: 'Blue', class: 'marker-blue', url: '/assets/images/marker-default-blue.svg', }, ] An array of icons that is used to create Icon Gallery

$.sMap.editor.implement();

var points = {
	"type": "FeatureCollection",
	"features": [
		{
			"type": "Feature",
			"properties": {
				title: 'Test1',
				description: 'Desc1',
				icon: '/assets/images/marker-default-green.svg',
			},
			"geometry": {
				"type": "Point",
				"coordinates": [52, 32]
			}
		},
		{
			"type": "Feature",
			"properties": {
				title: 'Test2',
				description: 'Desc2',
				icon: '/assets/images/marker-default-blue.svg',
			},
			"geometry": {
				"type": "Point",
				"coordinates": [53, 32]
			}
		},
		{
			"type": "Feature",
			"properties": {
				title: 'Test3',
				description: 'Desc3',
				icon: '/assets/images/marker-default-red.svg',
			},
			"geometry": {
				"type": "Point",
				"coordinates": [53, 33]
			}
		}
	]
};

points = $.sMap.editor.points.start({
	geoJson: points,
	modules: {
		create: true,
		drag: true,
		delete: true,
		get: true,
		editText: true,
		editIcon: true,
	},
	on: {
		click: function(feature){
			console.log('click');
			console.log(feature);
		},
		contextmenu: function(feature){
			console.log('contextmenu');
			console.log(feature);
		},
		change: function(){
			console.log($.sMap.editor.points.all());
		},
		create: function(point){
			console.log('create:');
			console.log(point);
		},
		drag: function(point){
			console.log('drag:');
			console.log(point);
		},
		delete: function(point){
			console.log('delete:');
			console.log(point);
		},
		get: function(point){
			console.log('get:');
			console.log(point);
		},
		editText: function(point){
			console.log('editText:');
			console.log(point);
		},
		editIcon: function(point){
			console.log('editIcon:');
			console.log(point);
		},
	},
	icons: [
		{
			title: 'Blue',
			class: 'marker-blue',
			url: '/assets/images/marker-default-blue.svg',
		},
		{
			title: 'Green',
			class: 'marker-green',
			url: '/assets/images/marker-default-green.svg',
		},
		{
			title: 'Red',
			class: 'marker-red',
			url: '/assets/images/marker-default-red.svg',
		},
	],
});
									
Stand-alone Demo

$.sMap.editor.points.all()

Gets no options and returns the point set geoJSON.


$.sMap.editor.points.all();
									

$.sMap.editor.points.inView()

Gets no options and returns only the points in set that are in viewport.


$.sMap.editor.points.inView();
									

$.sMap.editor.points.get()

Gets item index and returns the point's geometry.


$.sMap.editor.points.get(index);
									

$.sMap.editor.points.delete()

Gets item index and deletes it from the set.


$.sMap.editor.points.delete(index);
									

$.sMap.editor.points.add()

Gets an item and adds it to the set.


$.sMap.editor.points.add(item);
									

Polylines:

$.sMap.editor.polylines.start()

Gets an options object including a geoJSON, displays the set on the map upon start, and returns the polylines geoJSON.

Options
Property Type Default Description
geoJSON geoJSON { "type": "FeatureCollection", "features": [] }
modules Object { cluster: false, create: false, drag: false, delete: false, get: false, editText: false, editIcon: false, } Choose which options are enabled/disabled for the set.
on Object { click: false, contextmenu: false, create: function(){}, drag: function(){}, delete: function(){}, get: function(){}, editText: function(){}, editIcon: function(){}, } An object of callback functions.

$.sMap.editor.implement();

var polylines = {
	"type": "FeatureCollection",
	"features": [
		{
			"type": "Feature",
			"properties": {
				title: 'Test1',
				description: 'Desc1',
			},
			"geometry": {
				"type": "LineString",
				"coordinates": [
					[51,35],
					[50,34]
				]
			}
		},
		{
			"type": "Feature",
			"properties": {
				title: 'Test2',
				description: 'Desc2',
			},
			"geometry": {
				"type": "LineString",
				"coordinates": [
					[53,32],
					[51,33]
				]
			}
		}
	]
}

polylines = $.sMap.editor.polylines.start({
	geoJson: polylines,
	modules: {
		create: true,
		edit: true,
		delete: true,
		get: true,
		editText: true,
	},
	on: {
		click: function(feature){
			console.log('click');
			console.log(feature);
		},
		contextmenu: function(feature){
			console.log('contextmenu');
			console.log(feature);
		},
		change: function(){
			console.log($.sMap.editor.polylines.all());
		},
		create: function(polyline){
			console.log('create:');
			console.log(polyline);
		},
		drag: function(polyline){
			console.log('drag:');
			console.log(polyline);
		},
		delete: function(polyline){
			console.log('delete:');
			console.log(polyline);
		},
		get: function(polyline){
			console.log('get:');
			console.log(polyline);
		},
		editText: function(point){
			console.log('editText:');
			console.log(point);
		},
		edit: function(polyline){
			console.log('editText:');
			console.log(polyline);
		},
	},
});
									
Stand-alone Demo

$.sMap.editor.polylines.all()

Gets no options and returns the polyline set geoJSON.


$.sMap.editor.polylines.all();
									

$.sMap.editor.polylines.get()

Gets item index and returns the polyline's geometry.


$.sMap.editor.polylines.get(index);
									

$.sMap.editor.polylines.delete()

Gets item index and deletes it from the set.


$.sMap.editor.polylines.delete(index);
									

$.sMap.editor.polylines.add()

Gets an item and adds it to the set.


$.sMap.editor.polylines.add(item);
									

Polygons:

$.sMap.editor.polygons.start()

Gets an options object including a geoJSON, displays the set on the map upon start, and returns the polygons geoJSON.

Options
Property Type Default Description
geoJSON geoJSON { "type": "FeatureCollection", "features": [] }
modules Object { create: false, edit: false, delete: false, get: false, editText: false, } Choose which options are enabled/disabled for the set.
on Object { click: false, contextmenu: false, create: function(){}, edit: function(){}, delete: function(){}, get: function(){}, editText: function(){}, } An object of callback functions.

$.sMap.editor.implement();

var polygons = {
	"type": "FeatureCollection",
	"features": [
		{
			"type": "Feature",
			"properties": {
				title: 'Test1',
				description: 'Desc1',
			},
			"geometry": {
				"type": "Polygon",
				"coordinates": [
					[
						[55,35],
						[52,34],
						[52,36],
						[55,35]
					]
				]
			}
		},
		{
			"type": "Feature",
			"properties": {
				title: 'Test2',
				description: 'Desc2',
			},
			"geometry": {
				"type": "Polygon",
				"coordinates": [
					[
						[50,32],
						[57,34],
						[53,30],
						[50,32]
					]
				]
			}
		}
	]
}

polygons = $.sMap.editor.polygons.start({
	geoJson: polygons,
	modules: {
		create: true,
		edit: true,
		delete: true,
		get: true,
		editText: true,
	},
	on: {
		click: function(feature){
			console.log('click');
			console.log(feature);
		},
		contextmenu: function(feature){
			console.log('contextmenu');
			console.log(feature);
		},
		change: function(){
			console.log($.sMap.editor.polygons.all());
		},
		create: function(polygon){
			console.log('create:');
			console.log(polygon);
		},
		drag: function(polygon){
			console.log('drag:');
			console.log(polygon);
		},
		delete: function(polygon){
			console.log('delete:');
			console.log(polygon);
		},
		get: function(polygon){
			console.log('get:');
			console.log(polygon);
		},
		editText: function(point){
			console.log('editText:');
			console.log(point);
		},
		edit: function(polygon){
			console.log('editText:');
			console.log(polygon);
		},
	},
});
									
Stand-alone Demo

$.sMap.editor.polygons.all()

Gets no options and returns the polygon set geoJSON.


$.sMap.editor.polygons.all();
									

$.sMap.editor.polygons.get()

Gets item index and returns the polygon's geometry.


$.sMap.editor.polygons.get(index);
									

$.sMap.editor.polygons.delete()

Gets item index and deletes it from the set.


$.sMap.editor.polygons.delete(index);
									

$.sMap.editor.polygons.add()

Gets an item and adds it to the set.


$.sMap.editor.polygons.add(item);