I have the following js code:
export function loadDeliveryMap() {
var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyD1r7I_MfQzY&callback=initDeliveryMap';
script.defer = true;
script.async = true;
window.initDeliveryMap = function() {
console.log("init map");
console.log("Element is ", document.getElementById("delivery-map"));
deliveryMap = new google.maps.Map(document.getElementById("delivery-map"), {
center: { lat: 37.7749, lng: -122.4194 },
zoom: 8
});
};
document.head.appendChild(script);
}
That I'm trying to write in Clojurescript as follows:
(defn load-delivery-map []
(def delivery-map nil)
(let [script (js/document.createElement "script")
]
(set! (.-src script) "https://maps.googleapis.com/maps/api/js?key=AIzaSyD1r7IEvzY&callback=init_delivery_map")
(set! (.-defer script) true)
(set! (.-async script) true)
(set! (.-init-delivery-map js/window)
(fn []
(set! delivery-map
(js/google.maps.Map. (js/document.getElementById "delivery-map")
{:center {:lat 37.0 :lng -122.0}}))))
(js/document.head.appendChild script))
The js function works fine, but upon calling the analogous cljs function, I get the following error:
Uncaught (in promise) RangeError: Maximum call stack size exceeded
at ni.eval [as cljs$core$ILookup$_lookup$arity$3] (core.cljs:6891)
at ni.eval [as get] (core.cljs:6822)
at ni.streetView_changed (VM1567 js:217)
at $d (VM1567 js:63)
at ni._.O.set (VM1567 js:181)
at ni.streetView_changed (VM1567 js:217)
at $d (VM1567 js:63)
at ni._.O.set (VM1567 js:181)
at ni.streetView_changed (VM1567 js:217)
at $d (VM1567 js:63)
Why would that be?
Something is causing infinite recursion. Something to do with the script variable.
The error goes away when
(set! (.-src script) "https://maps.googleapis.com/maps/api/js?key=AIzaSvzY&callback=init_delivery_map")
is commented out but then the google map isn't loaded.
Related
I am trying to render in canvas the module that I built with SDL2, but I also need to call functions while the module is running and send data there, according to the examples I found it turns out so:
var Module = {
canvas: (function () {
var canvas = document.getElementById('canvas');
canvas.addEventListener('webglcontextlost', e => {
alert('WebGL context lost. You will need to reload the page.');
e.preventDefault();
}, false);
return canvas;
})(),
};
SSE.onmessage = msg => {
Module.onRuntimeInitialized = () => {
Module.ccall('set_num', null, ['number'], [msg]);
};
}
The function was called once, but I need to call it constantly in the event
make with
override CFLAGS += -std=c11\
-Os\
-sUSE_SDL_TTF=2\
-sUSE_SDL_IMAGE=2\
-sSDL2_IMAGE_FORMATS=["png"]\
-sEXPORTED_RUNTIME_METHODS=['ccall','cwrap']\
-sUSE_SDL=2\
-sWASM=1\
-sASSERTIONS\
--preload-file ./res
C
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
#endif
void set_num(int num) { g_obj->num = num; }
I want to add HTML popup to Mapbox in Vue project.
This is my MapComponent.Vue
<template>
<div>
<div id='map'></div>
</div>
</template>
<script>
import mapboxgl from 'mapbox-gl'
import StarRating from 'vue-star-rating'
export default {
....
methods: {
...
createMap: function () {
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxleC1wZXRyb3YiLCJhIjoiY2o3dGluZTl2NGh1bjMzbnVqYjA1dnc5cCJ9.6is8d4d-BwwVlT0rPcuU1Q'
this.map = new mapboxgl.Map({
container: 'map',
style: {
...
},
center: [-114.3393270, 48.4210780],
minZoom: 5,
maxZoom: 15,
zoom: 5
})
// disable map rotation using right click + drag
this.map.dragRotate.disable()
// disable map rotation using touch rotation gesture
this.map.touchZoomRotate.disableRotation()
this.$store.state.trails.forEach((trail) => this.addMarker(trail))
},
addMarker: function (trail) {
// create a HTML element for each feature
var el = document.createElement('div')
el.className = 'marker'
// var content = this.popupContent(trail)
// create the popup
var popup = new mapboxgl.Popup()
.setHTML(<StarRating />)
// make a marker for each feature and add to the map
new mapboxgl.Marker(el)
.setLngLat(trail.elements[14].data.point.split(','))
.setPopup(popup)
.addTo(this.map)
}
...
},
components: {
StarRating
}
}
</script>
I got this error.
ReferenceError: h is not defined
at VueComponent.addMarker (MapComponent.vue?70f3:101)
at VueComponent.boundFn [as addMarker] (vue.esm.js?65d7:179)
at eval (MapComponent.vue?70f3:92)
at Array.forEach (<anonymous>)
at VueComponent.createMap (MapComponent.vue?70f3:92)
at VueComponent.boundFn [as createMap] (vue.esm.js?65d7:180)
at eval (MapComponent.vue?70f3:54)
at <anonymous>
An error has occurred in this code.
// create the popup
var popup = new mapboxgl.Popup()
.setHTML(<StarRating />)
I am trying to search for this error but I didn't get any answer yet.
Is there anyone who has experience with this error?
How can I get rendered HTML code of StarRating Component in Script?
Thanks.
My code is here:
var target = Array.prototype.push
var handler = {
apply: function () {
return 'I am the proxy';
}
};
var p = new Proxy(target, handler);
Array.prototype.push = p
console.log(p,p(1));
Error is here:
[Function: push] 'I am the proxy' internal/process/next_tick.js:93
callback = tock.callback;
^
TypeError: Cannot read property 'callback' of undefined
at process._tickCallback (internal/process/next_tick.js:93:24)
When I assign a observer function to Array.protoType, I got this error. Where is the problem?
I have been trying to fix this since yesterday but I can't get my head around it. I am loading my google map asynchronously but The following code brings up an error which is due to the infobox not being loaded correctly.
My error is:
InfoBox is not defined
My code is:
function loadScript(callback) {
var map = document.createElement('script');
map.type = 'text/javascript';
map.src = 'https://maps.googleapis.com/maps/api/js?key=my_key_goes_here&sensor=false&callback=initialize';
document.body.appendChild(map);
map.onload = function() {
var box = document.createElement('script');
box.type = 'text/javascript';
box.src = 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js';
document.body.appendChild(box);
box.onload = callback;
};
}
window.onload = loadScript;
You specify an argument to your loadScript, 'callback'. Then in your map.src you specify callback=initialize. You call loadScript on window.onload, but you don't specify an argument to it. So box.onload doesn't know any value for callback I'm guessing, as it can't magically guess 'initialize' from the map.src string.
Make sense?
I hear that UnityScript is pretty close to JavaScript. Does UnityScript support the Object Literal syntax of JavaScript?
e.g.
var x = {
y: 12
};
Strangely, searching google for UnityScript "Object Literal" yields no useful results.
UnityScript versus JavaScript have very different semantics.
Creating a new JavaScript file in Unity with this syntax will not compile.
#pragma strict
var x = {
y: 12 // error: BCE0005
};
function Start () {
Debug.Log (x.y); // error: BCE0019
}
This will give build errors:
NewBehaviourScript(4,5): BCE0005: unknown identifier: 'y'.
NewBehaviourScript(8,17): BCE0019: 'y' is not a member of 'Boo.Lang.Hash'.
However, you could implement a Hashtable:
#pragma strict
var x:Hashtable = new Hashtable();
x["y"] = 12;
function Start () {
Debug.Log (x["y"]);
}