Linked Maps in GVH;
Hi All,
I tried to integrate google maps with an HTML5 viewer and I followed the steps in the Administrator and Developer Guide manual, but still Google Maps is not working, I get a blank map as shown in the below screenshot:
_img_ alt="User-added image" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=90660000000PDk5&feoid=Body&refid=0EM60000000HSrG" _/_img_
I changed the code in the following files:
1. Desktop.json.js (Directory: C:\Program Files (x86)\Latitude Geographics\Geocortex Essentials\Default\REST Elements\Sites\xxxxx\Viewers\x\VirtualDirectory\Resources\Config\Default)
"externalComponents": [
{
"id": "googleMaps",
"displayName": "Google Maps",
"uri": "Resources/3rdPartyMaps/GoogleMaps.html",
"viewpointIndicatorUri": "Resources/Images/Icons/location-direction-blue-32.png"
}
2. GoogleMaps.html (Directory: C:\inetpub\wwwroot\x\Resources\3rdPartyMaps)
<!DOCTYPE html>
<html>
<head>
<title>Bing Maps</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link href="3rdParty.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script src="../Scripts/Bridge.js"></script>
<script src="ThirdPartyMap.js"></script>
<script type="text/javascript">
var bingApiKey = "";
var map;
var currentZoom = 10;
var isReady = false;
var thirdPartyMap = new geocortex.essentialsHtmlViewer.integration.ThirdPartyMap("googleMaps",
initializeMap,
getMapViewpointParams,
handleViewerPositionUpdatedEvent,
handleViewpointIndicatorUpdatedEvent);
/**
* Initializes the google map.
*/
function initializeMap() {
var location = new google.maps.LatLng({lat: 0, lng: 0});
var mapOptions = {
//credentials: bingApiKey,
center: location,
// mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
zoom: currentZoom,
MapTypeControl: true,
streetViewControl: true,
rotateControl: true
// enableSearchLogo: false,
// showDashboard: true
};
map = new google.maps.Map(document.getElementById("map-container"), mapOptions);
}
/**
* Gets the current position of the Bing map.
*/
function getMapViewpointParams() {
var pos = map.getCenter();
var scale = thirdPartyMap.zoomLevelToScale(map.getZoom());
return {
center: {
x: pos.lng(),
y: pos.lat()
},
scale: scale,
heading: map.getHeading()
};
}
/**
* Updates the Bing map to match the viewer.
*/
function handleViewerPositionUpdatedEvent(arg) {
if (!isReady) {
// Add handlers after we have received our first position
// Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function () {
// thirdPartyMap.handleViewpointChanged();
map.addListener('center_changed', function() {
thirdPartyMap.handleViewpointChanged();
});
isReady = true;
}
currentZoom = thirdPartyMap.scaleToZoomLevel(arg.scale);
map.setCenter(new google.maps.LatLng({lat: arg.position.y, lng: arg.position.x}) );
map.setZoom(currentZoom);
// map.setView({ zoom: currentZoom, center: new Microsoft.Maps.Location(arg.position.y, arg.position.x) });
}
/**
* Updates the Bing map to match the viewpoint indicator position.
*/
function handleViewpointIndicatorUpdatedEvent(arg) {
map.setCenter(new google.maps.LatLng({lat: arg.y, lng: arg.x}) );
//map.setView({ center: new Microsoft.Maps.Location(arg.y, arg.x), animate: false });
}
</script>
</head>
<body>
<ul class="integration-panel-actions">
<li class="panel-action-button">
<button class="viewpoint-indicator viewpoint-indicator-bing" title="Viewpoint Indicator"></button>
</li>
<li class="panel-action-button">
<button id="centerButton" class="center-map" title="Center this map to the viewer"></button>
</li>
<li class="panel-action-button">
<button id="syncButton" class="sync-toggle-off" title="Synchronize Maps"></button>
</li>
<li class="panel-action-button">
<button id="dockButton" class="window-popout" title="Open in new window"></button>
</li>
<li class="panel-action-button">
<button id="closeButton" class="window-close" title="Close this map view"></button>
</li>
</ul>
<div id="map-container" class="map-container"></div>
</body>
</html>
What might be the issue here?
Thanks in advance,
Lubna
0
-
It's hard to tell with all the Bing map stuff commented out. Did you include the extra script tag with your google API key? 0 -
Hi Odiri, 0 -
You need to add that line for the google map to work. A Google API Key is free to get. Here's a link that better explains it: 0 -
Also, I may have misunderstood you before, but in that script tag, there's a part that says "key=YOUR_GOOGLE_API_KEY". You'll have to replace the "YOUR_GOOGLE_API_KEY" with the api key that you receive from google. 0 -
I wonder why it is not as simple as what we have in GVS? The linked maps appear straightaway 0 -
Hi Odiri 0 -
Hello Lubna, <!DOCTYPE html> <html> <head> <title>Google Maps</title> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <link href="3rdParty.css" rel="stylesheet" type="text/css" /> <link href="https://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="https://maps.google.com/maps/api/js?key={YOUR_GOOGLE_API_KEY_HERE}"></script> <script src="../Scripts/Bridge.js"></script> <script src="ThirdPartyMap.js"></script> <script type="text/javascript"> /* * jQuery throttle / debounce - v1.1 - 3/7/2010 * http://benalman.com/projects/jquery-throttle-debounce-plugin/ * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); </script> <script type="text/javascript"> var map; var currentZoom = 10; var isReady = false; var thirdPartyMap = new geocortex.essentialsHtmlViewer.integration.ThirdPartyMap("googleMapsAerial", initializeMap, getMapViewpointParams, handleViewerPositionUpdatedEvent, handleViewpointIndicatorUpdatedEvent); /** * Initializes the google map. */ function initializeMap() { var mapOptions = { zoom: currentZoom, mapTypeId: google.maps.MapTypeId.HYBRID }; map = new google.maps.Map(document.getElementById("map-container"), mapOptions); } /** * Gets the current position of the google map. */ function getMapViewpointParams() { var pos = map.getCenter(); var scale = thirdPartyMap.zoomLevelToScale(map.getZoom()); return { center: { x: pos.lng(), y: pos.lat() }, scale: scale }; } /** * Updates the google map to match the viewer. */ function handleViewerPositionUpdatedEvent(arg) { if (!isReady) { // Add handlers after we have received our first position google.maps.event.addListener(map,'bounds_changed', function() { thirdPartyMap.handleViewpointChanged(); }); isReady = true; } currentZoom = thirdPartyMap.scaleToZoomLevel(arg.scale); var ltlng = new google.maps.LatLng( arg.position.y,arg.position.x) map.setCenter(ltlng); map.setZoom(currentZoom); } /** * Updates the google map to match the viewpoint indicator position. */ function handleViewpointIndicatorUpdatedEvent(arg) { var ltlng = new google.maps.LatLng(arg.y,arg.x) map.setCenter(ltlng); } </script> </head> <body> <ul class="integration-panel-actions"> <li class="panel-action-button"> <button class="viewpoint-indicator viewpoint-indicator-bing" title="Viewpoint Indicator"></button> </li> <li class="panel-action-button"> <button id="centerButton" class="center-map" title="Center this map to the viewer"></button> </li> <li class="panel-action-button"> <button id="syncButton" class="sync-toggle-off" title="Synchronize Maps"></button> </li> <li class="panel-action-button"> <button id="dockButton" class="window-popout" title="Open in new window"></button> </li> <li class="panel-action-button"> <button id="closeButton" class="window-close" title="Close this map view"></button> </li> </ul> <div id="map-container" class="map-container"></div> </body> </html>
0 -
Hey Lubna, 0 -
Hi again, <!DOCTYPE html> <html> <head> <title>Google Maps</title> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <link href="3rdParty.css" rel="stylesheet" type="text/css" /> <link href="https://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="https://maps.google.com/maps/api/js?key=AIzaSyBkP23lKSYOQaKh485NHpj2LwAZbxdXLkQ"></script> <script src="../Scripts/Bridge.js"></script> <script src="ThirdPartyMap.js"></script> <script type="text/javascript"> /* * jQuery throttle / debounce - v1.1 - 3/7/2010 * http://benalman.com/projects/jquery-throttle-debounce-plugin/ * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); </script> <script type="text/javascript"> var map; var currentZoom = 10; var isReady = false; var thirdPartyMap = new geocortex.essentialsHtmlViewer.integration.ThirdPartyMap("googleMapsAerial", initializeMap, getMapViewpointParams, handleViewerPositionUpdatedEvent, handleViewpointIndicatorUpdatedEvent); /** * Initializes the google map. */ function initializeMap() { var mapOptions = { zoom: currentZoom, mapTypeId: google.maps.MapTypeId.HYBRID }; map = new google.maps.Map(document.getElementById("map-container"), mapOptions); } /** * Gets the current position of the google map. */ function getMapViewpointParams() { var pos = map.getCenter(); var scale = thirdPartyMap.zoomLevelToScale(map.getZoom()); return { center: { x: pos.lng(), y: pos.lat() }, scale: scale }; } /** * Updates the google map to match the viewer. */ function handleViewerPositionUpdatedEvent(arg) { if (!isReady) { // Add handlers after we have received our first position google.maps.event.addListener(map,'bounds_changed', function() { thirdPartyMap.handleViewpointChanged(); }); isReady = true; } currentZoom = thirdPartyMap.scaleToZoomLevel(arg.scale); var ltlng = new google.maps.LatLng( arg.position.y,arg.position.x) map.setCenter(ltlng); map.setZoom(currentZoom); } /** * Updates the google map to match the viewpoint indicator position. */ function handleViewpointIndicatorUpdatedEvent(arg) { var ltlng = new google.maps.LatLng(arg.y,arg.x) map.setCenter(ltlng); } </script> </head> <body> <ul class="integration-panel-actions"> <li class="panel-action-button"> <button class="viewpoint-indicator viewpoint-indicator-bing" title="Viewpoint Indicator"></button> </li> <li class="panel-action-button"> <button id="centerButton" class="center-map" title="Center this map to the viewer"></button> </li> <li class="panel-action-button"> <button id="syncButton" class="sync-toggle-off" title="Synchronize Maps"></button> </li> <li class="panel-action-button"> <button id="dockButton" class="window-popout" title="Open in new window"></button> </li> <li class="panel-action-button"> <button id="closeButton" class="window-close" title="Close this map view"></button> </li> </ul> <div id="map-container" class="map-container"></div> </body> </html>
0 -
I'm assuming is it something to do with your api key. I used your key and got the same screen as you. Using the recommendation to view the javascript console, the error I recieved was
"Google Maps API error: RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error Your site URL to be authorized: https://gis.miottawa.org/Ottawa/Geocortex/GE451/html5/Resources/3rdPartyMaps/GoogleMapsAerial.html"
Which is a good thing, that means no one else can use your api key from a different domain, only you can host it. You can open the console in most browsers by pressing ctrl+shift+j together or in the developer options in the menu tools.0 -
Hi Marshall, 0 -
Lubna, 0 -
Hi Marshall, 0 -
Hi All 0 -
Hi Majdoleen, 0 -
Hi all,
Dave
0 -
Hi Dave,
With the recent changes to Google Maps accounts, you will likely want to restrict your API key's usage given that it is no longer free. See this post for more information: https://support.geocortex.com/essentialsGSCkba?sub-nav=kba&main-nav=essentials&#!/feedtype=SINGLE_ARTICLE_DETAIL&dc=All_Essentials_kba&criteria=BESTANSWERS&id=kA3f2000000k9cB
0 -
Hi Stefan, 0
Please sign in to leave a comment.
Comments
18 comments