paper js display stop issue - html5-canvas

I use paper.js and canvas to make web api, but when open web page , there is nothing until I move mouse on canvas. I don't know why.
code as follow, actually when I try to draw a box , it also like that.
<script language="javascript" type="text/javascript" canvas="canvas">
paper.install(window);
window.onload=function(){
var scope2 = new PaperScope();
paper = scope2.setup('controlpanel');
// var L_controlpanel = new Layer();
var bgshadoW = new Shape.Rectangle({
point:[10,10],
size:[200,360],
fillColor:'#f2f2f2',
shadowColor:'black',
shadowBlur: 12,
shadowOffset: [5, 5]
});
var colorfunC ;
var G_colorfunC = new Group();
var colorcontenT = ['#ffff66','#77ff33','#66b3ff','#f0aad9','#ffd486']
for (var i, i=0;i<5;i++){
colorfunC = new Path.Rectangle({
point:[20,20+30*i],
size:[15,15],
radius:5,
strokeColor: 'black',
strokeWidth: 1,
fillColor:'#f2f2f2',
data:{'click':0,'color':colorcontenT[i]}
});
G_colorfunC.addChild(colorfunC);
colorfunC.onClick = function(event){
G_colorfunC.fillColor='#f2f2f2';
this.fillColor=' #4dc3ff';
fillcolorshoT = this.data['color'];
}
fixdemO = new Path.Rectangle({
point:[60,20+30*i],
size:[50,15],
fillColor:colorcontenT[i]
});
}
var G_denVfunC = new Group();
var denVcontenT = [120,150,200,250,300]
for (var i, i=0;i<5;i++){
denVfunC = new Path.Rectangle({
point:[20,200+30*i],
size:[15,15],
radius:5,
strokeColor: 'black',
strokeWidth: 1,
fillColor:'#f2f2f2',
data:{'click':0,'denV':denVcontenT[i]}
});
G_denVfunC.addChild(denVfunC);
denVfunC.onClick = function(event){
G_denVfunC.fillColor='#f2f2f2';
this.fillColor='#4dffa6';
denV = this.data['denV'];
}
FixText = new PointText({
point:[60,212+30*i],
fontSize:14,
fillColor: 'black',
content:'DOMA density: '+denVcontenT[i]
});
}
}
</script>

found cause,just add
paper.view.update();

Related

How to get Famo.us draggable modifier's render node

I am trying to get parent renderNode of a draggable modifier on 'end' event, is there any api to get a renderNode to which draggable belongs to? My code is as follows :
/*globals define*/
define(function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var StateModifier = require('famous/modifiers/StateModifier');
var Draggable = require("famous/modifiers/Draggable");
var RenderNode = require('famous/core/RenderNode');
/*
* #name DragTest
* #constructor
* #description
*/
function DragTest() {
View.apply(this, arguments);
_createDragSurface.call(this);
}
DragTest.prototype = Object.create(View.prototype);
DragTest.prototype.constructor = DragTest;
DragTest.DEFAULT_OPTIONS = {
};
function _createDragSurface(){
var yOffset=0;
for(var i=0;i<2;i++){
var draggable = new Draggable({
xRange: [-220,0],
yRange: [0,0]
});
var dragSurface= new Surface({
content:'this is a drag surface',
size:[150,150],
properties:{
marginLeft: '10px',
backgroundColor:'grey'
}
});
var dragSurfaceModifier= new StateModifier({
align:[0.5,yOffset]
});
yOffset+=0.3;
dragSurface.pipe(draggable);
draggable.on('end',function(e){
this.setPosition([0,0,0], {
method: 'snap',
period: 300
});
});
var nodePlayer = new RenderNode(draggable);
nodePlayer.add(dragSurfaceModifier).add(dragSurface);
this.add(nodePlayer);
}
}
module.exports = DragTest;
});
On drag of a surface to the left, once it reaches threshold, I want to remove the renderNode i.e.,
draggable.on('end',function(e){
if(e.position[0]<-50){
renderNode.remove()//how to achieve this part of the code as I dont have an access to nodePlayer renderNode here.
}
else{
this.setPosition([0,0,0], {
method: 'snap',
period: 300
});
}
});
If I simply use the name of a renderNode i.e., nodePlayer it will remove the last surface no matter which surface is been dragged.Any input on this is much appreciated.
Best Regards.
There are a lot of ways to accomplish what you want to do.
Since you are using the end event on the draggable and using the position value from the custom event, let's bind the references to the needed items to be able to access them.
There is not a .remove() method on the RenderNode so the example shows a way you could remove a node from the view with a RenderController.
Remember: There is no need to remove nodes from the DOM. Famo.us will manage the renderables in the render tree.
define('main', function(require, exports, module) {
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var Modifier = require('famous/core/Modifier');
var StateModifier = require('famous/modifiers/StateModifier');
var Draggable = require('famous/modifiers/Draggable');
var TransitionableTransform = require('famous/transitions/TransitionableTransform');
var DragTest = require('DragTest');
var mainContext = Engine.createContext();
var dragTest = new DragTest();
mainContext.add(dragTest);
dragTest.on('removed', function(e) {
console.log('removed ', e.removedNode);
});
});
define('DragTest', function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var StateModifier = require('famous/modifiers/StateModifier');
var Draggable = require("famous/modifiers/Draggable");
var RenderNode = require('famous/core/RenderNode');
var RenderController = require('famous/views/RenderController');
/*
* #name DragTest
* #constructor
* #description
*/
function DragTest() {
View.apply(this, arguments);
_createDragSurface.call(this);
}
DragTest.prototype = Object.create(View.prototype);
DragTest.prototype.constructor = DragTest;
DragTest.DEFAULT_OPTIONS = {};
function _endingDrag(e) {
console.log('end position', e.position, this);
if (e.position[0] < -180) {
this.renderController.hide(this.nodePlayer, function() {
this.surface.emit('removed', {
removedNode: this.nodePlayer
});
}.bind(this));
} else {
this.draggable.setPosition([0, 0, 0], {
duration: 300
});
}
}
function _updatingDrag(e) {
console.log('update position', e.position);
this.surface.setContent('Position ' + e.position);
}
function _createDragSurface() {
var yOffset = 0;
for (var i = 0; i < 2; i++) {
var dragSurface = new Surface({
content: 'this is a drag surface',
size: [150, 150],
properties: {
marginLeft: '10px',
backgroundColor: 'grey'
}
});
var dragSurfaceModifier = new StateModifier({
origin: [0, 0],
align: [0.5, yOffset]
});
yOffset += 0.3;
var draggable = new Draggable({
xRange: [-220, 0],
yRange: [0, 0]
});
var renderController = new RenderController();
this.add(renderController);
var nodePlayer = new RenderNode();
nodePlayer.add(dragSurfaceModifier).add(draggable).add(dragSurface);
renderController.show(nodePlayer)
draggable.on('end', _endingDrag.bind({
draggable: draggable,
renderController: renderController,
nodePlayer: nodePlayer,
surface: dragSurface
}));
draggable.on('update', _updatingDrag.bind({
surface: dragSurface
}));
draggable.subscribe(dragSurface);
dragSurface.pipe(this._eventOutput); // so we can emit a custom removed event to this widget
}
}
module.exports = DragTest;
});
require(['main']);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://requirejs.org/docs/release/2.1.16/minified/require.js"></script>
<script src="http://code.famo.us/lib/requestAnimationFrame.js"></script>
<script src="http://code.famo.us/lib/classList.js"></script>
<script src="http://code.famo.us/lib/functionPrototypeBind.js"></script>
<link rel="stylesheet" type="text/css" href="http://code.famo.us/famous/0.3.5/famous.css" />
<script src="http://code.famo.us/famous/0.3.5/famous.min.js"></script>

Google Maps APIv3 about handling multiple markers

I have some code I put together and I see that there must be some problem with zLat and zLng. I am wondering why it is when I replace zLat and zLng with tLat and tLng inside my for loop then I get one marker which makes sense. With zLat and zLng in there I get no markers. Why would this be happening?
P.S. My alert for zLat and zLng is producing what looks like proper output but it must not be?
// // // // // // // // Ajax returns from PHP
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var obj = $.parseJSON(xmlhttp.responseText);
var tLat = getCookie("tLat");
var tLng = getCookie("tLng");
var options = {
zoom: 4,
center: new google.maps.LatLng(40.7257, -74.0047),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Creating the map
var map = new google.maps.Map(document.getElementById('map'), options);
// Adding a marker to the map
/*var marker = new google.maps.Marker({
position: new google.maps.LatLng(tLat, tLng),
map: map,
title: 'Click me',
icon: 'http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png'
});*/
var marker;
alert(obj.length);
for(var i=0;i<obj.length;i++) {
var zLat = String(obj[i].lat);
var zLng = String(obj[i].lng);
marker = new google.maps.Marker({
position: new google.maps.LatLng(zLat, zLng),
map: map,
title: 'Click me'
});
alert(zLat+','+zLng+','+i);
}
$('#map').show();
}
}
// // // // // // // //
// // // // // // // // Ajax returns from PHP
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var obj = $.parseJSON(xmlhttp.responseText);
var tLat = getCookie("tLat");
var tLng = getCookie("tLng");
var options = {
zoom: 4,
center: new google.maps.LatLng(tLat, tLng),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Creating the map
var map = new google.maps.Map(document.getElementById('map'), options);
var myLatLng = new google.maps.LatLng(parseFloat(obj[0][2]), parseFloat(obj[0][1]));
//var marker = new google.maps.Marker({ position: myLatLng, map: map });
var marker;
for(var i=0;i<obj.length;i++) {
var myLatLng = new google.maps.LatLng(parseFloat(obj[i].lat), parseFloat(obj[i].lng));
var marker = new google.maps.Marker({ position: myLatLng, map: map });
}
$('#map').show();
}
}
// // // // // // // //

Add/Remove Image Dynamically from Controls in Google Maps V3

Greetigns Everyone,
I am working on a little application that will add and remove an image of a squirrel to a Google Maps application’s controls (http://www.geogodesigns.com/projects/squirrel/indexTest.html). Strange, yes, I know.
If you check out the site you will see that I can add and remove the squirrel just fine by clicking the 'Squirrel' button. However, subsequent additions and subtractions of the squirrel cause the little critter to scurry down the map. Hmmm...
What I want is for the squirrel to stay in the same place, just under the Google basemap controls, each and every time I click the 'Squirrel' button. This has been a tough nut to crack.
(function() {
window.onload = function() {
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom: 10,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map"), myOptions);
var homeControlDiv = document.createElement('DIV');
var homeControl = new HomeControl(homeControlDiv, map);
homeControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
};
})();
function HomeControl(controlDiv, map) {
controlDiv.style.padding = '5px';
var controlUI = document.createElement('DIV');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '2px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Show squirrel';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('DIV');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.color = 'black';
controlText.style.fontSize = '12px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.innerHTML = '<b>Squirrel</b>';
controlUI.appendChild(controlText);
var imageDiv = document.createElement('DIV');
imageDiv.setAttribute('id','imageDiv');
google.maps.event.addDomListener(controlUI, 'click', function() {
if(document.getElementById('image')){
controlUI.style.backgroundColor = 'white';
controlText.style.color = 'black';
var oldimage = document.getElementById('image');
imageDiv.removeChild(oldimage);
}
else{
controlUI.style.backgroundColor = 'black';
controlText.style.color = 'white';
var image = document.createElement('IMG');
image.setAttribute('id','image');
image.src = 'http://www.geogodesigns.com/projects/squirrel/img/squirrel.jpg';
imageDiv.appendChild(image);
map.controls[google.maps.ControlPosition.RIGHT].push(imageDiv);
}
});
}
Add the last line.
if(document.getElementById('image')){
controlUI.style.backgroundColor = 'white';
controlText.style.color = 'black';
var oldimage = document.getElementById('image');
imageDiv.removeChild(oldimage);
map.controls[google.maps.ControlPosition.RIGHT].pop(oldimage);
}

Google Map V3: Loading Markers using AJAX+ASP/PHP and Reload on Ruquest or Event

Hi I've searched so many things and found many contents but didn't found what I required actually.
I can loading all markers but unable to Refresh it or Reload it please help me out here's the code:
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
$(document).ready(function(e){
MYMAP.placeMarkers('testasp.asp');
});
});
var curr_infw;
var MYMAP = {
map: null,
bounds: null,
infowindow:null
}
MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}
MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
$(xml).find("marker").each(function(){
var name = $(this).find('name').text();
var address = $(this).find('address').text();
// create a new LatLng point for the marker
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
var infowindow = null;
// extend the bounds to include the new point
MYMAP.bounds.extend(point);
var marker = new google.maps.Marker({
position: point,
map: MYMAP.map,
clickable: true,
icon: 'truck_green.png'
});
//var infowindow = null;
infoWindow = new google.maps.InfoWindow();
var html='<strong>'+name+'</strong.><br />'+address;
google.maps.event.addListener(marker, 'mouseover', function() {
infoWindow.setContent(html);
infoWindow.open(MYMAP.map, marker);
});
MYMAP.map.fitBounds(MYMAP.bounds);
});
});
}
If somebody help me out I want to refresh it using click event or settimeout function though.
Regards and looking forward to hear it here soon. thanks
Not an answer, but what's this meant to be?
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
$(document).ready(function(e){
MYMAP.placeMarkers('testasp.asp');
});
});
Why are you nesting document.ready? Just do
$(document).ready(function() {
var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
MYMAP.init('#map', myLatLng, 11);
MYMAP.placeMarkers('testasp.asp');
});
For event use
google.maps.event.addListener([ mapObject ], 'bounds_changed', function() {
// [ update code here ]
});

Using sidebar click to trigger google maps event v3

Still stuck with this one can someone please help made some progress just having issues with the info windows now.
<div id="map"></div>
<div id="sidebar">
<h2>Sidebar</h2>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.890542, 151.274856),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
//console.log(infowindow);
var markers = [];
var marker = [];
var html = "<ul>";
for (i = 0; i < locations.length; i++) {
//console.info(marker.position());
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: "http://lindsay-and-dan.gettingmarried.co.uk/images/maps/icon-music.gif"
});
//console.log(marker);
var center = marker.position;
markers.push(marker);
console.log(markers[i]);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
//console.log(marker.position);
map.panTo(center);
}
})(marker, i));
//console.log(marker);
//console.log(locations[i][0]);
html += '<li>' + locations[i][0] + '</li>';
}
html += "</ul>";
$('#sidebar').html(html).fadeIn('slow');
$('.move').click(function(){
//infowindow.close();
var contents = $(this).attr('map');
var array = contents.split(',');
var lon = array[0];
var lat = array[1];
var content = array[2];
console.log(content);
infowindow.open(map, marker);
infowindow.setContent(content);
map.panTo(new google.maps.LatLng(lon,lat));
return false;
});
</script>
Here is a link to the test example.
http://extwit.users35.interdns.co.uk/gmap/
any suggestions???
Ok, so helping you DEFINITELY helped me. Your marker should look something like this:
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
Oa: locations[i][1],
Pa: locations[i][2],
map: map,
icon: "http://lindsay-and-dan.gettingmarried.co.uk/images/maps/icon-music.gif"
});
Oa and Pa were added.
Hope this helps
P.S: I just noticed your other issue with the info window itself. Add infowindow.open(map,marker); and also the positioning of the infowindow is off...not really sure about that one.
P.P.S.: Your $('.move') block of code needs to be within the markers loop; within this block, replace your marker reference with markers[i]. This should do it for you!

Resources