), elements using an ID, and classes if you use a '.' to prefix the class name.
Usage to remove our postData tag that indicates that LD+Json is being used: removeStr(value, "postData")
Usage to remove the 'foo' class from a string: removeStrBetween(str, '.foo');
*/
var removeStrBetween = function(str, selector) {
// Create a new container to operate on
var wrapped = $("
" + str + "
");
// Remove the content between the tags.
wrapped.find(selector).remove();
// Return it
return wrapped.html();
}
// Function to truncate and add an elipsis if the text exceeds a certain value
function truncateWithEllipses(text, max) {
return text.substr(0,max-1)+(text.length>max?'...':'');
}
function stripHtml(html){
html.replace(/<[^>]*>?/gm, '');
return html;
}
// Determine if a string has a space
function hasWhiteSpace(s) {
const whitespaceChars = [' ', '\t', '\n'];
return whitespaceChars.some(char => s.includes(char));
}
// ColdFusion like string functions
// ReplaceNoCase, scope is either 'all' or 'one'.
// Gregory Alexander
function replaceNoCase(string,subString,replacement, scope){
if (scope == 'all'){
// i is a RegEx ignore case flag, g is global flag
var regEx = new RegExp(subString, "ig");
} else {
// i is an RegEx ignore case flag
var regEx = new RegExp(subString, "i");
}
// i is an ignore case flag, g is global flag
var regEx = new RegExp(subString, "ig");
var result = string.replace(regEx, replacement);
return result;
}
// ColdFusion like list functions
function listLen(list, delimiter){
// Gregory Alexander
if(delimiter == null) { delimiter = ','; }
var thisLen = list.split(delimiter);
return thisLen.length;
}
function listGetAt(list, position, delimiter, zeroIndex) {
// Gregory Alexander
if(delimiter == null) { delimiter = ','; }
if(zeroIndex == null) { zeroIndex = true; }
list = list.split(delimiter);
if(list.length > position) {
if(zeroIndex){
// Better handling for JavaScript arrays
return list[position];
} else {
// Handles like the CF version without a zero-index
return list[position-1];
}
} else {
return 0;
}
}
function listFind(list, value, delimiter) {
// Adapted from a variety of sources by Gregory Alexander
var result = 0;
if(delimiter == null) delimiter = ',';
list = list.split(delimiter);
for ( var i = 0; i < list.length; i++ ) {
if ( value == list[i] ) {
result = i + 1;
return result;
}
}
return result;
}
// Compares two lists of comma seperated strings. Used to determine if the selected capabilities match the default capabilities for a given role. Function based on the listCompare method found in cflib.
function listCompare(string1, string2){
// Adapted from a variety of sources by Gregory Alexander
var s = string1.split(",");
for(var k = 0 ;k < s.length; k++){
if(string2.indexOf("," + s[k] + ",") ){
return true;
}
}
return false;
}
// Adds a value to a comma separated list. Will not add the value if the list already contains the value.
function listAppend(list, value) {
// Adapted from a variety of sources by Gregory Alexander
var re = new RegExp('(^|\\b)' + value + '(\\b|$)');
if (!re.test(list)) {
return list + (list.length? ',' : '') + value;
}
return list;
}
// Removes a value to a comma separated list. Based on the ListDeleteValue function by Ben Nadel CF fuction https://gist.github.com/bennadel/9753040
var listDeleteValue = function(list, value){
// Adapted from a variety of sources by Gregory Alexander
var values = list.split(",");
for(var i = 0 ; i < values.length ; i++) {
if (values[i] == value) {
values.splice(i, 1);
return values.join(",");
}
}
return list;
}
// URL functions
//
// parseUri 1.2.2
// (c) Steven Levithan
// MIT License
/*
Splits any well-formed URI into the following parts (all are optional):
----------------------
- source (since the exec method returns the entire match as key 0, we might as well use it)
- protocol (i.e., scheme)
- authority (includes both the domain and port)
- domain (i.e., host; can be an IP address)
- port
- path (includes both the directory path and filename)
- directoryPath (supports directories with periods, and without a trailing backslash)
- fileName
- query (does not include the leading question mark)
- anchor (i.e., fragment) */
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});
return uri;
};
parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};
// Dump function. Use like you would with cfdump.
// function to dump out a a javascript object.
function mydump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
var level_padding = "";
for(var j=0;j \"" + value + "\"\n";
}
}
} else {
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
console.log(dumped_text);
}
Bing Maps has been around since 2005. Today, Bing Maps offers a bird's-eye view, satellite imaging, real-time traffic and directions. While Google Maps is the undisputed mapping leader, Bing Maps has some advantages. Google has better in-depth coverage, but Bing Maps often offers superior aerial and 3D imagery. Most developers find Bings API to be more intuitive, and easier to implement custom mapping solutions. Additionally, Bing Maps is more generous and straightforward with its free tier pricing. For the casual or low to medium-volume blogger who is looking for a low-cost mapping API, I believe that Bing Maps is the better choice and hope to show you how you can use Bing Maps in your blog in the next several articles.
Bing Maps vs. Google Maps Cost Analysis
On paper alone, it seems like Google Maps is more generous with its free tier. For example, Bing Maps offers 125k map loads per year and Google Maps offers 28,500 map loads a month for a free developer license. However, what constitutes a 'mapload' is quite different between the two providers. Google considers an autosuggest returned from its API a map load, and Google charges more for a dynamic map, where the user can pan and zoom than it does for a static map that does not allow for user interaction. Google's pricing is rather complex and can quickly add up when creating sophisticated mapping applications. Bing Maps pricing is more straightforward, and unlike Google Maps- you don't need to provide a credit card when signing up for a Bing Maps Developer Key.
Get a Free Bing Maps Key
To get a Bing Maps API Key, go tohttps://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key,and follow the directions. Unless you plan on having unusually busy traffic, you should not have to pay for an enterprise plan. I have used Bing Maps on my sites for a couple of years, and although I don't have high-volume sites- I have come nowhere near the 130k map-view limit per year threshold for the free tier.
Outputting a Basic Dynamic Map Using the Bing Maps API
The following code will display a map of the San Juan Islands in Washington State. As you can see, generating dynamic maps on a webpage with the Bing Maps API is quite simple. Click on the button below to explore an interactive map that this code generates. I will delve into the details of a dynamic static map in the next article.
<script type='text/javascript'>
function getSanJuans() {
// Create a location. This takes the latitude and longitude, separated by a comma
var fridayHarbor = new Microsoft.Maps.Location(48.5348,-123.016);
// Map declaration
var sanJuans = new Microsoft.Maps.Map(document.getElementById('sanJuans'), {
// Center our map
center: fridayHarbor,
// Use an aerial image
mapTypeId: Microsoft.Maps.MapTypeId.aerial,
// Zoom out a little bit to get all of the islands
zoom: 11
});
}
</script>
<!-- Map control -->
<script type='text/javascript' src='https://sdk.virtualearth.net/api/maps/mapcontrol?key=yourBingMapKey&callback=getSanJuans' async defer></script>
<div id="sanJuans" style="width:100%;height:100%"></div>
Hi, my name is Gregory! I have several degrees in computer graphics and multimedia authoring, and I have been developing enterprise web applications for the last 25 years. I love web technologies and the outdoors and am passionate about giving back to the community.
This entry was posted on October 7, 2023 at 12:53 AM and has received 2251 views.