How do I create and use multiple independent components that depend on the same script (ie Google Maps API) in Backpack for Laravel? - laravel-backpack

I am trying to make a Create form in Laravel Backpack that has two fields: an address_google field, and a custom field based on https://github.com/abr4xas/gmaps-input-backpack, which includes the Google Maps API to render a map. Each includes an import of the Google Maps API. I'm looking for a way to build this map component as an independent backpack component, which depends on the Google Maps API, and I don't want to include the Google Maps API once for each component. Here's what I've found:
When both fields are allowed to use their default import, an error is thrown stating "You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors"
(image of the log here). On the actual page, the address_google field works, but the map doesn't render at all (seen here).
If I comment out the Google Maps import in the address_google field, the map does render, but the address_google field does not autocomplete (seen here).
If I comment out the Google Maps import in the map field, the address_google field will autocomplete, but the map will not render (seen here).
Finally, if I put the Google Maps import link in config/backpack/base.php in the scripts part of the array, and remove the Google Maps import on both the address_google field and map field, I can get both to render properly (seen here), but then the google maps API is imported into every admin panel in the application, and I don't want the Google Maps library to be included globally like this.
How would I include the Google Maps API, so that the two includes do not conflict each other? More generally, is there a recommended technique for creating independent Backpack components that depend on the same script when they will be used together on the same screen?

That's an interesting question. There's no default way to do that in Backpack, but here are two possible options:
Option (1) Only load the JS in your custom field type if address_google isn't loaded onpage:
{{-- resources/views/vendor/backpack/base/widgets/gmaps --}}
#if ($crud->fieldTypeNotLoaded(['type' => 'address_google']))
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=XXXXXXX&libraries=places&callback=initGoogleAddressAutocomplete" async defer></script>
#endif
Option (2) Create a Backpack widget with the script:
#push('after_scripts')
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=XXXXXXX&libraries=places&callback=initGoogleAddressAutocomplete" async defer></script>
#endpush
and add that widget only on Create and Update for this entity, in your setupCreateOperation() and/or setupUpdateOperation()
Widget::add([
'type' => 'gmaps_script',
]);
Of course, option 2 could be generalized as a script widget, where you pass the URL as a parameter, and maybe other attributes too.

Related

populating an input element within an flt-glass-pane in WebView

I have an Android application that has a WebView in it, it opens an external website that is supposed to be populated by my application. There is no issue populating it using javascript
(document.getElementById('id').value='something')
if it's an ordinary website.
However, the site that I am having trouble with is done in Flutter so it is making use of Dart.js. The form elements are not accessible and will always return null with any selector.
I have tried document.getElementsByTagName, document.querySelector and document.evaluate for xpath but the result is the same.
The goal of the application is to autofill the site with its profile data.
EDIT: I've done some reading and found out that it makes use of Shadow DOM which I am not familiar to, I was able to pull the value but it doesn't accept any changes
(document.firstChild.nextSibling.childNodes[2].childNodes[10].shadowRoot.childNodes[5].value)

Single Line Address for MapQuest

I'm trying to provide other map options besides just Google. Unfortunately a single HTTP query (e.g. location=123+main+street) only seems to be readily supported by Google.
I had no luck trying to find anything about embedding in the documentation and decided to email them directly:
The MapQuest business products
(https://developer.mapquest.com/documentation/) support both single
line input "location=1555+Blake+St+Denver+CO+80202+US" and the
advanced, 5-box method
("street=1555+Blake+St&city=Denver&state=CO&postalCode=80202&country=US").
Our API and SDK also lets you add the mapping/geocoding/routing
functions to your site without embedding links to the consumer site at
www.MapQuest.com.
Okay, so location=123+main+street should be supported in theory. However no example was provided. So using the iframe URL from the more client-oriented approach I tried the following without luck:
https://www.mapquest.com/embed/?location=1555+Blake+St+Denver+CO+80202+US
That just shows the map of the US as a whole.
How do I get the single HTTP query location to work for MapQuest embedding?
Correct: location=1555+Blake+St+Denver+CO+80202+US (single HTTP query).
Incorrect: street=1555+Blake+St&city=Denver (multiple HTTP queries).
It looks like a mix of MapQuest APIs and MapQuest.com. Check out the Link to MapQuest documentation. I think the Map a Location > Fielded Location is what you're after.
On this page: https://developer.mapquest.com/documentation/tools/link-to-mapquest/
Scroll down to Link to MapQuest Wizard.
Click on Map a Location.
Click on Single Line Location.
Click on the Run Sample with Embed View Specifier button.
Copy the URL from the new tab.
An example of the working MapQuest single HTTP query embedded page:
https://www.mapquest.com/embed/search/results?query=1555%20Blake%20St%20Denver%20CO%2080202&centerOnResults=1

How to correctly configure an Open Graph story with map attachment?

In a test app I've set up an object (race) and an action (run). I'm now trying to set up a story that combines both of these.
Ideally the race object references a place on my app. But I've been experimenting with many configurations trying to get this to work — none successfully.
In the 'edit attachment' popup is a field 'highlighted points'. I believe this should provide a dropdown list of selectable options? It currently is not, and if I type free text into this field, it is not saved.
What am I doing wrong?
The race page on my app includes the following:
And the course pages include
>>>' />
>>' %> />
On Facebook, course is configured as a Place, race has the course property assigned. But I am unable to select race.course:location in the map popup.
I have also tried various configurations, including defining the lat/lon explicitly on the race page and defining appropriate properties on FB.
I am still unable to select the highlighted points value.
Am I missing something?
Have a look at the answer at
Open Graph Map layout
This should be able to guide you.
Also
https://developers.facebook.com/docs/reference/opengraph/object-type/place/#properties

How to integrate DTM (Dynamic Tag Management) with AEM 6?

I am a newbie to Adobe DTM (Dynamic Tag Management) and have not done any kind of training related to it. However, I have been given a requirement to integrate DTM with AEM 6. I Have some requirements related to Omniture where certain events on the website are tracked and that information needs to be sent to DTM. I have followed steps described on this blog (http://blogs.adobe.com/aemtutorials/2013/07/24/customize-the-client-context/) to customize the client context by creating a new session store and storing some sample data inside it. Now, next part is to retrieve this data into DTM which I am completely unaware on how to do. What is need to achieve in particular is to create a new data element as shown in the screenshot below and write some custom java script to access the data stored inside the client context (which is present in the session store) as explained in the blog mentioned.
I have no idea on how to integrate DTM with AEM instance and how to get hold of that data needed using the script. There is no info available on the internet regarding this, hence request you to help me in case anybody have worked on such a requirement earlier. Any help is highly appreciated
Step 1 - Set up DTM cloud services configuration in AEM. You may find cloud services config at /etc/cloudservices/dynamictagmanagement.html
Step 2 - Apply the above cloud config to the root of your website using the page property. This will insert the required JS scripts and JS object into the DOM. You could also do step (1) & (2) together by manually inserting header and footer code (from DTM) into the template.
Step 3 - Supply data to DTM JS object. This you could populate the data from server side or at client side using JS. You could leverage client context as well. JS APIs available to query client context.
PS: Am also a learner on this.
Helpful links:
http://blogs.adobe.com/experiencedelivers/experience-management/integrating-dtm-custom-aem6-page-template/
http://docs.adobe.com/docs/en/aem/6-0/administer/integration/marketing-cloud/dtm.html
You can use data elements with custom script like this:
e.g. dataElement authorizableId is custom script with content
return CQ_Analytics.ClientContext.get("/profile/authorizableId");
or
dataElement pageTitle
return CQ_Analytics.PageDataMgr.getProperty("title”);
This is how I implemented it. Please note that this implementation is for integrating with flat HTML files. Where we need to add the scripts in Head tag.
Pre-requisites:
1. We need to have login credentials for DTM website.
We need to have admin rights.
We need sc3.omniture site credentials. This is usually provided by Adobe team.
From Omniture console we need to generate the AppMeasurement.js file.
From AppMeasurement.js file we need to get important details like:
a. Tracking Server Name
b. s_account name
c. Visitor namespace
Connecting HTML files to DTM:
Login to https://dtm.adobe.com with admin credentials.
Click on Project dashboard
Click on Embed tab on top navigation.
Enable Host on Akamai.
Expand Header Code widget and copy the code.
Paste that code in the tag of your HTML.
Go back to DTM again. Expand Footer Code widget and copy the code.
Paste that code to the tag of your HTML.
Configuring DTM for Direct Call Rules:
1. Go to Rules tab from top navigation.
2. Click on Direct Call Rules from left navigation now.
Click on create rule.
Give it a name in the Name section.
Expand Conditions widget.
Pay close attention to the Conditions textbox. Direct Call Rules are fired using the _satelitte.track() method, and the text you enter in the Conditions textbox will be the argument you pass in this method. We entered “change-offer-submit”, so to fire this Direct Call Rule, we will use _satelitte.track(“change-offer-submit”) as you will see in the code below.
Now use the Adobe Analytics section to set up a custom link.
Below is the code that sets up our form and its validation. Notice the way the DTM _satelitte.track() is used. Each of the arguments passed in the _satelitte.track() method matches the Condition textbox in separate DTM rules.
HTML
<div class="outer-btn">
<input class="input-btn analyticsEvent" type="button" value="Submit" data-eventName="change-offer-submit">
</div>
JavaScript
<script>
jQuery('.analyticsEvent').on('click',function() {
window.console.log('Logged Event: ' + jQuery(this).attr('data-eventName'));
_satellite.track(jQuery(this).attr('data-eventName'));
location.href='./landingPage.html';
});
</script>
This has been superseded by a tool added to DTM in the June 2016 release, ContextHub was added in 6.1 as beta, in 6.2 it reached feature parity with ClientContext. It saves a lot of time building data layers as a lot of it will be there already .

Bing maps pushpins in REST

I am using bing maps REST services and I need to add pushpins but surprisingly it's giving me a hard time. I found out how to easily add pushpins in AJAX services, but that would need me to include scripts and stuff to my pages which I'd really rather skip. I tried searching the internet for information on how to add pushpins in REST ( or simply an iframe with a URL ) but I failed to find any useful such. Does anyone know how I can add pushpins in REST?
EDIT: I'm using dynamic maps based on this link http://www.bing.com/maps/embed/viewer.aspx?showCopyright=false&cp=43.835109710693~25.957630157471&lvl=1&w=250&h=350&sty=r
Assuming that you are using the Bing Maps Imagery REST service, you will be able to add pushpin based on the URL parameters, see the MSDN: http://msdn.microsoft.com/en-us/library/ff701724.aspx
Here is an sample request that will allow you to add pushpins, take a look at the pp parameter:
http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.619048,-122.35384/15?mapSize=500,500&pp=47.620495,-122.34931;21;AA&pp=47.619385,-122.351485;;AB&pp=47.616295,-122.3556;22&key=BingMapsKey
If you are using embedded maps, here is the list of parameters: http://msdn.microsoft.com/en-us/library/ee692180.aspx