<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Extend map plugin capabilities using Custom JS. Fla-shop.com blog</title>
	<atom:link href="https://www.fla-shop.com/blog/category/empowerment-with-custom-js/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fla-shop.com/blog/category/empowerment-with-custom-js/</link>
	<description>Interactive Maps, HTML5, WordPress, Map Use-cases – Fla-shop.com blog</description>
	<lastBuildDate>Sat, 19 Nov 2022 17:08:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Example JS script for flashing cities on a map</title>
		<link>https://www.fla-shop.com/blog/example-js-script-for-flashing-cities-on-a-map/</link>
					<comments>https://www.fla-shop.com/blog/example-js-script-for-flashing-cities-on-a-map/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 03 Oct 2019 07:11:18 +0000</pubDate>
				<category><![CDATA[Empowerment with Custom JS]]></category>
		<guid isPermaLink="false">https://www.fla-shop.com/blog/?p=997</guid>

					<description><![CDATA[<p>Another example of using a script for a plugin with a map of the USA. JS code randomly shows one of the added points. When you hover over the map, all points are displayed, which allows you to click on any point.</p>
<p>The post <a href="https://www.fla-shop.com/blog/example-js-script-for-flashing-cities-on-a-map/">Example JS script for flashing cities on a map</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-group article_md_block"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow"> <!-- start Fla-shop.com HTML5 Map --> <div class='usaHtml5Mapbottom htmlMapResponsive' style='max-width:980px; width: 100%'><div id='usa-html5-map-map-container_0' class='usaHtml5MapContainer' data-map-variable='usahtml5map_map_0'></div><div style='clear:both; height: 20px;'></div> <style> #usa-html5-map-map-container_0 { } #usa-html5-map-map-container_0 .fm-tooltip-name { color: #000000; font-size: 20px; } #usa-html5-map-map-container_0 .fm-tooltip-comment { font-size: 12px; } #usa-html5-map-map-container_0 .fm-tooltip-comment p { font-size: 12px; } @media only screen and (max-width: 480px) { #usa-html5-map-map-container_0 { float: none; width: 100%; } } </style><script type="text/javascript"> jQuery(function(){ var hightlighted = null; usahtml5map_map_0 = new FlaShopUSAMap(usahtml5map_map_cfg_11); usahtml5map_map_0.draw('usa-html5-map-map-container_0'); usahtml5map_map_0.on('mousein', function(ev, sid, map) { if (hightlighted && sid != hightlighted) { map.stateHighlightOut(hightlighted); hightlighted = null; } }); (function (map, containerId, mapId) { var INTERVAL = 1; var ORDER = 'random'; /* Otherwise - direct */ var points = Object.keys(map.mapConfig.points); var canShow = true; var currentI = null; var enTimer = false; var hidePoints = function () { for (var i = 0; i < points.length; i++) { if (i !== currentI) map.hideState(points[i]); } }; var showPoints = function () { for (var i = 0; i < points.length; i++) { if (i !== currentI) map.showState(points[i]); } }; var showNextPoint = function () { var curPid; if ( ! canShow) return; if (currentI === null) { currentI = ORDER === 'random' ? Math.floor(Math.random()*1000) % points.length : 0; } else { hideCurrentPoint(); if (ORDER === 'random') { do { var cI = Math.floor(Math.random()*1123) % points.length; } while (cI === currentI); currentI = cI; } else { currentI = currentI == points.length - 1 ? 0 : currentI + 1; } } showCurrentPoint(); }; var showCurrentPoint = function () { if (currentI === null) return; var curPid; curPid = points[currentI]; map.showState(curPid); map.stateHighlightIn(curPid); }; var hideCurrentPoint = function (onlyTt) { if (currentI === null) return; var curPid; curPid = points[currentI]; map.stateHighlightOut(curPid); if (onlyTt) return; map.hideState(curPid); }; hidePoints(); setInterval(showNextPoint, INTERVAL * 1000); showNextPoint(); jQuery('#'+containerId).on('mouseenter', function (ev) { if (enTimer) { clearTimeout(enTimer); enTimer = false; } hideCurrentPoint(true); showPoints(); canShow = false; }); jQuery('#'+containerId).on('mouseleave', function (ev) { if (enTimer) { clearTimeout(enTimer); enTimer = false; } enTimer = setTimeout(function () { canShow = true; hidePoints(); showCurrentPoint(); }, 300); }); })(usahtml5map_map_0, 'usa-html5-map-map-container_0', 11); var html5map_onclick = function(ev, sid, map) { var cfg = usahtml5map_map_cfg_11; var link = map.fetchStateAttr(sid, 'link'); var is_group = map.fetchStateAttr(sid, 'group'); var popup_id = map.fetchStateAttr(sid, 'popup-id'); var is_group_info = false; if (typeof cfg.map_data[sid] !== 'undefined') jQuery('#usa-html5-map-selector_0').val(sid); else jQuery('#usa-html5-map-selector_0').val(''); if (is_group==undefined) { if (sid.substr(0,1)=='p') { popup_id = map.fetchPointAttr(sid, 'popup_id'); link = map.fetchPointAttr(sid, 'link'); } } else if (typeof cfg.groups[is_group]['ignore_link'] == 'undefined' || ! cfg.groups[is_group].ignore_link) { link = cfg.groups[is_group].link; popup_id = cfg.groups[is_group]['popup_id']; is_group_info = true; } if (link=='#popup') { if (typeof SG_POPUP_DATA == "object") { if (popup_id in SG_POPUP_DATA) { SGPopup.prototype.showPopup(popup_id,false); } else { jQuery.ajax({ type: 'POST', url: 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=11' + '&usahtml5map_get_popup', data: {popup_id:popup_id}, }).done(function(data) { jQuery('body').append(data); SGPopup.prototype.showPopup(popup_id,false); }); } } else if (typeof SGPBPopup == "function") { var popup = SGPBPopup.createPopupObjById(popup_id); popup.prepareOpen(); popup.open(); } return false; } if (link == '#info') { var id = is_group_info ? is_group : (sid.substr(0,1)=='p' ? sid : map.fetchStateAttr(sid, 'id')); jQuery('#usa-html5-map-state-info_0').html('Loading...'); jQuery.ajax({ type: 'POST', url: (is_group_info ? 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=11' + '&usahtml5map_get_group_info=' : 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=11' + '&usahtml5map_get_state_info=') + id, success: function(data, textStatus, jqXHR){ jQuery('#usa-html5-map-state-info_0').html(data); }, dataType: 'text' }); return false; } if (ev===null && link!='') { if (!jQuery('.html5dummilink').length) { jQuery('body').append('<a href="#" class="html5dummilink" style="display:none"></a>'); } jQuery('.html5dummilink').attr('href',link).attr('target',(map.fetchStateAttr(sid, 'isNewWindow') ? '_blank' : '_self'))[0].click(); } }; usahtml5map_map_0.on('click',html5map_onclick); }); </script><div id='usa-html5-map-state-info_0' class='usaHtml5MapStateInfo'></div> </div> <div style='clear: both'></div> <!-- end HTML5 Map --> 
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p>This example uses the <a href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">US Map for WordPress plugin</a>.</p>



<h2 class="wp-block-heading">Code for the &#8220;Custom JS&#8221; section in the plugin settings</h2>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
var INTERVAL = 1;
var ORDER = 'random'; /* Otherwise - direct */

var points = Object.keys(map.mapConfig.points);

var canShow = true;
var currentI = null;
var enTimer = false;

var hidePoints = function () {
    for (var i = 0; i &lt; points.length; i++) {
        if (i !== currentI)
            map.hideState(points&#x5B;i]);
    }
};

var showPoints = function () {
    for (var i = 0; i &lt; points.length; i++) {
        if (i !== currentI)
            map.showState(points&#x5B;i]);
    }
};

var showNextPoint = function () {
    var curPid;
    if ( ! canShow)
        return;
    if (currentI === null) {
        currentI = ORDER === 'random' ? Math.floor(Math.random()*1000) % points.length : 0;
    } else {
        hideCurrentPoint();
        if (ORDER === 'random') {
            do {
                var cI = Math.floor(Math.random()*1123) % points.length;
            } while (cI === currentI);
            currentI = cI;
        } else {
            currentI = currentI == points.length - 1 ? 0 : currentI + 1;
        }
    }
    showCurrentPoint();
};

var showCurrentPoint = function () {
    if (currentI === null)
        return;
    var curPid;
    curPid = points&#x5B;currentI];
    map.showState(curPid);
    map.stateHighlightIn(curPid);
};

var hideCurrentPoint = function (onlyTt) {
    if (currentI === null)
        return;
    var curPid;
    curPid = points&#x5B;currentI];
    map.stateHighlightOut(curPid);
    if (onlyTt) return;
    map.hideState(curPid);
};

hidePoints();

setInterval(showNextPoint, INTERVAL * 1000);
showNextPoint();

jQuery('#'+containerId).on('mouseenter', function (ev) {
    if (enTimer) {
        clearTimeout(enTimer);
        enTimer = false;
    }
    hideCurrentPoint(true);
    showPoints();
    canShow = false;
});

jQuery('#'+containerId).on('mouseleave', function (ev) {
    if (enTimer) {
        clearTimeout(enTimer);
        enTimer = false;
    }
    enTimer = setTimeout(function () {
        canShow = true;
        hidePoints();
        showCurrentPoint();
    }, 300);
});
</pre></div>


<h2 class="wp-block-heading">How to add Custom JS code in the plugin?</h2>



<p>On the Tools tab in the plugin settings there is a &#8220;Custom JavaScript&#8221; field where you can insert JS code.<br>See the following screenshot.</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://www.fla-shop.com/blog/wp-content/uploads/2019/01/tools-tab-custom-js.png" alt="Tools tab"/></figure></div>



<h2 class="wp-block-heading">Examples of other scripts to extend the functionality</h2>



<ul class="wp-block-list"><li><a href="https://www.fla-shop.com/blog/examples-of-custom-js-scripts/">How to highlight the state when you click on the map</a></li></ul>



<p>If you have any ideas for customization, we&#8217;d appreciate it if you&#8217;d share it with us.</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<p class="has-text-align-center"><a class="greenbutton" href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">Get try-for-free customizable US map for WordPress</a></p>
</div></div>
<p>The post <a href="https://www.fla-shop.com/blog/example-js-script-for-flashing-cities-on-a-map/">Example JS script for flashing cities on a map</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.fla-shop.com/blog/example-js-script-for-flashing-cities-on-a-map/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Real Examples Of Custom JS Scripts For WordPress Maps</title>
		<link>https://www.fla-shop.com/blog/examples-of-custom-js-scripts/</link>
					<comments>https://www.fla-shop.com/blog/examples-of-custom-js-scripts/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 04 Jan 2019 19:47:36 +0000</pubDate>
				<category><![CDATA[Empowerment with Custom JS]]></category>
		<guid isPermaLink="false">https://www.fla-shop.com/blog/?p=879</guid>

					<description><![CDATA[<p>Use some of these custom JS script examples to extend the functionality of Fla-shop.com interactive maps on your WordPress website.</p>
<p>The post <a href="https://www.fla-shop.com/blog/examples-of-custom-js-scripts/">Real Examples Of Custom JS Scripts For WordPress Maps</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>For the purpose of this read, we will be looking at how to add custom JS to your interactive maps, along with some real examples to help get you started. So without further ado, let&#8217;s get started!</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Which Plugins Are Compatible With Custom JS?</h2>



<p>Custom JS scripting is currently supported by all the single-level premium plugins like the <a href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">US map</a>, <a href="https://www.fla-shop.com/products/wp-plugins/world/countries/">World Map</a>, and so on.</p>



<p>You will find plenty of examples of JS codes on Fla-shop.com&#8217;s site which you can use to enhance the functionality of your interactive maps.</p>



<p>Here is an example showing how it is done:&nbsp;</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Example – Highlighting A State When It Is Clicked</h2>
</div></div>



<div class="wp-block-group article_lg_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained"> <!-- start Fla-shop.com HTML5 Map --> <div class='usaHtml5Mapright htmlMapResponsive' style='max-width:980px; width: 100%'><div id='usa-html5-map-map-container_1' class='usaHtml5MapContainer' data-map-variable='usahtml5map_map_1'></div> <style> #usa-html5-map-map-container_1 { } #usa-html5-map-map-container_1 .fm-tooltip-name { color: #000000; font-size: 20px; } #usa-html5-map-map-container_1 .fm-tooltip-comment { } #usa-html5-map-map-container_1 .fm-tooltip-comment p { } @media only screen and (max-width: 480px) { #usa-html5-map-map-container_1 { float: none; width: 100%; } } </style><script type="text/javascript"> jQuery(function(){ var hightlighted = null; usahtml5map_map_1 = new FlaShopUSAMap(usahtml5map_map_cfg_8); usahtml5map_map_1.draw('usa-html5-map-map-container_1'); usahtml5map_map_1.on('mousein', function(ev, sid, map) { if (hightlighted && sid != hightlighted) { map.stateHighlightOut(hightlighted); hightlighted = null; } }); (function (map, containerId, mapId) { var selected = null; map.on('click', function(ev, sid, map) { var was_selected = !!selected; if (selected && selected != sid) { map.stateHighlightOff(selected); selected = null; } var link = map.fetchStateAttr(sid, 'link'); if (link === '#info') { if (sid !== selected) map.stateHighlightOn(sid, '#FF0000', '#FFFFFF'); selected = sid; } if (!selected && was_selected) { jQuery('#'+containerId).parent().find('.usaHtml5MapStateInfo').html(''); } }); })(usahtml5map_map_1, 'usa-html5-map-map-container_1', 8); var html5map_onclick = function(ev, sid, map) { var cfg = usahtml5map_map_cfg_8; var link = map.fetchStateAttr(sid, 'link'); var is_group = map.fetchStateAttr(sid, 'group'); var popup_id = map.fetchStateAttr(sid, 'popup-id'); var is_group_info = false; if (typeof cfg.map_data[sid] !== 'undefined') jQuery('#usa-html5-map-selector_1').val(sid); else jQuery('#usa-html5-map-selector_1').val(''); if (is_group==undefined) { if (sid.substr(0,1)=='p') { popup_id = map.fetchPointAttr(sid, 'popup_id'); link = map.fetchPointAttr(sid, 'link'); } } else if (typeof cfg.groups[is_group]['ignore_link'] == 'undefined' || ! cfg.groups[is_group].ignore_link) { link = cfg.groups[is_group].link; popup_id = cfg.groups[is_group]['popup_id']; is_group_info = true; } if (link=='#popup') { if (typeof SG_POPUP_DATA == "object") { if (popup_id in SG_POPUP_DATA) { SGPopup.prototype.showPopup(popup_id,false); } else { jQuery.ajax({ type: 'POST', url: 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=8' + '&usahtml5map_get_popup', data: {popup_id:popup_id}, }).done(function(data) { jQuery('body').append(data); SGPopup.prototype.showPopup(popup_id,false); }); } } else if (typeof SGPBPopup == "function") { var popup = SGPBPopup.createPopupObjById(popup_id); popup.prepareOpen(); popup.open(); } return false; } if (link == '#info') { var id = is_group_info ? is_group : (sid.substr(0,1)=='p' ? sid : map.fetchStateAttr(sid, 'id')); jQuery('#usa-html5-map-state-info_1').html('Loading...'); jQuery.ajax({ type: 'POST', url: (is_group_info ? 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=8' + '&usahtml5map_get_group_info=' : 'https://www.fla-shop.com/blog/' + 'index.php' + '?map_id=8' + '&usahtml5map_get_state_info=') + id, success: function(data, textStatus, jqXHR){ jQuery('#usa-html5-map-state-info_1').html(data); }, dataType: 'text' }); return false; } if (ev===null && link!='') { if (!jQuery('.html5dummilink').length) { jQuery('body').append('<a href="#" class="html5dummilink" style="display:none"></a>'); } jQuery('.html5dummilink').attr('href',link).attr('target',(map.fetchStateAttr(sid, 'isNewWindow') ? '_blank' : '_self'))[0].click(); } }; usahtml5map_map_1.on('click',html5map_onclick); }); </script><div id='usa-html5-map-state-info_1' class='usaHtml5MapStateInfo'>Try clicking on the state</div> </div> <div style='clear: both'></div> <!-- end HTML5 Map --> 
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>By default, the plugin allows you to configure 2 colors for each state &#8211; <strong>default color</strong> and <strong>hover color</strong>. How about a third color &#8211; <strong>selected color</strong>? This can be easily added with some custom JS code.</p>



<p>Let&#8217;s consider this short JS snippet</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
var selected = null;
 
map.on('click', function(ev, sid, map) {
    var was_selected = !!selected;
    if (selected && selected != sid) {
        map.stateHighlightOff(selected);
        selected = null;
    }
    var link = map.fetchStateAttr(sid, 'link');
    if (link === '#info') {
        if (sid !== selected)
            map.stateHighlightOn(sid, '#FF0000', '#FFFFFF');
        selected = sid;
    }
    if (!selected && was_selected) {
        jQuery('#'+containerId).parent().find('.usaHtml5MapStateInfo').html('');
    }
});
</pre></div></div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">What Does This Code Do?</h2>



<p>This code is programmed to highlight states in your map when a user clicks on it.</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">How To Use The Code?</h2>



<p>There is a dedicated option under the tools tab of your Fla-shop.com interactive map settings panel where you can insert custom JavaScript.</p>



<figure class="wp-block-image"><img decoding="async" src="https://www.fla-shop.com/blog/wp-content/uploads/2019/01/tools-tab-custom-js.png" alt="Tools tab"/></figure>



<p>Just enter your JS code and click save and it&#8217;s done. It is so easy that any novice can do it. Furthermore, you don&#8217;t necessarily have to know JS to use this functionality.</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">How To Change The Color Of The Highlighted State?</h2>



<p>Notice the red arrow in the image below. It points to the HEX code used to specify the colors of the selected state. You can change the HEX code of any color you want to use in your interactive map.</p>



<figure class="wp-block-image"><img decoding="async" src="https://www.fla-shop.com/blog/wp-content/uploads/2019/01/custom-js-01.png" alt="Color for selected states"/></figure>



<p>In case, you don&#8217;t know the HEX code of the color you are looking for, simply Google, &#8220;hex code of [color name]&#8221; and you will get it.&nbsp;</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">How To Use This Code For Interactive Maps Of Other Countries?</h2>



<p>The provided JS snippet is for the Fla-shop.com US Interactive Map. If you want to use it for an interactive Map of another country, say Canada, then you need to tweak the code.</p>



<p>Search for the line</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
jQuery('#'+containerId).parent().find('.usaHtml5MapStateInfo').html('');
</pre></div>


<p>Locate the string: &#8216;<code>usaHtml5MapStateInfo</code>&#8216;<br>Change it to &#8211; &#8216;<code>canadaHtml5MapStateInfo</code>&#8216;<br>Similarly, if you want to use the code for the Map of India, use &#8216;<code>indiaHtml5MapStateInfo</code>&#8216;.</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Calling All Developers</h2>



<p>As you can see, Fla-shop.com interactive maps promise a lot of potential. They can host an array of features and functionalities based on custom JS scripts. If you are a developer with a new idea/functionality to add to the interactive maps, then we welcome your contribution. In return for your ingenuity, we promise to give you a free license to our premium plugin.&nbsp;</p>
</div></div>



<div class="wp-block-group article_sm_block"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">In Conclusion</h2>



<p>So this is how you can use custom JS codes to add extra features and functionalities to Fla-shop.com interactive maps. And even if you don&#8217;t have coding knowledge yourself, you can always use many of examples custom JS codes as shown in the article.</p>



<p class="has-text-align-center"><a class="greenbutton" href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">Get a try-for-free customizable US map for WordPress</a></p>
</div></div>
<p>The post <a href="https://www.fla-shop.com/blog/examples-of-custom-js-scripts/">Real Examples Of Custom JS Scripts For WordPress Maps</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.fla-shop.com/blog/examples-of-custom-js-scripts/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Adding Custom JavaScript to the Map Plugin</title>
		<link>https://www.fla-shop.com/blog/adding-custom-javascript-to-the-map/</link>
					<comments>https://www.fla-shop.com/blog/adding-custom-javascript-to-the-map/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 12 Jun 2018 16:21:53 +0000</pubDate>
				<category><![CDATA[Empowerment with Custom JS]]></category>
		<guid isPermaLink="false">https://www.fla-shop.com/blog/?p=564</guid>

					<description><![CDATA[<p>As of version 2.9.9.6, our WordPress map plugins support a new advanced feature. Now you can add custom JavaScript code to the map. This code executes after the map is drawn and has access to most of map’s properties. Thanks to this feature you can implement all kinds of interactive behavior previously impossible or hard to do.</p>
<p>The post <a href="https://www.fla-shop.com/blog/adding-custom-javascript-to-the-map/">Adding Custom JavaScript to the Map Plugin</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Enhancing capabilities of Map plugins for WordPress</h2>
</p>
<p>Our plugins are well-acclaimed for their extremely simple interface, so even a novice WordPress user can easily configure and embed an interactive map on his or her WordPress website. All settings are visual and do not require any coding. Settings cover colors, tooltips, adding points, grouping countries into regions, and other possibilities.</p>
</p>
<p>In the post <a href="https://www.fla-shop.com/blog/5-types-of-interaction-in-plugin-us-map-for-wordpress/">&#8216;5 Features of the US Map for WordPress Plugin,&#8217;</a> you can find some examples of map interaction that even a complete rookie can implement.<br />At the same time, our maps have JavaScript API, so experienced developers can implement complex and non-standard usage scenarios for plugins. And now this gets even simpler thanks to the custom JavaScript code field already added into the plugin settings.</p>
</p>
<p>The following update refers to the following products: <a href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">US Map for WP</a>, <a href="https://www.fla-shop.com/products/wp-plugins/world/countries/">World countries Map for WP</a>, as well as all single-level map plugins.</p>
</div>
</div>
</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">How custom JavaScript works</h2>
</p>
<p>Custom JavaScript code is executed when the map is drawn for the first time. Any further redraws of the map do not trigger the execution. However, if you have multiple instances of the map on the same page, each one will execute its own custom JS code.</p>
</p>
<p>In the script, you can use any JS code, such as: executing standard or custom functions, reading and writing values of variables, parsing the HTML document, and whatever else. In addition, in the script you have access to the following variables:</p>
</p>
<p><code><strong>map</strong></code> – an instance of the map that provides access to public methods of the map class. This includes callback handlers that allow you to perform certain actions in response to certain events (see below).</p>
</p>
<p>You can find the complete list of methods available to you <a href="https://docs.html5maps.com/html5-locator-maps/api" target="_blank" rel="noopener noreferrer">here</a>.</p>
</p>
<p><code><strong>containerId</strong></code> – this variable holds the HTML id of the container the map is placed to.</p>
</p>
<p>Example:</p>
</p>
<div class="wp-block-syntaxhighlighter-code ">
<pre class="brush: jscript; title: ; notranslate">&lt;/p&gt;
 map.on(&#039;click&#039;, function (event, sid, map) {
    var name = map.fetchStateAttr(sid, &#039;name&#039;);
    console.log(&#039;Clicked state is: &#039; + name);
 });
&lt;p&gt;</pre>
</div>
</div>
</div>
</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">How to add custom JavaScript to the map</h2>
</p>
<p>Open map settings and switch to the &#8216;Tools&#8217; tab. Scroll down to the Custom JavaScript section:</p>
</p>
<figure class="wp-block-image size-large"><img decoding="async" src="https://www.fla-shop.com/blog/wp-content/uploads/2018/06/custom-js.png" alt="Custom JS"/></figure>
</p>
<p>You can insert custom JavaScript code in the corresponding textbox. Click the &#8216;Save Changes&#8217; button.</p>
</p>
<p>Here is what the above example code does. It fetches the name of the state on the map that a user has clicked and prints that name to the console.</p>
</div>
</div>
</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">What can you do with custom JavaScript?</h2>
</p>
<p>Since you have access to most of the map object methods as well as to the HTML of the page, you can do almost anything. Let’s review some basic functions provided by the map object:</p>
</p>
<h3 class="wp-block-heading">Callback functions</h3>
</p>
<p>By using the <code>FlaMap.on</code> method you can assign a callback function to certain events including: on click, on double click, on mouse move, on mouse in, on mouse out, on mouse button down, and on mouse button up.<br />The callback function receives the original event that triggered the callback; the state id corresponding to the event (for example, if the event is a click, the function receives the id of the clicked state); the map object.</p>
</p>
<h3 class="wp-block-heading">Map state manipulation</h3>
</p>
<p>The map object provides a number of ways to view or modify various state settings: name, color, label, is a state is shown or hidden and is a state is enabled or not. You can also modify the URL assigned to a specific state.</p>
</p>
<h3 class="wp-block-heading">Points manipulation</h3>
</p>
<p>Map points are used to mark various objects on the map: headquarters, dealership network sites, local offices, and so on. Using custom JavaScript, you can track clicks on points, as well as change their parameters: label, color, size, coordinates, and assigned URL.</p>
</p>
<h3 class="wp-block-heading">Map drawing and overall appearance</h3>
</p>
<p>You can adjust the general settings of the map and initiate redrawing using the <code>map.reloadMap()</code> method.</p>
</p>
<p>Please refer to the <a href="https://docs.html5maps.com/html5-locator-maps/api">documentation</a> on the complete list and description of <code>FlaMap</code> methods.</p>
</div>
</div>
</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Examples of use</h2>
</p>
<h3 class="wp-block-heading">Auto-fill forms</h3>
</p>
<p>A map combined with a form can simplify filling in the data for a user.<br />For example, if a form has such fields as State or Country, then normally a user would have to manually type or select these values from the dropdown. With a map enhanced with custom JS code, you can simplify this down to just one click on the map.</p>
</p>
<p>What you need is to write a callback function and pass it to the <code>FlaMap.on</code> method. In the callback function, you fetch the name of the clicked state/country and insert the corresponding state/country values into the form.</p>
</p>
<h3 class="wp-block-heading">Select multiple states</h3>
</p>
<p>If you need to give your visitor the possibility to select multiple states, using custom JavaScript can help. We have reviewed a similar example for non-WordPress maps here: <a href="https://www.fla-shop.com/howto/interacting-with-maps-via-checkboxes/">https://www.fla-shop.com/howto/interacting-with-maps-via-checkboxes/</a></p>
</p>
<h3 class="wp-block-heading">Tracking clicks on states in Google Analytics</h3>
</p>
<p>A common use case of our map plugins is displaying a dealership map for a given country or state. When a state or a country is clicked on the map, the corresponding contact information displays side-by-side with the map. And now, if you want to know how often this or that state or country is clicked and see this info in Google Analytics, you can use custom JavaScript to integrate the map to GA and therefore see the map click data.</p>
</p>
<p>Specifically, you need to invoke Google Analytics scripts (analytics.js, gtag.js, etc) from your custom JS code.</p>
</div>
</div>
</p>
<div class="wp-block-group article_sm_block">
<div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 class="wp-block-heading">Conclusion</h2>
</p>
<p>As you see, custom JavaScript added to the interactive map can greatly enhance its basic functionality. Enjoy!</p>
</p>
<p class="has-text-align-center"><a class="greenbutton" href="https://www.fla-shop.com/products/wp-plugins/united-states/us/">Try United States map for WordPress for free</a></p>
</div>
</div>
<p>The post <a href="https://www.fla-shop.com/blog/adding-custom-javascript-to-the-map/">Adding Custom JavaScript to the Map Plugin</a> appeared first on <a href="https://www.fla-shop.com/blog">Fla-Shop.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.fla-shop.com/blog/adding-custom-javascript-to-the-map/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
