I hope someone can explain this to me. I have built a sencha touch 2.2.1 app and converted it to a native android app.
I have a map view that extends Ext.Map as shown below. When I remove that view, the app loads successfully on my mobile. When I integrate the view again, the mobile app first displays a white screen, then it displays the default sencha theme blue screen and stays there. Not even the loading indicator appears.
When the apk was tested in the emulator, everything works fine.
I included this line in index.html before using the map. I included it in the HEAD section. However in the sencha examples provided, it is included in the BODY section. Does it make any difference?
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
Here are my files:
Controller:
Ext.define('EntityApp.controller.Map', {
extend : 'Ext.app.Controller',
requires : 'Ext.device.Connection',
config : {
refs : {
map : '.mappanel'
},
control : {
map: {
initialize: 'initMap'
}
}
},
initMap: function () {
var me = this;
var gMap = me.getMap();
gMap.on('maprender', this.onMapRender, this, {single : true});
},
onMapRender: function(e) {
if (Ext.device.Connection.isOnline()) {
var latLngCoordinates = new google.maps.LatLng(<value>, <value>);
marker = new google.maps.Marker({
position: latLngCoordinates,
animation: google.maps.Animation.DROP,
map: this.getMap().getMap()
});
this.getMap().getMap().setMapTypeId(google.maps.MapTypeId.ROADMAP);
this.getMap().setMapCenter(latLngCoordinates);
this.getMap().getMap().setZoom(17);
}
}
});
View:
Ext.define('EntityApp.view.Map', {
extend: 'Ext.Map',
xtype: 'mappanel',
config: {
layout: 'fit',
iconCls: 'icon-location',
title: 'Location',
useCurrentLocation: false,
styleHtmlContent: true,
items: {
docked: 'top',
xtype: 'titlebar',
title: 'Location'
},
mapOptions: {
center: !(window.google || {}).maps ? null : new google.maps.LatLng(<value>, <value>),
zoom: 17
}
},
constructor: function(config) {
this.callParent(config);
if (!(window.google || {}).maps) {
this.setHtml('<p id="maperror">Internet Connection Required!</p>');
}
}
});
Even I'm also getting same error, I just add
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
tag after
<script id="microloader" type="text/javascript" src="touch/microloader/development.js"></script>
in my index.html. It works fine. Try this.
I managed to solve the above by overriding the Ext.Map with my own data.
I also assigned a custom xtype called mymap and now I just do xtype:'mymap' and a map component loads with my custom data, as shown below:
Ext.define('App.view.Map', {
extend: 'Ext.Panel',
xtype: 'mappanel',
config: {
layout: 'fit',
iconCls: 'icon-location',
title: 'Location',
useCurrentLocation: false,
styleHtmlContent: true,
items: [
{ docked: 'top', xtype: 'titlebar', title: 'Location' },
{ xtype: 'mymap' }
]
}
});
It seems that sencha processes the views data before the script tags in index.html. Correct me if I am wrong...
Related
I'm looking for a way to separate custom created context menu visually (like background color etc.) from the default menu options like (Show properties, Isolate, etc.)
I've seen this example:
menu.push({
title: 'Show details',
className: 'fa fa-share',
target: [{
title: 'Hub details',
className: 'fa fa-cloud',
target: () => {
this.emit('context.details', {
event, node, type: 'hubs'
})
}
}]
})
but it seems className key doesn't work here. Is there a way to style context menu ?
The class name for your custom icon must be set to a property called icon, not className. Running the following code snippet works as expected:
NOP_VIEWER.registerContextMenuCallback('test', (menu, status) => {
menu.push({
title: 'Test',
icon: 'adsk-icon-first-person',
target: () => { console.log('It works!'); }
});
});
I'm using js-MarkerClusterer for creating clustered markers on my Map. I'm using API v3.
I've managed to create clusters:
new MarkerClusterer({
map: map,
markers: markers,
renderer: {
render: ({markers, _position: position}) => {
return new google.maps.Marker({
position: {
lat: position.lat(),
lng: position.lng(),
},
icon: '/assets/images/bitmap/cluster-marker.png',
label: String(markers.length),
color: '#fff'
});
},
},
});
Is there a way to change the label color? It is 'black' by default.
After a lot of searching, I found the sollution. It seems that label can be a object.
If fixed it by changing my label option to:
label: {
text: String(markers.length),
color: 'white'
},
I have to add a view with Google maps map on my project. I followed the official ionic native Google maps documentation but it does not work.
I assigned background color pink to the div that contains the map (for testing), before adding the map to the div, the div shows correctly. But when the map is added to the div the background of the modal window turns to transparent, and the div disappears. But no error is shown.
I tried different ways to attach the map on the div, but the results are the same.
When I use the code of the Ionic docs I got this error message "GoogleMaps [deprecated] Please use GoogleMaps.create()". I tried using GoogleMaps.create() instead of the argument of the constructor avoiding this error message, but still not working.
My ion-content:
<ion-content fullscreen overflow-scroll="true" class="container">
<div #map id="map"></div>
</ion-content>
Part of the css:
#map {
height: 90%;
width: 100%;
border-width: 5px;
border-color: red;
background: pink;
}
And here we got fragments of the ts:
import {
GoogleMaps,
GoogleMap,
GoogleMapsEvent,
GoogleMapOptions,
CameraPosition,
MarkerOptions,
Marker
} from '#ionic-native/google-maps';
...
export class PerfilPage {
#ViewChild(Content) content: Content;
#ViewChild('map') mapElement: ElementRef;
map: GoogleMap;
...
ionViewDidLoad() {
// I use this for changing the nab-bar color
this.content.ionScroll.subscribe((scroll) => {
// console.log('user scrolled', scroll);
if ( scroll.scrollTop > 100 ) {
this.toolbar_color = "bg_search"
} else {
this.toolbar_color = "transparent"
}
this.ref.detectChanges();
});
// this.loadMap();
// this.initMap();
// this.testMap();
this.offiMap();
}
// Official Ionic documentation code
offiMap() {
let mapOptions: GoogleMapOptions = {
camera: {
target: {
lat: 43.0741904,
lng: -89.3809802
},
zoom: 18,
tilt: 30
}
};
this.map = this.googleMaps.create('map', mapOptions);
// Wait the MAP_READY before using any methods.
this.map.one(GoogleMapsEvent.MAP_READY)
.then(() => {
console.log('Map is ready!');
// Now you can use all methods safely.
this.map.addMarker({
title: 'Ionic',
icon: 'blue',
animation: 'DROP',
position: {
lat: 43.0741904,
lng: -89.3809802
}
})
.then(marker => {
marker.on(GoogleMapsEvent.MARKER_CLICK)
.subscribe(() => {
alert('clicked');
});
});
});
}
}
PS: the API key works on other projects (not Ionic projects), so idk where is the problem.
Thanks :)
As I describe on the git repo, the maps plugin places the native map view under (or behind) the browser.
https://github.com/mapsplugin/cordova-plugin-googlemaps#how-does-this-plugin-work
That's why all parent elements of the map div becomes transparent.
If you need to set the background of application, you need to use Environment.setBackground("pink").
Since the map is displayed under the browser, this plugin CAN NOT display on dialogs.
loadMap() {
let element = document.getElementById('map');
let mapOptions: GoogleMapOptions = {
camera: {
target: {
lat: 43.0741904,
lng: -89.3809802
},
zoom: 18,
tilt: 30
}
};
let map: GoogleMap = this.googleMaps.create(element, mapOptions);
map.addMarker({
title: 'Location',
icon: 'blue',
animation: 'DROP',
position: {
lat: 43.0741904,
lng: -89.3809802
}
})
.then(marker => {
marker.on(GoogleMapsEvent.MARKER_CLICK)
.subscribe(() => {
//alert('clicked');
});
});
}
Try this
I had the exact issue as OP had when follow the Official Ionic Native Google Maps Guide
There's a misleading on the slide page Google Maps API Key. The URL in the slide is https://console.developers.google.com/projectselector/apis/library which is INCORRECT.
For generating Google Maps API Key for Android and IOS, we use Google Cloud Platforms https://cloud.google.com/maps-platform/
Here's the link I asked the same question Ionic3 ionic native google maps doesn't show map but only google logo (display grey blank map )
Hope it can help people who have the same issue.
I'm using React Meteor 1.3 and this google maps package.
https://github.com/dburles/meteor-google-maps-react-example.
I can successfully render the map to a single page App, however as soon as I add routing to the mix - things stop working. Specifically when I move the element from an index html template to a JSX component that renders to the page - it breaks. I'm at a bit of a loss here and as the problem is quite vague (in my mind at least) I can't find an answer on google.
What's happening here? Does anyone have an example of this package working with flowrouter?
My current working set up looks like this.
Map.jsx
import React from 'react';
import ReactDOM from 'react-dom';
MyTestMap = React.createClass({
mixins: [ReactMeteorData],
componentDidMount() {
GoogleMaps.load();
},
getMeteorData() {
return {
loaded: GoogleMaps.loaded(),
mapOptions: GoogleMaps.loaded() && this._mapOptions()
};
},
_mapOptions() {
return {
center: new google.maps.LatLng(-37.8136, 144.9631),
zoom: 8
};
},
render() {
if (this.data.loaded)
return <GoogleMap name="mymap" options={this.data.mapOptions} />;
return <div>Loading map...</div>;
}
});
GoogleMap = React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired,
options: React.PropTypes.object.isRequired
},
componentDidMount() {
GoogleMaps.create({
name: this.props.name,
element: ReactDOM.findDOMNode(this),
options: this.props.options
});
GoogleMaps.ready(this.props.name, function(map) {
var marker = new google.maps.Marker({
position: map.options.center,
map: map.instance
});
});
},
componentWillUnmount() {
if (GoogleMaps.maps[this.props.name]) {
google.maps.event.clearInstanceListeners(GoogleMaps.maps[this.props.name].instance);
delete GoogleMaps.maps[this.props.name];
}
},
render() {
return (
<div id="mapId" className="map-container"></div>
)
}
});
if (Meteor.isClient) {
Meteor.startup(function() {
return ReactDOM.render(<MyTestMap />, document.getElementById('root'));
});
}
And then I render this to an Index.html file - however this means that the map is on every page.
<head>
<title>googlemaps-react</title>
</head>
<body>
<div id="root"></div>
</body>
Thanks
I'm creating a changelog and i decided to load my changelog from .html file
I've got
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
modal : true,
height : 400,
width : 500,
resizable : false,
html: 'changes.html',
buttons: [{
text: 'Закрыть',
handler: function() {
this.up('window').close();
}
}]
});
How i can solve this ? (html: 'changes.html')
How i can load html to my window ?
There is a better solution that uses the declaration of the loader config of the panel:
loader: {
url: 'changes.html',
autoLoad: true
},
which will result in this global code.
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
modal : true,
height : 400,
width : 500,
resizable : false,
loader: {
url: 'changes.html',
autoLoad: true
},
buttons: [{
text: 'Закрыть',
handler: function() {
this.up('window').close();
}
}]
});
This is preferable, because we do not need to define a listener, nor an Ext.Ajax call.
You'd need to load the html asynchronously, then inject it into your component. So:
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
// response.responseText will have your html content
// you can then feed it into your component using update()
}
});
So if you declare you component with id:
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
id: : 'my-log',
...
});
You can then do:
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
Ext.getCmp('my-log').update( response.responseText );
}
});
You can `integrate' it into your panel like so:
Ext.define('MeridianCRM.dialogs.recentСhanges.recentСhanges', {
extend : 'Ext.window.Window',
title : 'Последние изменения на сайте',
id: : 'my-log',
listeners: {
'render': function()
{
Ext.Ajax.request({
url: 'changes.html',
success: function(response){
Ext.getCmp('my-log').update( response.responseText );
}
});
}
}
...
});
Notice though, that you may have issues if the returned html contains <head> tag (as the extjs page already has one).