ExtJS Google Map SetCenter ERROR - google-maps

var layout = Ext.create('Ext.panel.Panel', {
//renderTo: 'layout',
width: window.innerWidth,
height: window.innerHeight,
//title: 'Border Layout', //no title will be blank
layout: 'border',
items: [{
title: 'Message List',
region: 'south', // position for region
xtype: 'panel',
height: 100,
split: true, // enable resizing
collapsible: true,
margins: '0 5 5 5',
collapsed: true
},tree,{
xtype: 'gmappanel',
region: 'center',
id : 'mygooglemap',
center: new google.maps.LatLng(3.951941, 102.052002),
mapOptions: {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
}],
renderTo: Ext.getBody() //get the body and display Layout at there
});
});
function addInfoWindow(lat,lng) {
var map123 = Ext.getCmp('mygooglemap');
var latLng = new google.maps.LatLng(lat, lng);
map123.SetCenter(latLng);
}
how come i can't set the map to center of the coordinate?
Firebug with this error
TypeError: map123.setCenter is not a function
[Break On This Error]
map123.setCenter(latLng);
EDITED
where is my GMapPanel.js download from https://raw.github.com/VinylFox/ExtJS.ux.GMapPanel/master/src/GMapPanel3.js
then i put it in my localhost/ux/GMapPanel3.js
and this is my config before use the GMapPanel
Ext.Loader.setPath('Ext.ux', 'ux/');
Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.window.MessageBox',
'Ext.window.*',
'Ext.ux.GMapPanel'
]);
but fail to set Center , why?

I am assuming that you are using the plugin from here: https://github.com/VinylFox/ExtJS.ux.GMapPanel
Assuming that is true, from looking at the code it looks like you need to use getMap() on your gmappanel before calling setCenter():
map123.getMap().setCenter(latLng);
Or, you can specify the setCenter property when configuring the gmappanel:
{
xtype: 'gmappanel',
region: 'center',
id : 'mygooglemap',
setCenter: {
lat: 3.951941,
long: 102.052002
},
mapOptions: {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
}
One of the great things about ExtJS/Javascript is that you have access to the code of all of your libraries. When you see errors like "xxx is not a function", it should be pretty self-explanatory: the function you are trying to use is not available on the object on which you are calling it.

Related

how to add google map as a ui component in magento 2

i need to display a coordinates field , coming from database, currently am displaying it as an input like this:
i need to display it as map like this:
i googled a LOT and lot of answers on how to load the map using requireJS , but non is working with Magento 2.1..
currently am at this stage:
requirejs.config({
paths: {
googlemaps: 'googlemaps',
async: 'requirejs-plugins/src/async'
},
googlemaps: {
params: {
key: 'xxxxxxxxxxxxxx'
}
}
});
define([
'Magento_Ui/js/form/element/abstract',
'jquery',
'googlemaps!'
],function(Abstract,$,gmaps) {
return Abstract.extend({
initialize: function () {
return this._super();
},
initMap: function() {
console.log(this.value());
console.log("-------------");
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
},
});
});
now , question is how to call the initMap function after page is loaded ?
help pleaaaaase

Zoom button has been missed on my google map today! (Openlayers, Geoext)

I had a map which overlays Google street map plus some WMSs. It was working till yesterday, but, suddenly today I can see the map, but zoom button is missed! I am using Google map API v2, Openlayaers and Geoext APIs. My code is:
Ext.onReady(function () {
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
numZoomLevels: 18,
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
};
var map = new OpenLayers.Map(options);
var gmap = new OpenLayers.Layer.Google(
"Google Streets",
{ isBaseLayer: true, numZoomLevels: 20, sphericalMercator: true }
);
map.addLayer(gmap);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{ type: G_SATELLITE_MAP, 'sphericalMercator': true, numZoomLevels: 20 }
);
map.addLayer(gsat);
var mappanel = new GeoExt.MapPanel({
region: "center",
map: map,
title: 'Map Layers on Google'
});
var layerList = new GeoExt.tree.LayerContainer({
text: 'Map Layers',
layerStroe: mappanel.layers,
leaf: false,
expanded: true
});
var layerTree = new Ext.tree.TreePanel({
title: 'Map Layers',
maxWidth: 500,
Width: 300,
region: "west",
collapsible: true,
collapsed: true,
root: layerList,
split:true
});
var descriptionPanel = new Ext.Panel({
title: 'Metadata Description',
Width: 400,
region: "east",
contentEl: "description",
collapsible: true,
collapsed: false,
split:true
});
var mainPanel = new Ext.Panel({
height: 800,
renderTo: "mainpanel",
layout: "border",
items: [mappanel, layerTree, descriptionPanel]
});
Is there anybody here who could let me know what happened when everything was working!
By the way, I received an email by google couple of days ago that google map v2 is has expired and will be down next month! Maybe they shutdown it earlier!
Cheers,
I think this is related to Google Map API v2. As soon as I switched to using v3, this problem solved.
Here in Openlayers example, the same problem is observable.
http://openlayers.org/dev/examples/google.html
I've the same problem. Nobody knows what has changed on API v2? With V3 it's all OK http://openlayers.org/dev/examples/google-v3.html

Sencha Touch: Maxium call stack size exceeded (google maps)

I've been trying to get google maps to work on my sencha touch page but it just won't work.
Ive found a lot of topics on this problem, but I can't seem to find the problem in my code. Basically at the moment I'm trying to put a marker on my current location with google maps. Later I will try to show a route based on a given adress. But when I open the page I only see the interface elements of the map. It keeps saying the following in my element inspector in chrome:
Uncaught RangeError: Maximum call stack size exceeded
ze
F.get
F.get
(anonymous function)
F.transform_changed
ag
ag
F.set
Rs.(anonymous function).ta
F.aa
Qh.(anonymous function).l
(anonymous function)
O.trigger
F.aa
Qh.(anonymous function).l
(anonymous function)
O.trigger
F.aa
Qh.(anonymous function).l
(anonymous function)
O.trigger
I just noticed I am also getting the following messages in element inspector:
Resource interpreted as Font but transferred with MIME type font/woff: "http://themes.googleusercontent.com/static/fonts/roboto/v9/Hgo13k-tfSpn0qi1SFdUfT8E0i7KZn-EPnyo3HZu7kw.woff".
Resource interpreted as Font but transferred with MIME type font/woff: "http://themes.googleusercontent.com/static/fonts/roboto/v9/2UX7WLTfW3W8TclTUvlFyQ.woff".
Resource interpreted as Font but transferred with MIME type font/woff: "http://themes.googleusercontent.com/static/fonts/roboto/v9/RxZJdnzeo3R5zSexge8UUT8E0i7KZn-EPnyo3HZu7kw.woff".
The code in my view is as follows:
Ext.define('Sencha.view.Tournaments', {
extend: 'Ext.Container',
xtype: 'tournamentPage',
config: {
title: 'maps',
layout: 'fit'
},
initialize : function() {
var lat, lng;
var geoLocationOptions = {
maximumAge: 3000,
timeout: 5000,
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoLocationSuccess,geoLocationError,geoLocationOptions);
function geoLocationSuccess(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
}
function geoLocationError() {
Ext.Msg.alert('Error','Error while getting geolocation');
}
var position = new google.maps.LatLng(lat,lng);
map = this.add({
xtype: 'map',
getLocation: true,
autoLoad: true,
mapOptions: {
zoom: 15,
center: position,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
zoomControl: true,
mapTypeControl: true,
scrollwheel: true,
scaleControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
}
}
});
marker = new google.maps.Marker({
id: 'geoLocMarker',
position: position,
map: map.getMap(),
visible: true
});
}
})
I hope I'm not asking to stupid of a question, I'm trying to learn! I've been going at it for a while now and it just does not seem to work! Thanks in advance.

EXTJS Google Map are blank

I am using GmapPanelv3.js. I can see the zooming and everything, but how come the map is blank? Here is an example http://jsfiddle.net/anthor/4aAKL/3/
Ext.onReady(function() {
var w = Ext.create('Ext.window.Window', {
title: 'Gmap',
height: 400,
width: 600,
layout: 'border',
items: [
{
title: 'Message List',
region: 'south',
height: 50,
split: true,
collapsible: true,
margins: '0 5 5 5',
collapsed: true
},{
region: 'west',
title: 'Tree',
collapsible: true,
width: 100,
items: [
{
xtype: 'button',
text: 'add',
handler: addInfoWindow // reference to event handler function
}]
},{
xtype: 'gmappanel',
region: 'center',
cls: 'reset-box-sizing',
mapConfOpts:['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
setCenter: {
lat: 3.951941,
long: 102.052002
}
}
]
});
/**
* Just example, do not write code like this!
* GMApPanel source code
* http://docs.sencha.com/extjs/4.2.0/extjs-build/examples/ux/GMapPanel.js
*/
// get the map reference
var map = w.down('gmappanel');
function openInfoWindow(content, marker) {
// create a info window
var infowindow = new google.maps.InfoWindow({
content: content,
size: new google.maps.Size(50,50)
});
infoBubble = new InfoBubble({
content: '<div class="example">Some label</div>',
//position: new google.maps.LatLng(53.5267, newlong),
shadowStyle: 1,
padding: 10,
borderRadius: 5,
minWidth: 200,
borderWidth:1,
//borderColor: '#2c2c2c',
disableAutoPan: true,
hideCloseButton: false,
backgroundClassName: 'example',
//arrowSize: 0,
//arrowPosition:7,
//arrowStyle:3
});
infoBubble.open(map.gmap,marker);
var div = document.createElement('DIV');
div.innerHTML = 'Hello';
infoBubble.addTab('A Tab', div);
infoBubble.addTab('A Tab', div);
// All GMapPanel instances has the reference to the underlying googlemap object
// porperty name `gmap`.
//infowindow.open(map.gmap, marker);
}
function addInfoWindow() {
// uses GMapPanel `addMarker` method to create a marker and attached it to tree.
// Detailes - look at the source code of GMapPanel
var marker = map.addMarker({
lat: 53.5267,
lng: -1.13330,
title: 'Marker',
// listeners can be added via configuration or after create
// using standard google maps API, i.e.
// google.maps.event.addListener(marker, 'click', function() {...})
listeners: {
click: function() {
openInfoWindow('hello', marker);
}
}
});
}
w.show();
});
i just change
setCenter: {
'lat': 3.951941,
'lng': 102.052002,
}
all problem are solved!

Google Maps toggle button

I have been struggling with this all day. I have made new buttons to actually go on my map that match the Google Maps buttons sit on the map better. I have been trying to get them to work with the current buttons above the map so I can remove those but I can't seem to get them to work. What am I missing.
Here is a link to the page so you can see. The buttons above the map work and I am going to remove them. The buttons on the map don't work which I am trying to get to work.
DEMO LINK
Here is the code. The var radarButton and var satButton is the new ones. The ones below that is to the current buttons.
jQuery(document).ready(function($) {
var mapTypeId = wundermap.getMapTypeId("hyb");
var googlemap = new google.maps.Map($("#map")[0], {
center: new google.maps.LatLng(32.782878, -96.609862),
panControl: false,
zoom: 6,
mapTypeId: mapTypeId,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
},
});
var radarOptions = {
gmap: googlemap,
name: 'Radar',
position: google.maps.ControlPosition.TOP_RIGHT,
action: function(){
if (wundermap.map.overlayMapTypes.length==0) {
wundermap.map.overlayMapTypes.push(null); // create empty overlay entry
wundermap.map.overlayMapTypes.setAt("1",Radar);
}
else {
wundermap.map.overlayMapTypes.clear();
}
}
}
var radarButton = new buttonControl(radarOptions);
var satOptions = {
gmap: googlemap,
name: 'Satellite',
position: google.maps.ControlPosition.TOP_RIGHT,
action: function(){
if (wundermap.map.overlayMapTypes.length==0) {
wundermap.map.overlayMapTypes.push(null); // create empty overlay entry
wundermap.map.overlayMapTypes.setAt("1",Satellite);
}
else {
wundermap.map.overlayMapTypes.clear();
}
}
}
var satButton = new buttonControl(satOptions);
wundermap.setOptions({
map: googlemap,
refreshPeriod: 60000,
units: "english",
debug: 0,
source: "wxmap",
StreetsOverlay: true,
layers: [
{
layer: "Radar",
active: "on",
opacity: 70,
type: "N0R",
type2: "",
animation: {
num: 6,
max: 10,
delay: 25
},
stormtracks: "off",
smooth: "on",
subdomain: "radblast-aws"
},
{
layer: "Satellite",
defaultUI: 0,
opacity: "85",
source: "",
active: "off",
animation: {
num: 1,
max: 8,
delay: 25
}
},
],
});
wundermap.initialize();
});
Here is the link to the code for the actual layer. The code is to long to post but the overlay is called Radar.
RADAR CODE
The place to start is the JavaScript console. The error messages there tell you what the problems are.
First, when the page is loaded you have an error on line 286 of wxgr3radar.php:
<body onload="initialize()">
Where is your initialize() function defined? I don't see it in your code.
Then, when I click the Satellite button it stops on line 41 of imap.js because map.overlayMapTypes is undefined:
if (map.overlayMapTypes.length==0) {
Here you're expecting map to be a Maps API object, but map is not what you think it is. Look at it in the debugger. It's a DOM element, not a Maps API map. Your Maps API map is in a variable called googlemap, which you create in line 3 of imap.js.