Titanium Studio - Putting my detailed data into a table - json

I have a data table and on eventlistener click, the row becomes a detailed window with the data of the row selected. I have the data as labels, but I want to display some of the data as a table with row titles (particularly my vars, mon, tues, weds, thurs, fri, sat, sund). I attempted to create a table within the eventlistener, but it did not appear. how would I approach this? Below is my code:
var win = Titanium.UI.currentWindow;
var data = [];
var barList = Titanium.UI.createTableView({
height: 366,
width: 320,
top: 0,
left: 0
});
win.add(barList);
barList.addEventListener('click', function (e) {
Ti.API.info('data: ' + JSON.stringify(e.rowData.data));
var detail = Ti.UI.createWindow({
backgroundColor: '#fff',
data: e.rowData.data, // use rowData
title: e.rowData.data.name, // now you can access name as well as address
});
var lbl = Ti.UI.createLabel({
text: JSON.stringify(e.rowData.data.address),
top: 10
});
detail.add(lbl); // just so you can see it here as well
var mon = Ti.UI.createLabel({
text: e.rowData.data.mon_special,
top: 30
});
detail.add(mon);
var tues = Ti.UI.createLabel({
text: e.rowData.data.tues_special,
top: 50
});
detail.add(tues);
var weds = Ti.UI.createLabel({
text: e.rowData.data.weds_special,
top: 50
});
detail.add(weds);
var thurs = Ti.UI.createLabel({
text: e.rowData.data.thurs_special,
top: 50
});
detail.add(thurs);
var fri = Ti.UI.createLabel({
text: e.rowData.data.fri_special,
top: 50
});
detail.add(fri);
var sat = Ti.UI.createLabel({
text: e.rowData.data.sat_special,
top: 50
});
detail.add(sat);
var sund = Ti.UI.createLabel({
text: e.rowData.data.sun_special,
top: 50
});
detail.add(sund);
detail.open({
modal: true
});
});
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function () {
var json = JSON.parse(this.responseText);
Ti.API.info(json.length);
for (var i = 0; i < json.length; i++) {
var row = Titanium.UI.createTableViewRow({
className: 'bar-row',
data: json[i].bar, // pass everything because you also use name later on
hasChild: true,
filter: json[i].bar.name
});
var titleLabel = Titanium.UI.createLabel({
text: json[i].bar.name,
font: {
fontSize: 14,
fontWeight: 'bold'
},
left: 70,
top: 5,
height: 20,
width: 210
});
row.add(titleLabel);
var addressLabel = Titanium.UI.createLabel({
text: json[i].bar.address,
font: {
fontSize: 10,
fontWeight: 'normal'
},
left: 70,
top: 25,
height: 40,
width: 200
});
row.add(addressLabel);
var iconImage = Titanium.UI.createImageView({
text: json[i].bar.logo_file_name,
width: 50,
height: 50,
left: 10,
top: 10
});
row.add(iconImage);
data.push(row);
}
barList.setData(data);
};
xhr.open('GET', 'http://example.com/bars.json');
xhr.send();

as your new to Titanium it think it is difficult to put data
we can approch this type of method in following ways
1) store the data you called i mean your bar dat
var win = Titanium.UI.currentWindow;
var data = [];
var json=''
var barList = Titanium.UI.createTableView({
height: 366,
width: 320,
top: 0,
left: 0
});
win.add(barList);
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function () {
json = JSON.parse(this.responseText);
Ti.API.info(json.length);
for (var i = 0; i < json.length; i++) {
var row = Titanium.UI.createTableViewRow({
className: 'bar-row',
data: json[i].bar, // pass everything because you also use name later on
hasChild: true,
filter: json[i].bar.name
});
var titleLabel = Titanium.UI.createLabel({
text: json[i].bar.name,
font: {
fontSize: 14,
fontWeight: 'bold'
},
left: 70,
top: 5,
height: 20,
width: 210
});
row.add(titleLabel);
var addressLabel = Titanium.UI.createLabel({
text: json[i].bar.address,
font: {
fontSize: 10,
fontWeight: 'normal'
},
left: 70,
top: 25,
height: 40,
width: 200
});
row.add(addressLabel);
var iconImage = Titanium.UI.createImageView({
text: json[i].bar.logo_file_name,
width: 50,
height: 50,
left: 10,
top: 10
});
row.add(iconImage);
data.push(row);
}
barList.setData(data);
};
xhr.open('GET', 'http://site.com/bars.json');
xhr.send();
barList.addEventListener('click', function (e) {
var newwindow =require('tabledetails')
var wind= new newwindow(json[e.index]) /// here we are sending particular bar data
wind.open({modal:true})
})
2) show the details using the data
-----> tabledetails.js
function details(data){
var details =Ti.UI.createWindow({backgroundColor="#fff"})
var lbl = Ti.UI.createLabel({
text: JSON.stringify(data.address),
top: 10
});
detail.add(lbl); // just so you can see it here as well
var mon = Ti.UI.createLabel({
text: data.mon_special,
top: 30
});
detail.add(mon);
var tues = Ti.UI.createLabel({
text: data.tues_special,
top: 50
});
detail.add(tues);
var weds = Ti.UI.createLabel({
text: data.weds_special,
top: 50
});
detail.add(weds);
var thurs = Ti.UI.createLabel({
text: e.rowData.data.thurs_special,
top: 50
});
detail.add(thurs);
var fri = Ti.UI.createLabel({
text: data.fri_special,
top: 50
});
detail.add(fri);
var sat = Ti.UI.createLabel({
text: e.rowData.data.sat_special,
top: 50
});
detail.add(sat);
var sund = Ti.UI.createLabel({
text: data.sun_special,
top: 50
});
detail.add(sund);
return details;
}
module.exports=detials

Related

Responsive friendly square openstreetmap

I'm using this code to display an openstreetmap. It works great on a desktop display but it's not very responsive friendly. I like to have a square sized map. I'm having some problems to find the right parameters for a responsive hight and width.
How can I set it to a 1:1 ratio?
My demo of the below source code: https://jsfiddle.net/uyn9posg/
<link id="cf7-map-field-leaflet-css" rel="stylesheet" href="https://unpkg.com/leaflet#1.7.1/dist/leaflet.css" />
<script id="cf7-map-field-leaflet-js" src="https://unpkg.com/leaflet#1.7.1/dist/leaflet.js"></script>
<div style="position:relative">
<div id="CF7MapFieldDiv" style="height:600px;width:100%"></div>
<span style="position:absolute;right:0px;bottom:20px;font: 12px Arial,Helvetica,sans-serif;background-color: rgba(255, 255, 255, 0.698);padding:2px 7px;z-index: 1000;" >
Marker bei: <span id="CF7MapMarkerAt">none</span>
</span>
</div>
<script>
var map;
var marker;
function updateMarkerPosition(e) {
//var markerLatLang = [e.lat.toFixed(6), e.lng.toFixed(6)].join(',');
var markerLong = e.lng.toFixed(6);
var markerLat = e.lat.toFixed(6);
//document.getElementById('CF7MapMarkerAt').innerHTML = markerLatLang;
document.getElementById('CF7MapMarkerAt').innerHTML = "Lat="+markerLat +", Long="+markerLong;
var hidd = document.getElementById('CF7MapLocationHidden');
var hidd2 = document.getElementById('CF7MapLocationHidden_long');
var hidd3 = document.getElementById('CF7MapLocationHidden_lat');
var hidd4 = document.getElementById('CF7MapLocationHidden_zoom');
//var val = [map.getZoom(), markerLatLang].join(';');
var zoomstufe = map.getZoom();
//if (!!hidd) { hidd.value = val; }
if (!!hidd2) { hidd2.value = markerLong; }
if (!!hidd3) { hidd3.value = markerLat; }
if (!!hidd4) { hidd4.value = zoomstufe; }
}
function onMarkerDrag(e) {
updateMarkerPosition(marker.getLatLng());
}
function onMapClick(e) {
map.removeLayer(initMarker);
if (marker === undefined) {
var markerIcon = L.icon({
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-icon.png',
shadowUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-shadow.png',
iconSize: [25, 41],
shadowSize: [41, 41],
shadowAnchor: [15, 41]
});
marker = L.marker(e.latlng, {
icon: markerIcon,
draggable: true
}).addTo(map);
marker.on('drag', onMarkerDrag);
} else {
marker.setLatLng([e.latlng.lat, e.latlng.lng]);
}
updateMarkerPosition(e.latlng);
}
var initMarker = {};
function initmap() {
// set up the map
map = new L.Map('CF7MapFieldDiv');
// create the tile layer with correct attribution
var mapUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var mapAttrib = '© OpenStreetMap contributors';
var mapTile = new L.TileLayer(mapUrl, {
minZoom: 2,
maxZoom: 18,
attribution: mapAttrib
});
map.addLayer(mapTile);
// set default view (London)
//map.setView(new L.LatLng(51.501, -0.105), 8);
map.setView(new L.LatLng(47.77929097015571, 9.609822830498674), 9);
initMarker = L.marker([47.77929097015571, 9.609822830498674], {
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-icon.png',
shadowUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-shadow.png',
iconSize: [25, 41],
shadowSize: [41, 41],
shadowAnchor: [15, 41], draggable: true
}).addTo(this.map);
// add events
map.on('click', onMapClick);
}
initmap();
</script>
Constraining to the Smallest Viewport Dimension
Not sure if this would be an alright way of doing for your use case. But I usually like to take the smaller (minimum) of the viewport height viewport width, min(100vh,100vw) and use that to set the height and width of the element I'm trying to keep a square 1:1 aspect ratio. This will also work for other fractions of viewport height and width. Effectively, this will contain the square to the smallest dimension. Press the blue Run code snippet button below to see the results and test the responsiveness using the full page link:
Minimal Example:
.Rectangle {
--Dimensions: min(80vh, 80vw);
height: var(--Dimensions);
width: var(--Dimensions);
position: absolute;
top: calc(50% - var(--Dimensions)/2);
left: calc(50% - var(--Dimensions)/2);
background-color: cyan;
}
<div class="Rectangle"></div>
Map Implementation:
<link id="cf7-map-field-leaflet-css" rel="stylesheet" href="https://unpkg.com/leaflet#1.7.1/dist/leaflet.css" />
<script id="cf7-map-field-leaflet-js" src="https://unpkg.com/leaflet#1.7.1/dist/leaflet.js"></script>
<div style="position:relative">
<div id="CF7MapFieldDiv" style="height:min(100vh,100vw); width:min(100vh,100vw); left: calc(50% - min(100vh,100vw)/2)"></div>
<span style="position:absolute;right:0px;bottom:20px;font: 12px Arial,Helvetica,sans-serif;background-color: rgba(255, 255, 255, 0.698);padding:2px 7px;z-index: 1000;" >
Marker bei: <span id="CF7MapMarkerAt">none</span>
</span>
</div>
<script>
var map;
var marker;
function updateMarkerPosition(e) {
//var markerLatLang = [e.lat.toFixed(6), e.lng.toFixed(6)].join(',');
var markerLong = e.lng.toFixed(6);
var markerLat = e.lat.toFixed(6);
//document.getElementById('CF7MapMarkerAt').innerHTML = markerLatLang;
document.getElementById('CF7MapMarkerAt').innerHTML = "Lat="+markerLat +", Long="+markerLong;
var hidd = document.getElementById('CF7MapLocationHidden');
var hidd2 = document.getElementById('CF7MapLocationHidden_long');
var hidd3 = document.getElementById('CF7MapLocationHidden_lat');
var hidd4 = document.getElementById('CF7MapLocationHidden_zoom');
//var val = [map.getZoom(), markerLatLang].join(';');
var zoomstufe = map.getZoom();
//if (!!hidd) { hidd.value = val; }
if (!!hidd2) { hidd2.value = markerLong; }
if (!!hidd3) { hidd3.value = markerLat; }
if (!!hidd4) { hidd4.value = zoomstufe; }
}
function onMarkerDrag(e) {
updateMarkerPosition(marker.getLatLng());
}
function onMapClick(e) {
map.removeLayer(initMarker);
if (marker === undefined) {
var markerIcon = L.icon({
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-icon.png',
shadowUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-shadow.png',
iconSize: [25, 41],
shadowSize: [41, 41],
shadowAnchor: [15, 41]
});
marker = L.marker(e.latlng, {
icon: markerIcon,
draggable: true
}).addTo(map);
marker.on('drag', onMarkerDrag);
} else {
marker.setLatLng([e.latlng.lat, e.latlng.lng]);
}
updateMarkerPosition(e.latlng);
}
var initMarker = {};
function initmap() {
// set up the map
map = new L.Map('CF7MapFieldDiv');
// create the tile layer with correct attribution
var mapUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var mapAttrib = '© OpenStreetMap contributors';
var mapTile = new L.TileLayer(mapUrl, {
minZoom: 2,
maxZoom: 18,
attribution: mapAttrib
});
map.addLayer(mapTile);
// set default view (London)
//map.setView(new L.LatLng(51.501, -0.105), 8);
map.setView(new L.LatLng(47.77929097015571, 9.609822830498674), 9);
initMarker = L.marker([47.77929097015571, 9.609822830498674], {
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-icon.png',
shadowUrl: 'http://cdn.leafletjs.com/leaflet-0.4.4/images/marker-shadow.png',
iconSize: [25, 41],
shadowSize: [41, 41],
shadowAnchor: [15, 41], draggable: true
}).addTo(this.map);
// add events
map.on('click', onMapClick);
}
initmap();
</script>

Change cluster icon for a particular google map cluster - markerclusterplus

I would like to change the cluster icon (dynamically/for particular cluster) based on some particular condition. I am able to identify the condition and have restricted further drill-down on the same. At that particular level we are opening infobox for the user.
The problem lies with cluster as I want to change the icon to something else. For the individual pins the icon is fine.
Below is the code that I am trying to implement:
<!DOCTYPE html>
<html>
<head>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 80%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCtTgoZ3tcsUSNfK6yCPzX_muSVOG6N9Ho"></script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<button type="button" id="refreshmap">Click Me!</button>
<div id="map"></div>
<script>
var gm_map;
var markerArray = [];
var clusterMarkers = [];
var infoWindow = new google.maps.InfoWindow();
function initialize(searchMarkers = []) {
var marker, i;
if(searchMarkers.length == 0) {
clusterMarkers = [
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "P1220214 1.JPG",
label: {
text: 'Label 1',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "P1220214 2.JPG",
label: {
text: 'Label 2',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.340715, 13.49631),
map: gm_map,
title: "P1220214 3.JPG",
label: {
text: 'Label 3',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.327232, 13.487384),
map: gm_map,
title: "P1220214 4.JPG",
label: {
text: 'Label 4',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.379034, 13.516566),
map: gm_map,
title: "P1220214 5.JPG",
label: {
text: 'Label 5',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.330000, 13.485000),
map: gm_map,
title: "P1220214 6.JPG",
label: {
text: 'Label 6',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.328501, 13.485782),
map: gm_map,
title: "P1220214 7.JPG",
label: {
text: 'Label 7',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.328501, 13.485782),
map: gm_map,
title: "P1220214 8.JPG",
label: {
text: 'Label 8',
color: '#222222',
fontSize: '12px'
}
})
]
} else {
clusterMarkers = searchMarkers;
}
var options_googlemaps = {
minZoom: 9,
zoom: 9,
center: new google.maps.LatLng(59.328631, 13.485688),
maxZoom: 18,
}
gm_map = new google.maps.Map(document.getElementById('map'), options_googlemaps)
var options_markerclusterer = {
//gridSize: 20,
maxZoom: 18,
zoomOnClick: false,
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m',
label: {
text: 'This is custom text'
}
};
var markerCluster = new MarkerClusterer(gm_map, clusterMarkers, options_markerclusterer);
markerCluster.setCalculator(function(markers, numStyles){
var index = 0,
count = markers.length,
total = count;
while (total !== 0) {
//Create a new total by dividing by a set number
total = parseInt(total / 5, 10);
//Increase the index and move up to the next style
index++;
}
index = Math.min(index, numStyles);
samePin = _getPinStatus(markers);
if (samePin) {
return {
text: count + " ("+ count + " Jobs)",
index: index
};
} else {
return {
text: count,
index: index
};
}
});
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
//This needs some logic to identify if all the internal pings are at same location - execute else part otherwise further zoom in using if code.
var markers = cluster.getMarkers();
var samePin = false;
samePin = _getPinStatus(markers);
if (!samePin ){
gm_map.setCenter(cluster.center_);
gm_map.setZoom(gm_map.getZoom() + 2);
} else {
// This is where I want to change the icon of the particular cluster.
var array = [];
for (i = 0; i < markers.length; i++) {
array.push(markers[i].getTitle() + '<br>');
}
if (gm_map.getZoom() <= markerCluster.getMaxZoom()) {
infoWindow.setContent(markers.length + " markers<br>" + array);
infoWindow.setPosition(cluster.getCenter());
infoWindow.open(gm_map);
}
}
});
for (i = 0; i < clusterMarkers.length; i++) {
var marker = clusterMarkers[i];
google.maps.event.addListener(marker, 'click', (function(marker) {
return function() {
infoWindow.setContent(this.getTitle());
infoWindow.open(gm_map, this);
}
})(marker));
}
}
$(document).ready(function() {
initialize();
$('body').on('click', '#close-link', function() {
$('#toggle-photolist').fadeOut();
$('#close-overlay').fadeOut();
});
$('#refreshmap').click(function() {
searchMarkers = [
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "Search Data 1.JPG",
label: {
text: 'Search label 1',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.338683, 13.492057),
map: gm_map,
title: "Search Data 2.JPG",
label: {
text: 'Search label 1',
color: '#222222',
fontSize: '12px'
}
})
]
initialize(searchMarkers);
});
});
function _getPinStatus(markers) {
for (i = 0; i < markers.length; i++) {
var parentLatitude = markers[0].getPosition().lat();
var parentLongitude = markers[0].getPosition().lng();
if(markers[i].getPosition().lat() == parentLatitude &&
markers[0].getPosition().lng() == parentLongitude) {
samePin = true;
}
else {
// break out of the loop in case a single pin is different and allow user to further zoom in the map
samePin = false;
break;
}
}
return samePin;
}
</script>
<!-- Replace following script src -->
</body>
</html>
The logic that I am trying to build is that if the cluster has identical pins beneath it (I would not like to drill down) then change the icon to anything else.
The function _getPinStatus helps me identify the above logic and creates the infowindow.
I also somehow could not manage to get the zoom change event - but this is rather a separate query
I tried with clearMarkers() function and remap the clusters by providing the image in options_markerclusterer array but it does replace the image on all underlying markers.
I could not find details around setStyles and its implementation. Would it be feasible to push styles once the map is already plotted.
Appreciate any suggestions.
You can add additional styles to the style array used to define the Cluster icon styles:
var mcStyles = markerCluster.getStyles();
mcStyles.push({
url: "http://www.geocodezip.com/mapIcons/markerclusterer/heart50.png",
width: 50,
height: 44,
anchorIcon: [44, 25],
textSize: 10,
textColor: "black",
textDecoration: "none",
fontStyle: "normal",
fontFamily: "Arial,sans-serif",
backgroundPosition: "0 0",
});
Then adjust the "calculator" to return the appropriate index (in this case 6) when you hit your "same pin" case:
markerCluster.setCalculator(function(markers, numStyles) {
var index = 0,
count = markers.length,
total = count;
while (total !== 0) {
//Create a new total by dividing by a set number
total = parseInt(total / 5, 10);
//Increase the index and move up to the next style
index++;
}
index = Math.min(index, numStyles);
samePin = _getPinStatus(markers);
if (samePin) {
return {
text: count + " (" + count + " Jobs)",
index: 6 // reference added style
};
} else {
return {
text: count,
index: index
};
}
});
proof of concept fiddle
code snippet:
var gm_map;
var markerArray = [];
var clusterMarkers = [];
var infoWindow = new google.maps.InfoWindow();
function initialize(searchMarkers = []) {
var marker, i;
if (searchMarkers.length == 0) {
clusterMarkers = [
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "P1220214 1.JPG",
label: {
text: 'Label 1',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "P1220214 2.JPG",
label: {
text: 'Label 2',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.340715, 13.49631),
map: gm_map,
title: "P1220214 3.JPG",
label: {
text: 'Label 3',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.327232, 13.487384),
map: gm_map,
title: "P1220214 4.JPG",
label: {
text: 'Label 4',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.379034, 13.516566),
map: gm_map,
title: "P1220214 5.JPG",
label: {
text: 'Label 5',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.330000, 13.485000),
map: gm_map,
title: "P1220214 6.JPG",
label: {
text: 'Label 6',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.328501, 13.485782),
map: gm_map,
title: "P1220214 7.JPG",
label: {
text: 'Label 7',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.328501, 13.485782),
map: gm_map,
title: "P1220214 8.JPG",
label: {
text: 'Label 8',
color: '#222222',
fontSize: '12px'
}
})
]
} else {
clusterMarkers = searchMarkers;
}
var options_googlemaps = {
minZoom: 9,
zoom: 9,
center: new google.maps.LatLng(59.328631, 13.485688),
maxZoom: 18,
}
gm_map = new google.maps.Map(document.getElementById('map'), options_googlemaps)
var options_markerclusterer = {
//gridSize: 20,
maxZoom: 18,
zoomOnClick: false,
imagePath: 'https://www.geocodezip.net/mapIcons/markerclusterer/m',
label: {
text: 'This is custom text'
}
};
var markerCluster = new MarkerClusterer(gm_map, clusterMarkers, options_markerclusterer);
var mcStyles = markerCluster.getStyles();
console.log(mcStyles);
mcStyles.push({
url: "https://www.geocodezip.net/mapIcons/markerclusterer/heart50.png",
width: 50,
height: 44,
anchorIcon: [44, 25],
textSize: 10,
textColor: "black",
textDecoration: "none",
// textLineHeight: 12,
// fontWeight: "bold",
fontStyle: "normal",
fontFamily: "Arial,sans-serif",
backgroundPosition: "0 0",
});
markerCluster.setCalculator(function(markers, numStyles) {
console.log("setCalculator(numMarkers" + markers.length + ", numStyles=" + numStyles + ")");
var index = 0,
count = markers.length,
total = count;
while (total !== 0) {
//Create a new total by dividing by a set number
total = parseInt(total / 5, 10);
//Increase the index and move up to the next style
index++;
}
index = Math.min(index, numStyles);
samePin = _getPinStatus(markers);
if (samePin) {
return {
text: count + " (" + count + " Jobs)",
index: 6
};
} else {
return {
text: count,
index: index
};
}
});
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
//This needs some logic to identify if all the internal pings are at same location - execute else part otherwise further zoom in using if code.
var markers = cluster.getMarkers();
var samePin = false;
samePin = _getPinStatus(markers);
if (!samePin) {
gm_map.setCenter(cluster.center_);
gm_map.setZoom(gm_map.getZoom() + 2);
} else {
// This is where I want to change the icon of the particular cluster.
var array = [];
for (i = 0; i < markers.length; i++) {
array.push(markers[i].getTitle() + '<br>');
}
if (gm_map.getZoom() <= markerCluster.getMaxZoom()) {
infoWindow.setContent(markers.length + " markers<br>" + array);
infoWindow.setPosition(cluster.getCenter());
infoWindow.open(gm_map);
}
}
});
for (i = 0; i < clusterMarkers.length; i++) {
var marker = clusterMarkers[i];
google.maps.event.addListener(marker, 'click', (function(marker) {
return function() {
infoWindow.setContent(this.getTitle());
infoWindow.open(gm_map, this);
}
})(marker));
}
}
$(document).ready(function() {
initialize();
$('body').on('click', '#close-link', function() {
$('#toggle-photolist').fadeOut();
$('#close-overlay').fadeOut();
});
$('#refreshmap').click(function() {
searchMarkers = [
new google.maps.Marker({
position: new google.maps.LatLng(59.381059, 13.504026),
map: gm_map,
title: "Search Data 1.JPG",
label: {
text: 'Search label 1',
color: '#222222',
fontSize: '12px'
}
}),
new google.maps.Marker({
position: new google.maps.LatLng(59.338683, 13.492057),
map: gm_map,
title: "Search Data 2.JPG",
label: {
text: 'Search label 1',
color: '#222222',
fontSize: '12px'
}
})
]
initialize(searchMarkers);
});
});
function _getPinStatus(markers) {
for (i = 0; i < markers.length; i++) {
var parentLatitude = markers[0].getPosition().lat();
var parentLongitude = markers[0].getPosition().lng();
if (markers[i].getPosition().lat() == parentLatitude &&
markers[0].getPosition().lng() == parentLongitude) {
samePin = true;
} else {
// break out of the loop in case a single pin is different and allow user to further zoom in the map
samePin = false;
break;
}
}
return samePin;
}
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 95%;
margin: 0;
padding: 0;
}
<!DOCTYPE html>
<html>
<head>
<title>SO MarkerClusterer Question</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=&v=weekly"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<!-- jsFiddle will insert css and js -->
</head>
<body>
<button type="button" id="refreshmap">Click Me!</button>
<div id="map"></div>
</body>
</html>
details on how this works:
MarkerClustererPlus source on GitHub
useStyle:
/**
* Sets the icon styles to the appropriate element in the styles array.
*
* #ignore
* #param sums The icon label text and styles index.
*/
useStyle(sums: ClusterIconInfo): void
Is used in the Cluster updateIcon:
/**
* Updates the cluster icon.
*/
public updateIcon(): void
here: Cluster
const sums = this.markerClusterer_.getCalculator()(
this.markers_,
numStyles
);
this.clusterIcon_.setCenter(this.center_);
this.clusterIcon_.useStyle(sums);
this.clusterIcon_.show();
Where sums is the structure returned by the calculator function:

How to hide the numbers on a cluster marker in Google Maps?

So I have this:
But what I want is this:
I'm pretty sure there should be an option I can specify here:
var options = {
gridSize: 80,
imagePath: imagePath ,
someOption : iAmMissing ??
}
var mc = new MarkerClusterer(map, mapmarkers, options);
google.maps.event.addListener(mc, 'clusteringend', function(){
setTimeout(fixMyPageOnce, 1);
});
But I can't seem to find an option. Is this the right place or is there another way I can get rid of the numbers in the circles?
You can just use the "styles" options and set the "textSize" option slightly above 0:
var options = {
gridSize: 80,
styles: [{
url: imagePath,
height: 29,
width: 29,
anchor: [0, 0],
textSize: 0.001
}, {
url: imagePath,
height: 49,
width: 49,
anchor: [0, 0],
textSize: 0.001
}, {
url: imagePath,
width: 65,
height: 65,
anchor: [0, 0],
textSize: 0.001
}]
}
It is working for me.
Just set textColor to transparent
var options = {
textColor: 'transparent',
gridSize: 80,
imagePath: imagePath ,
someOption : iAmMissing ??
}
Create a custom "calculator" function that sets the "text" property of the return value to "".
calculator: function(markers, numStyles) {
var index = 0;
var count = markers.length.toString();
var dv = count;
while (dv !== 0) {
dv = parseInt(dv / 10, 10);
index++;
}
index = Math.min(index, numStyles);
return {
text: "",
index: index,
title: count
};
}
proof of concept fiddle
code snippet:
function initialize() {
var center = new google.maps.LatLng(52.4357808, 4.991315699999973);
var mapOptions = {
zoom: 12,
center: center,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
for (i = 0; i < markers.length; i++) {
addMarker(markers[i]);
}
markerCluster = new MarkerClusterer(map, gmarkers, {
imagePath: 'https://cdn.rawgit.com/googlemaps/v3-utility-library/master/markerclustererplus/images/m',
calculator: function(markers, numStyles) {
var index = 0;
var title = "";
var count = markers.length.toString();
var dv = count;
while (dv !== 0) {
dv = parseInt(dv / 10, 10);
index++;
}
index = Math.min(index, numStyles);
return {
text: "",
index: index,
title: count
};
}
});
}
var gmarkers = [];
var markers = [];
var infowindow = new google.maps.InfoWindow({
content: ''
});
var markerCluster;
// Our markers
markers = [
['0', 'Title 1', 52.4357808, 4.991315699999973, 'car'],
['1', 'Title 2', 52.4357808, 4.981315699999973, 'third'],
['2', 'Title 3', 52.4555687, 5.039231599999994, 'car'],
['3', 'Title 4', 52.4555687, 5.029231599999994, 'second']
];
function addMarker(marker) {
var title = marker[1];
var pos = new google.maps.LatLng(marker[2], marker[3]);
var content = marker[1];
var marker = new google.maps.Marker({
title: title,
position: pos,
map: map
});
gmarkers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker1, content) {
return function() {
infowindow.setContent(content);
infowindow.open(map, marker);
}
})(marker, content));
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map-canvas {
width: 100%;
height: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<script src="https://unpkg.com/#googlemaps/markerclustererplus/dist/index.min.js"></script>
<div id="map-canvas"></div>

Exporting kineticJS to image (datatoURL)

I ran into an issue while using kineticJS to create multiple stages.
I am trying to export multiple "stages" to images but I cant get past exporting the first stage, the datatoURL function doesnt seem to be working, and it breaks my script, or perhaps I'm calling it at the wrong location...
When the user clicks the save button, each stage should be converted to an image and displayed on the same page.
Can anyone tell me why the first stage is not being displayed as an image on the page?
Thanks in advance
Here is the code that puts the stage data into the image placeholder on the page.
document.getElementById('save').addEventListener('click', function() {
stage.toDataURL({
callback: function(dataUrl) {
document.getElementById("canvasimg").src = dataUrl;
document.getElementById("canvasimg").style.display = "inline";
}
});
}, false);
below is the full code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Canvas</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript' src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.1.min.js"></script>
<script type='text/javascript'>
$(window).load(function(){
var highlightWidth = 8;
var stage = new Kinetic.Stage({
container: 'container1',
width: 300,
height: 100
});
var layer = new Kinetic.Layer();
stage.add(layer);
document.getElementById('save').addEventListener('click', function() {
stage.toDataURL({
callback: function(dataUrl) {
document.getElementById("canvasimg").src = dataUrl;
document.getElementById("canvasimg").style.display = "inline";
}
});
}, false);
var dropzone = new Kinetic.Stage({
container: 'container2',
width: 300,
height: 100
});
var dropLayer = new Kinetic.Layer();
dropzone.add(dropLayer);
addBackground(stage, layer, dropLayer);
layer.draw();
addBackground(dropzone, dropLayer, layer);
dropLayer.draw();
var stage2 = new Kinetic.Stage({
container: 'container3',
width: 300,
height: 100
});
var layer2 = new Kinetic.Layer();
stage2.add(layer2);
var dropzone2 = new Kinetic.Stage({
container: 'container4',
width: 300,
height: 100
});
var dropLayer2 = new Kinetic.Layer();
dropzone2.add(dropLayer2);
addBackground(stage2, layer2, dropLayer2);
layer2.draw();
addBackground(dropzone2, dropLayer2, layer2);
dropLayer2.draw();
var images = {};
var URLs = {
house1: 'https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house204-3.jpg',
house2: 'https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house204-4.jpg',
house3: 'https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house204-1.jpg'
};
loadImages(URLs, start);
function start() {
var house1 = kImage(images.house1, 10, 10, 50, 50, layer);
var house2 = kImage(images.house2, 75, 10, 50, 50, layer);
var house3 = kImage(images.house3, 140, 10, 50, 50, layer);
layer.draw();
var house1 = kImage(images.house1, 10, 10, 50, 50, dropLayer);
var house2 = kImage(images.house2, 75, 10, 50, 50, dropLayer);
var house3 = kImage(images.house3, 140, 10, 50, 50, dropLayer);
dropLayer.draw();
var house1 = kImage(images.house1, 10, 10, 50, 50, layer2);
var house2 = kImage(images.house2, 75, 10, 50, 50, layer2);
var house3 = kImage(images.house3, 140, 10, 50, 50, layer2);
layer.draw();
var house1 = kImage(images.house1, 10, 10, 50, 50, dropLayer2);
var house2 = kImage(images.house2, 75, 10, 50, 50, dropLayer2);
var house3 = kImage(images.house3, 140, 10, 50, 50, dropLayer2);
dropLayer.draw();
}
function swapStagesIfSelected(sourceLayer, destinationLayer, startX, startY) {
var elements = sourceLayer.get("Image");
var totalWidth = 0;
var maxHeight = -999;
var layerWidth = destinationLayer.getStage().getWidth();
var layerHeight = destinationLayer.getStage().getHeight();
for (var i = 0; i < elements.length; i++) {
if (elements[i].isSelected) {
totalWidth += elements[i].getWidth();
maxHeight = Math.max(elements[i].getHeight(), maxHeight);
}
}
if (startX + totalWidth > layerWidth) {
startX = layerWidth - totalWidth - 15;
}
if (startY + maxHeight > layerHeight) {
startY = layerHeight - maxHeight - 15;
}
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.isSelected) {
var img = element.getImage();
kImage(img, startX, startY, element.getWidth(), element.getHeight(), destinationLayer);
startX += element.getWidth() + 10;
element.remove();
}
}
sourceLayer.draw();
destinationLayer.draw();
}
function kImage(image, x, y, width, height, theLayer) {
var image = new Kinetic.Image({
image: image,
x: x,
y: y,
width: width,
height: height,
strokeWidth: 0,
stroke: "white",
draggable: true
});
image.myLayer = theLayer;
image.isSelected = false;
image.on("click", function () {
this.myLayer.draw();
});
image.myLayer.add(image);
return (image);
}
function addBackground(theStage, theLayer, otherLayer) {
var background = new Kinetic.Rect({
x: 0,
y: 0,
width: theStage.getWidth(),
height: theStage.getHeight(),
fill: "white",
stroke: "blue",
strokeWidth: 1
});
background.on("click", function () {
var pos = theStage.getMousePosition();
var mouseX = parseInt(pos.x);
var mouseY = parseInt(pos.y);
swapStagesIfSelected(otherLayer, theLayer, mouseX, mouseY);
});
theLayer.add(background);
}
function loadImages(URLs, callback) {
var loaded = 0;
var needed = 0;
for (var url in URLs) {
needed++;
console.log(url);
}
for (var url in URLs) {
images[url] = new Image();
images[url].onload = function () {
if (++loaded >= needed) {
callback(images);
}
};
images[url].src = URLs[url];
}
}
});
</script>
</head>
<body>
<div id="container1"></div>
<div id="container2"></div>
<div id="container3"></div>
<div id="container4"></div>
<img style="background:url(test1.png);" id="canvasimg" style="display:none;">
<button id="save">Save as image</button>
</body>
</html>

Titanium Mobile Detailed view for row data

I am trying to create a detailed view of my json data. I am unsure of how to really approach it. I have the eventlistener, but I am unsure of how to pull data based on the name of the bar selected. Here is my json pull:
var win =Titanium.UI.currentWindow;
var data = [];
var xhr = Titanium.Network.createHTTPClient();
var barList = Titanium.UI.createTableView({
height:366,
width: 320,
top:0,
left:0
});
win.add(barList);
xhr.onload = function () {
var json = JSON.parse(this.responseText);
Ti.API.info(json.length);
for (var i = 0; i < json.length; i++) {
var row = Titanium.UI.createTableViewRow({
hasChild: true,
className: 'bar-row',
filter: json[i].bar.name
});
var titleLabel = Titanium.UI.createLabel({
text: json[i].bar.name,
font: {
fontSize: 14,
fontWeight: 'bold'
},
left: 70,
top: 5,
height: 20,
width: 210
});
row.add(titleLabel);
var addressLabel = Titanium.UI.createLabel({
text: json[i].bar.address,
font: {
fontSize: 10,
fontWeight: 'normal'
},
left: 70,
top: 25,
height: 40,
width: 200
});
row.add(addressLabel);
var iconImage = Titanium.UI.createImageView({
text: json[i].bar.logo_file_name,
width: 50,
height: 50,
left: 10,
top: 10
});
row.add(iconImage);
data.push(row);
row.addEventListener('click',function(e){
var detail = Ti.UI.createWindow({
title: e.rowData.title
});
detail.open({modal: true});
})
}
barList.data = data;
};
xhr.open('GET', 'http://site.com/db.json');
xhr.send();
JSON data:
I'm looking to pull the name, description, mon_special, tues_special, etc., for the bar selected
http://pastie.org/private/eyp9m5il6hrulbds76a8q
Simplest way to do this is attach the data to the row you created:
var row = Titanium.UI.createTableViewRow({
hasChild: true,
className: 'bar-row',
filter: json[i].bar.name,
barData : json[i].bar
});
Then access it through the event listener added to the TableView itself (don't use the rowData object of the event if you've created the row itself)
barList.addEventListener('click', function(e) {
// Get the row clicked, then get our custom attribute
var passedJSONBarData = e.row.barData;
// Now pass along through the window, or build the window here
var detail = Ti.UI.createWindow({
title: passedJSONBarData.title,
barData : passedJSONBarData
});
detail.open({modal: true});
});
I add the event listener to the table so that we only create the function once you may get some performance / memory savings using this approach.