Ext.map markers are not loading in Sencha touch 2 - sencha-touch

I use following code to add markers to map which is not showing me the marker in Ext.map
{
xtype: 'map',
id :'geomap',
width: '70%',
height: '100%',
layout: 'fit',
useCurrentLocation: false,
flex: 3,
mapOptions: {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl : false,
navigationControl : false,
streetViewControl : false,
backgroundColor: 'transparent',
disableDoubleClickZoom: true,
draggable: true,
keyboardShortcuts: false,
scrollwheel: true,
},
initialize: function() {
var gMap = this.getMap();
// drop map marker
var marker = new google.maps.Marker({
map: gMap,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng (12.82787,80.219722),
title:"Hello World!"
});
var geo = Ext.create('Ext.util.Geolocation', {
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
var center = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
Ext.getCmp('geomap').update(center);
//To place the marker
var marker = new google.maps.Marker({
position: center,
map: Ext.getCmp('geomap').map
});
Ext.msg.alert('New latitude: ' + geo.getLatitude());
},
locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if (bTimeout) {
Ext.msg.alert('Timeout occurred.');
} else {
Ext.msg.alert('Error occurred.');
}
}
}
});
geo.updateLocation();
}
}
which is not showing markers . Please help .

The initialize method is not the appropriate place to play with the map because you can't be sure it has been rendered yet in there. You need to put your code in a maprender event handler.
Then, in order to find your first marker easily, you should initially center the map on it (like in this example).
Finally, you've got some small errors in your Geolocation handler's code. See my comments in the code.
Here's a fixed version of your code. For me, it works for both markers with Touch 2.2.1. I've not tested the Geolocation part, though, since it is not available in my browser...
{
xtype: 'map',
id :'geomap',
width: '70%',
height: '100%',
layout: 'fit',
useCurrentLocation: false,
flex: 3,
mapOptions: {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl : false,
navigationControl : false,
streetViewControl : false,
backgroundColor: 'transparent',
disableDoubleClickZoom: true,
draggable: true,
keyboardShortcuts: false,
scrollwheel: true
// Center your map to see your first marker ;)
,center: new google.maps.LatLng (12.82787,80.219722)
}
,listeners: {
maprender: function() {
// Get a ref to the google map object (should be provided
// as an argument to the listener but apparently there is
// a bug...)
var gMap = this.getMap();
new google.maps.Marker({
map: gMap,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng (12.82787,80.219722),
title:"Hello World!"
});
var geo = Ext.create('Ext.util.Geolocation', {
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
var center = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());
// This is deprecated
// Ext.getCmp('geomap').update(center);
Ext.getCmp('geomap').setMapCenter(center);
//To place the marker
var marker = new google.maps.Marker({
position: center,
// This won't work
// map: Ext.getCmp('geomap').map
//
// Use the ref we already have:
map: gMap
//
// Or you could get it this way:
// map: Ext.getCmp('geomap').getMap()
});
Ext.msg.alert('New latitude: ' + geo.getLatitude());
},
locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if (bTimeout) {
Ext.Msg.alert('Timeout occurred.');
} else {
Ext.Msg.alert('Error occurred.');
}
}
}
});
geo.updateLocation();
}
}
}

Related

ArcGIS JS API: make circle not zoom

I have a ArcGIS JavaScript API map. On map click I want to display a circle and highlight all the points within that circle.
However, when I create the circle and zoom in the map, the circle zooms in as well. How can I get the circle to stay the same pixel radius no matter what the zoom level of the map?
<script>
require([
"esri/Map",
"esri/layers/GeoJSONLayer",
"esri/views/MapView",
"esri/widgets/Zoom",
"esri/core/watchUtils",
"esri/geometry/geometryEngine"
], function (Map, GeoJSONLayer, MapView, Zoom, watchUtils, {buffer}) {
const url =
"https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson";
const template = {
title: "Earthquake Info",
content: "Magnitude {mag} {type} hit {place} on {time}",
fieldInfos: [
{
fieldName: "time",
format: {
dateFormat: "short-date-short-time"
}
}
]
};
const renderer = {
type: "simple",
field: "mag",
symbol: {
type: "simple-marker",
color: "orange",
outline: {
color: "white"
}
},
visualVariables: [
{
type: "size",
field: "mag",
stops: [
{
value: 2.5,
size: "4px"
},
{
value: 8,
size: "40px"
}
]
}
]
};
const geojsonLayer = new GeoJSONLayer({
url: url,
copyright: "USGS Earthquakes",
popupTemplate: template,
renderer: renderer //optional
});
const map = new Map({
basemap: "gray",
layers: [geojsonLayer]
});
const view = new MapView({
container: "viewDiv",
center: [-168, 46],
zoom: 3,
map: map
});
let csvLayerView;
let highlight;
let resultFeatures;
view.whenLayerView(geojsonLayer).then(layerView => {
csvLayerView = layerView;
});
view.on("click", ({mapPoint}) => {
const geom = buffer(mapPoint, 500, "miles");
view.graphics.removeAll();
view.graphics.add({
geometry: geom,
symbol: {
type: "simple-fill",
color: [51, 51, 204, 0.2],
style: "solid",
outline: {
color: "white",
width: 1
}
}
});
const query = geojsonLayer.createQuery();
query.geometry = geom;
csvLayerView.queryObjectIds(query).then(oids => {
if (highlight) {
highlight.remove();
}
highlight = csvLayerView.highlight(oids);
return csvLayerView.queryFeatures(query);
}).then(({features}) => {
resultFeatures = features;
});
});
});
</script>
The circle that you create, using a 500 miles buffer of the click point, is a polygon. So naturally will be the same one no matter what zoom level you have. In other words, represent a geographic area so it can not change based on the zoom level.
On contrary, in the same example you have the points that represent the earthquakes, that are represented with a orange circle. Because it is a symbol that represents a geographic place, it keeps the size in pixels for all zoom levels.
Resuming, you can not make the 500 miles buffer area, represented by the polygon, to change with the zoom levels, because it is an area.

Intermittent Error using Google Maps API: Uncaught TypeError: undefined is not a function

Hi All: a little help needed...
I am trying to use Google Maps API now and I followed all the instructions from the official google site for it. However, I noticed that it doesn't always work.
Often times, I get an error:
Failed to load resource: net::ERR_CONNECTION_REFUSED https://maps.gstatic.com/intl/en_us/mapfiles/api-3/16/8/main.js
Uncaught TypeError: undefined is not a function
I sometimes refresh and it works. But sometimes this error appears in the console.
Is this an issue with the API or my code?
Here's my jsfiddle: http://jsfiddle.net/SQ3Bx/
<script>var myLatlng = new google.maps.LatLng(14.572388, 121.057784);
var marker;
var map;
function initialize() {
var styles = [
{
stylers: [
{ hue: "#319885" },
]
},
{
featureType: 'water',
elementType: 'geometry.fill',
stylers: [
{ color: '#3191fe' }
]
}
];
var styledMap = new google.maps.StyledMapType(styles,
{name: "Timeframe Style"});
var isDraggable = $(document).width() > 1000 ? true : false;
var mapOptions = {
draggable: isDraggable,
center: myLatlng,
zoom: 14,
scrollwheel: false,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.SATELLITE, 'map_style']
}
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
image = 'img/map_marker.png';
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: myLatlng,
icon: image
});
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

How to link map marker to detail view on Sencha Touch (Architect 2)

I have a map with a marker, and i want to make the marker clicktable to show some basic info.
I am new to Sencha, and I need advice what should I implemante in listener function to get the same effect as i click on list item:
for example, this is my code of maprender function
var lat = 37.428607;
var lng = -122.169344;
var latLng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: latLng,
map: gmap,
draggable: false,
animation: google.maps.Animation.DROP,
title: 'cool'
});
var contentString = 'bla bla bla';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
/* here comes something that will make my detail list visible with the marker details*/
});
and i want to make it work in the same way as my function for "itemtap" which i use in my list... something like this:
onMyListItemTap: function(dataview, index, target, record, e, options) {
this.setActiveItem('detalji');this.down('#back').show();
this.down('#detalji').setData(record.data);
}
There is a great example on Github for Sencha Touch 1...I believe it's called World Map. If you unzip that (the app is in one of the many folders) you can see a Google map wil multiple custom markers. This project is very useful for learning, as it not only shows custom map markers, but also popup overlays on a marker click.
I have yet to adapt it to Sencha Touch 2, but it shouldn't be too difficult...here is some example code (after multiple markers have been added):
google.maps.event.addListener(marker, 'click', function()
{
if (!this.popup)
{
this.popup = new Ext.Panel(
{
floating: true,
modal: true,
centered: true,
width: 500,
styleHtmlContent: true,
scroll: 'vertical',
items:[{
xtype:'button',
ui:'round',
text:'See Country Profile',
handler:goToCountryWrapper,
scope : this
},
(new countryOverlay(country)).overlayPanel
],
layout: {
type: 'auto',
padding: '55',
align: 'left'
},
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
title: country.title
}],
});
};
this.popup.show('pop');
});
Also I think from what I understand about Sencha Touch 2, you would have to put a listener in your map controller (MyApp.map.controller file)....read up about the refs, as the refs 'finds' the marker(s) you have defined and adds a listener to the item.
If you have any progress please post your findings :-)

Marker in sencha touch map

I can't put any marker on my google map using sencha touch. This code works correctly:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
var position = new google.maps.LatLng(36.830618975720746,10.1987886428833);
var position2 = new google.maps.LatLng(33.7580276912933,10.848312377929688);
var map = new Ext.Map({
mapOptions: {
center: position
},
listeners: {
delay: 500,
afterrender: function(){
var marker = new google.maps.Marker({
position: position,
title: 'helooooooo',
map: map.map
});
var marker2 = new google.maps.Marker({
position: position2,
title: 'helooooooo',
map: map.map
});
}
}
});
var icons = new Ext.TabPanel({
fullscreen: true,
items: [{
iconCls: 'bookmarks',
title: 'page principale',
cls: 'card card3',
html: 'Blaaaaaaaa'
}, {
iconCls: 'search',
title: 'MapTunis',
cls: '',
layout: 'fit',
items: map
}],
tabBar: {
scroll: {
direction: 'horizontal',
scrollbars: false
},
layout: {
pack: 'center'
}
},
});
}
});
I tried this code on its own and it worked fine. But when i tried it with an xtype:Map it wouldnt work no matter what I try.
App.views.Homegeoatm = Ext.extend(Ext.Panel, {
items: [{
xtype: 'map',
id: 'map',
useCurrentLocation: true,
fullscreen: true,
markerDesc: "salam",
markerPos: new google.maps.LatLng (36.830618975720746,10.1987886428833),
mapOptions: {
zoom: 8
},
listeners: {
delay: 500,
afterrender: function(){
var marker = new google.maps.Marker({
position: position = new google.maps.LatLng (36.830618975720746,10.1987886428833),
map: App.views.Homegeoatm.getComponent('map').map,
});
}
}
}]
});
Ext.reg('Homegeoatm', App.views.Homegeoatm);
You need to add the marker on "maprender" event (instead of "afterrender") of the map. Try this one:
listeners: {
maprender: function(extMapComponent, googleMapComp){
var marker = new google.maps.Marker({
position: new google.maps.LatLng (36.830618975720746,10.1987886428833),
map: googleMapComp,
});
}
This should work (not tested).

Position ExtJs Color Picker

I am using ExtJs Color Picker component.
var cp = Ext.create('Ext.picker.Color', {
style: {
backgroundColor: "#fff"
} ,
listeners: {
scope:me,
select: selectColor
}
});
But I do not know how can I position color picker at the screen ?
You can encapsulate color component in window object
It will be something like this
var cp = Ext.create('Ext.picker.Color', {
style: {
backgroundColor: "#fff"
} ,
listeners: {
scope:me,
select: selectColor
}
});
var window = Ext.create('Ext.window.Window', {
title: 'Select Color',
resizable: false,
draggable: false,
closeAction: 'hide',
width: 150,
height: 135,
border: false,
hidden: true,
layout:'fit',
floating: true,
renderTo: "divCompare",
items: [cp]
})
Than you can use
win.showat(x,y)
method