Mapbox Markers in Wrong Place - javascript

I've made a simple mapbox map using the mapbox.js API and following several examples they have on their site. To display the marker location I'm calling a .geojson file, however the markers appear fairly off place even to the point that some load on top of the Ocean.
Someone said I'm calling the geojson file twice but I checked and it's being loaded once.
JS code is:
// Mapbox
L.mapbox.accessToken = 'token_here';
var mapCol = L.mapbox.map('map', 'mapbox.streets').setView([5.5, -73.249], 6);
var filters = document.getElementById('filters');
var markers = L.mapbox.featureLayer().loadURL('regions.geojson');
markers.on('ready', function(e) {
var typesObj = {},
types = [];
var features = e.target._geojson.features;
for (var i = 0; i < features.length; i++) {
typesObj[features[i].properties['description']] = true;
}
for (var key in typesObj) {
if ({}.hasOwnProperty.call(typesObj, key)) {
types.push(key);
}
}
var checkboxes = [];
for (var j = 0; j < types.length; j++) {
var item = filters.appendChild(document.createElement('div'));
var checkbox = item.appendChild(document.createElement('input'));
var label = item.appendChild(document.createElement('label'));
checkbox.type = 'checkbox';
checkbox.id = types[j];
checkbox.checked = true;
label.innerHTML = types[j];
label.setAttribute('for', types[j]);
checkbox.addEventListener('change', update);
checkboxes.push(checkbox);
}
function update() {
var enabled = {};
for (var k = 0; k < checkboxes.length; k++) {
if (checkboxes[k].checked) enabled[checkboxes[k].id] = true;
}
markers.setFilter(function(feature) {
return feature.properties['description'] in enabled;
});
}
}).addTo(mapCol);
mapCol.scrollWheelZoom.disable();

This is the issue: markers are images, and this page has a broad rule about images, saying that they should have a bottom margin. This moves the markers north, into the sea.
The issue can be fixed by making the CSS rule more precise.

Related

Illustrator Script: Export Single Layer to SVG

I have been trying to get a script going that is able to export a specific illustrator file to a SVG format. I have been referencing this Adobe forum post about a method of doing this and implemented it somewhat succesfully, see below:
var singleLayer,
doc,
path = 'C:/Users/lukeb/Desktop/New folder',
type = ExportType.SVG,
options = new ExportOptionsSVG(),
layerAmount;
doc = this.myApp;
singleLayer = this.myApp.layers["buttons"];
options.embedRasterImages = false;
options.cssProperties = SVGCSSPropertyLocation.PRESENTATIONATTRIBUTES;
options.fontSubsetting = SVGFontSubsetting.None;
options.documentEncoding = SVGDocumentEncoding.UTF8;
options.coordinatePrecision = 4;
layerAmount = doc.layers.length;
hideAllLayers();
for (var i = layerAmount - 1, k = 0; i >= 0; i--, k++) {
if (this.myApp.layers[i] === singleLayer) {
var file;
singleLayer.visible = true;
file = new File(path + "/" + singleLayer);
this.myApp.exportFile(file, type, options);
singleLayer.visible = false;
}
}
showAllLayers();
function hideAllLayers() {
for(var i = 0; i < layerAmount; i++) {
doc.layers[i].visible = false;
}
}
function showAllLayers() {
for(var i = 0; i < layerAmount; i++) {
doc.layers[i].visible = true;
}
}
This code runs perfectly, to an extent. It singles out the layer in my layer library and turns all of them off except that one. But for some reason it does not export just that one layer as an SVG, it exports a whole lot, if not all of them. Is there something missing with this? There isnt a lot of documentation around all of this so wasnt too sure of a fool proof solution to just get a single layer.

Having issue On Loading All JSON Data into Markers Layer With in For Loop

I have a code like below which is suppose to add over 600 points into a GraphicLayer projectsG and eventually add the projectsG to layer1 and map but I am not sure what I am doing wrong in
projectsG = new esri.Graphic(project, symbol).setInfoTemplate(projectInfoTemplate);
}
console.log(thepoints);
layer1 = new esri.layers.GraphicsLayer();
for (i = 0; i < points.length; ++i) {
layer1.add(projectsG);
}
part which only adds the last project into the map! Can you please take a look at following code and let me know what I am doing wrong in looping?
var layer1,
var thepoints=[];
var projectInfoTemplate;
var projectsG;
var points = [
{
"ProjectID":"15260",
"Longitude":"-118.641508",
"Latitude":"51.949915",
},
{
"ProjectID":"17043",
"Longitude":"-125.444557",
"Latitude":"51.097552",
},
....
{
"ProjectID":"13009",
"Longitude":"-130.257086",
"Latitude":"56.882834",
},
{
"ProjectID":"17088",
"Longitude":"-124.160699",
"Latitude":"50.897618",
}
];
function drawSeries1() {
for (var i = 0; i < points.length; i++) {
var projects = points[i];
var project = new esri.geometry.Point(projects.Longitude, projects.Latitude);
project = esri.geometry.geographicToWebMercator(project);
var symbol = new esri.symbol.PictureMarkerSymbol("e-Chartreuse.png", 32, 32);
projectInfoTemplate = new InfoTemplate();
projectInfoTemplate.setTitle("Project Details");
projectInfoTemplate.setContent('<div>Some Att Here</div> ');
projectsG = new esri.Graphic(project, symbol).setInfoTemplate(projectInfoTemplate);
thepoints.push(projectsG);
}
console.log(thepoints);
layer1 = new esri.layers.GraphicsLayer();
for (i = 0; i < points.length; ++i) {
layer1.add(projectsG);
}
map.addLayer(layer1);
}
try this for loop :
for (var i = 0; i < thepoints.length; ++i) {
layer1.add(thepoints[i]);
}
even "better", you could skip that last for loop, and replace thepoints.push(projectsG); with layer1.add(projectsG); in the previous for loop

Google Apps Script: How to get this code run after UI is closed?

This may seem a very newbie question, but I'm stuck with it. I've got this code to show a check list in a UI and insert the paragraphs of one or more documents into another target document:
var fact_list = [ ["Kennedy Inauguration", "politics", "tZwnNdFNkNklYc3pVUzZINUV4eUtWVWFSVEf"], ["Pericles’ Funeral Oration", "politics", "sdgrewaNkNklYc3pVUzZINUV4eUtW345ufaZ"], ["The Pleasure of Books", "culture", "1234rFszdgrfYc3pVUzZINUV4eU43usacd"], ["I Am The First Accused (Nelson Mandela)", "law", "34rsgadOsidjSZIswjadi95uydnfklsdks"] ];
function showList() {
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication();
var panel = app.createVerticalPanel().setId('panel');
// Store the number of items in the array (fact_list)
panel.add(app.createHidden('checkbox_total', fact_list.length));
// add 1 checkbox + 1 hidden field per item
for(var i = 0; i < fact_list.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(fact_list[i][0]);
var hidden = app.createHidden('checkbox_value_'+i, fact_list[i]);
panel.add(checkbox).add(hidden);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
app.add(panel);
mydoc.show(app);
}
function submit(e){
var numberOfItems = e.parameter.checkbox_total;
var itemsSelected = [];
// for each item, if it is checked / selected, add it to itemsSelected
for(var i = 0; i < numberOfItems; i++){
if(e.parameter['checkbox_isChecked_'+i] == 'true'){
itemsSelected.push(e.parameter['checkbox_value_'+i]);
}
}
var app = UiApp.getActiveApplication();
ScriptProperties.setProperties({'theses': itemsSelected}, true);
app.close();
return app;
}
function importTheses(targetDocId, thesesId, thesesType) { // adapted from Serge insas
var targetDoc = DocumentApp.openById(targetDocId);
var targetDocParagraphs = targetDoc.getParagraphs();
var targetDocElements = targetDocParagraphs.getNumChildren();
var thesesDoc = DocumentApp.openById(thesesId);
var thesesParagraphs = thesesDoc.getParagraphs();
var thesesElements = thesesDoc.getNumChildren();
var eltargetDoc=[];
var elTheses=[];
for( var j = 0; j < targetDocElements; ++j ) {
var targetDocElement = targetDoc.getChild(j);
// Logger.log(j + " : " + type);// to see targetDoc's content
eltargetDoc[j]=targetDocElement.getText();
if(el[j]== thesesType){
for( var k = 0; k < thesesParagraphs-1; ++k ) {
var thesesElement = thesesDoc.getChild(k);
elTheses[k] = thesesDoc.getText();
targetDoc.insertParagraph(j, elTheses[k]);
}
}
}
}
But when I call these functions inside my main function, I got a red message (in my language): service not available: Docs and, after the UI from showList() is closed, nothing more happens with my code (but I wanted the main functions continues to run). I call these functions this way:
if (theses == 1){
showList();
var thesesArrays = ScriptProperties.getProperty('theses');
for (var i = 0; i < thesesArrays.lenght(); i++){
var thesesId = ScriptProperties.getProperty('theses')[i][2];
var thesesType = ScriptProperties.getProperty('theses')[i][1];
importTheses(target, thesesId, thesesType);
}
}
showURL(docName, link); // Shows document name and link in UI
So, how can I fix that? How can I get the code run until the line showURL(docName, link);?
showList();
This function creates only Ui.
You are setting the script properties only in the Server Handler which executes on the click of submit button. Since then:
ScriptProperties.getProperty('theses');
will hold nothing. So you need to call these lines:
var thesesArrays = ScriptProperties.getProperty('theses');
for (var i = 0; i < thesesArrays.lenght(); i++){
var thesesId = ScriptProperties.getProperty('theses')[i][2];
var thesesType = ScriptProperties.getProperty('theses')[i][1];
importTheses(target, thesesId, thesesType);
}
Inside server handler or put them inside a method and call the method from the server Handler.

Photoshop Scripting: How to make page numbers

Hello I was wondering if anyone can help me write a Photoshop script that will display a number and save the document incrementally?
I got to here so far:
if(app.documents.length != 0){
var doc = app.activeDocument;
for(i = 0; i < doc.artLayers.length; ++i){
var layer = doc.artLayers[i];
if(layer.kind == LayerKind.TEXT){
layer.textItem.contents = 1;
layer.textItem.size = 20;
}
}
}
But I'm having trouble writing the content with increments. I want it so that the page number on my document increases by 1.
It isn't entirely clear what you are after. This will increment the number shown, but every text layer it encounters will get numbered.
if(app.documents.length != 0){
var doc = app.activeDocument;
var j = 1;
for(i = 0; i < doc.artLayers.length; ++i){
var layer = doc.artLayers[i];
if(layer.kind == LayerKind.TEXT){
layer.textItem.contents = j;
layer.textItem.size = 20;
j++;
}
}
}

sharepoint javascript on click shape

I need to add an onclick event to shapes from Visio in SharePoint, with JavaScript, like the vwaControl handler shapeselectionchanged but on click, is there any way I could do that?
I'm sorry about my English is not my native language.
I hope you can understand me.
I just did something similar.
You can use the shapeSelectionChangedHandler to handle clicks to. As far as I know there is no onClick functionality, but shapeSelectionChangedHandler works fine for me.
See:
Programming with Visio in SharePoint, create new Outlook meeting in ?Javascript?
See: http://msdn.microsoft.com/en-us/library/gg243427.aspx for guide to set it up with Content WebPart and so on.
Code I use, just add what you want in shapeSelectionChangedHandler = function(source, args) {}
<script language="javascript">
var app = Sys.Application;
app.add_load(onApplicationLoad);
// hold an instance of the Visio VWA control
var vwaControl;
var shapeSelectionChangedHandler = null;
function onApplicationLoad()
{
vwaControl= new Vwa.VwaControl("WebPartWPQ4");
vwaControl.addHandler("diagramcomplete", onDiagramComplete);
vwaControl.addHandler("shapeselectionchanged", shapeSelectionChangedHandler);
}
function onDiagramComplete()
{
var vwaPage = vwaControl.getActivePage();
vwaPage.setZoom(35); // force the initial zoom level
}
shapeSelectionChangedHandler = function(source, args)
{
// get the selected shape from the shapes on the page
var vwaPage = vwaControl.getActivePage();
var vwaShapes = vwaPage.getShapes();
var shape = vwaShapes.getItemById(args);
// get the data to display for the selected shape
var data = shape.getShapeData();
var strRoomName = "";
var strFloorNumber = "";
var strCapacity = "";
var strStatus = "";
for (var j = 0; j < data.length; j++)
{
if (data[j].label == "RoomName")
{
strRoomName = data[j].value;
continue;
}
if (data[j].label == "FloorNumber")
{
strFloorNumber = data[j].value;
continue;
}
if (data[j].label == "Capacity")
{
strCapacity = data[j].value;
continue;
}
if (data[j].label == "RoomStatus")
{
strStatus = data[j].value;
continue;
}
}
// get the selected state input and set its value
var inputRoomName = document.getElementById('strRoomName');
inputRoomName.value = strRoomName;
var inputFloorNumber = document.getElementById('strFloorNumber');
inputFloorNumber.value = strFloorNumber;
var inputCapacity = document.getElementById('strCapacity');
inputCapacity.value = strCapacity;
var inputStatus = document.getElementById('strStatus');
inputStatus.value = strStatus;
}

Categories

Resources