Last active
February 15, 2019 14:57
-
-
Save skorasaurus/ebc8f78780b1f5a035a622bcb2a5a0f2 to your computer and use it in GitHub Desktop.
my-mapbox-code.js is a ; Is using shortcodes a best practice? ; why can't I just bind it other more complex examples are at https://www.mapbox.com/mapbox.js/example/v1.0.0/markercluster-custom-polygon-appearance/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function enqueue_scripts() { | |
/** | |
you can remove the if statement if you want the script to load on all pages; | |
locations is the page's slug | |
*/ | |
if (is_page( 'locations' )) { | |
wp_register_style('mapbox_css', 'https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css'); | |
wp_register_script('mapbox_js', 'https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js', '', '', true); | |
wp_register_script('mapbox_custom', get_stylesheet_directory_uri().'/js/my-mapbox-code.js', [ 'mapbox_js' ], '', true); | |
wp_enqueue_style('mapbox_css'); | |
wp_enqueue_script('mapbox_js'); | |
wp_enqueue_script('mapbox_custom'); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'enqueue_scripts', 4); | |
function display_mapbox_map() { | |
ob_start(); | |
?> | |
<div id="mapid"></div> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode('mapbox_shortcode', 'display_mapbox_map'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this will be deactivated in a couple weeks anyways. | |
L.mapbox.accessToken = 'pk.eyJ1Ijoic2tvcmFzYXVydXMiLCJhIjoiY2pzNjZleGM0MDl6bDQzbWx3bW9kMzVrNSJ9.HWcJ1KptAncGPZvZW9Z6Sg'; | |
var myMap = L.mapbox.map('mapid', 'skorasaurus.0d3d48ab').setView([41.51783221717116, -81.68334960937501], 11); | |
// your server must have CORS enabled! | |
// var featLayer = L.mapbox.featureLayer().loadURL('MYGEOJSONURL').addTo(myMap); | |
// featLayer.on('ready', function() { | |
// featLayer.eachLayer(function(tehLayer) { | |
// popupContent = '<a href="'+tehLayer.feature.properties.shortlink+'">'+tehLayer.feature.properties.name +'</a><br>' + tehLayer.feature.properties.housenumber + ' ' + tehLayer.feature.properties.street+ '<br>' + | |
// '<a href="https://www.google.com/maps/search/'+tehLayer.feature.properties.housenumber + ' ' + tehLayer.feature.properties.street+ " Cleveland" + ' ' + tehLayer.feature.properties.postcode + '">'+' Get directions </a>'; | |
// tehLayer.bindPopup(popupContent); | |
// }); | |
// }).addTo(myMap); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#mapid { | |
width: 80%; | |
height: 320px; | |
position: relative; | |
margin-bottom: 3em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment