How to display Popups on a Mapbox Map - Morioh

文章推薦指數: 80 %
投票人數:10人

import ReactMapGL, {Marker, Popup } from 'react-map-gl'; const CustomPopup = ({index, marker, closePopup}) => { return ( { return(

{marker.name}

)}; Again,thankstoreact-map-gl,wegetaPopupcomponentwhichtakeslat/long,butalso offsetTop (meaning,inthiscase,Iwantthepopuptoappearontopofthemarker). Tomakeitwork,weaddneedanonClickonourmarkerscalled openPopup.Thisfunctionwillsetwhichmarkerwasclickedthankstoitsuniqueindex. constCustomMarker=({index,marker,openPopup})=>{ return( openPopup(index)}> {index+1} )}; Andbacktoourparentcomponent: constructor(props){ super(props); this.state={ ..., selectedIndex:null, ... }; } setSelectedMarker=(index)=>{ this.setState({selectedIndex:index}) } closePopup=()=>{ this.setSelectedMarker(null) }; openPopup=(index)=>{ this.setSelectedMarker(index) } render(){ return( ... { this.state.markers.map((marker,index)=>{ return( ) }) } ... ) } #javascript#mapbox#reactjs#react WhatisGEEK BuddhaCommunity VeronicaRoob 1653475560 APurePHPImplementationOfTheMessagePackSerializationFormat msgpack.phpApurePHPimplementationoftheMessagePackserializationformat.FeaturesFullycompliantwiththelatestMessagePackspecificationSupportsstreamingunpackingSupportsunsigned64-bitintegershandlingSupportsobjectserializationFullytestedRelativelyfastInstallationTherecommendedwaytoinstallthelibraryisthroughComposer:composerrequirerybakit/msgpack UsagePackingTopackvaluesyoucaneitheruseaninstanceofaPacker:$packer=newPacker(); $packed=$packer->pack($value); orcallastaticmethodontheMessagePackclass:$packed=MessagePack::pack($value); Intheexamplesabove,themethodpackautomaticallypacksavaluedependingonitstype.However,notallPHPtypescanbeuniquelytranslatedtoMessagePacktypes.Forexample,theMessagePackformatdefinesmapandarraytypes,whicharerepresentedbyasinglearraytypeinPHP.Bydefault,thepackerwillpackaPHParrayasaMessagePackarrayifithassequentialnumerickeys,startingfrom0andasaMessagePackmapotherwise:$mpArr1=$packer->pack([1,2]);//MParray[1,2] $mpArr2=$packer->pack([0=>1,1=>2]);//MParray[1,2] $mpMap1=$packer->pack([0=>1,2=>3]);//MPmap{0:1,2:3} $mpMap2=$packer->pack([1=>2,2=>3]);//MPmap{1:2,2:3} $mpMap3=$packer->pack(['a'=>1,'b'=>2]);//MPmap{a:1,b:2} However,sometimesyouneedtopackasequentialarrayasaMessagePackmap.Todothis,usethepackMapmethod:$mpMap=$packer->packMap([1,2]);//{0:1,1:2} Hereisalistoftype-specificpackingmethods:$packer->packNil();//MPnil $packer->packBool(true);//MPbool $packer->packInt(42);//MPint $packer->packFloat(M_PI);//MPfloat(32or64) $packer->packFloat32(M_PI);//MPfloat32 $packer->packFloat64(M_PI);//MPfloat64 $packer->packStr('foo');//MPstr $packer->packBin("\x80");//MPbin $packer->packArray([1,2]);//MParray $packer->packMap(['a'=>1]);//MPmap $packer->packExt(1,"\xaa");//MPext Checkthe"Customtypes"sectionbelowonhowtopackcustomtypes.PackingoptionsThePackerobjectsupportsanumberofbitmask-basedoptionsforfine-tuningthepackingprocess(defaultsareinbold):NameDescriptionFORCE_STRForcesPHPstringstobepackedasMessagePackUTF-8stringsFORCE_BINForcesPHPstringstobepackedasMessagePackbinarydataDETECT_STR_BINDetectsMessagePackstr/bintypeautomatically  FORCE_ARRForcesPHParraystobepackedasMessagePackarraysFORCE_MAPForcesPHParraystobepackedasMessagePackmapsDETECT_ARR_MAPDetectsMessagePackarray/maptypeautomatically  FORCE_FLOAT32ForcesPHPfloatstobepackedas32-bitsMessagePackfloatsFORCE_FLOAT64ForcesPHPfloatstobepackedas64-bitsMessagePackfloatsThetypedetectionmode(DETECT_STR_BIN/DETECT_ARR_MAP)addssomeoverheadwhichcanbenoticedwhenyoupacklarge(16-and32-bit)arraysorstrings.However,ifyouknowthevaluetypeinadvance(forexample,youonlyworkwithUTF-8stringsor/andassociativearrays),youcaneliminatethisoverheadbyforcingthepackertousetheappropriatetype,whichwillsaveitfromrunningtheauto-detectionroutine.Anotheroptionistoexplicitlyspecifythevaluetype.Thelibraryprovides2auxiliaryclassesforthis,MapandBin.Checkthe"Customtypes"sectionbelowfordetails.Examples://detectstr/bintypeandpackPHP64-bitfloats(doubles)toMP32-bitfloats $packer=newPacker(PackOptions::DETECT_STR_BIN|PackOptions::FORCE_FLOAT32); //thesewillthrowMessagePack\Exception\InvalidOptionException $packer=newPacker(PackOptions::FORCE_STR|PackOptions::FORCE_BIN); $packer=newPacker(PackOptions::FORCE_FLOAT32|PackOptions::FORCE_FLOAT64); UnpackingTounpackdatayoucaneitheruseaninstanceofaBufferUnpacker:$unpacker=newBufferUnpacker(); $unpacker->reset($packed); $value=$unpacker->unpack(); orcallastaticmethodontheMessagePackclass:$value=MessagePack::unpack($packed); Ifthepackeddataisreceivedinchunks(e.g.whenreadingfromastream),usethetryUnpackmethod,whichattemptstounpackdataandreturnsanarrayofunpackedmessages(ifany)insteadofthrowinganInsufficientDataException:while($chunk=...){ $unpacker->append($chunk); if($messages=$unpacker->tryUnpack()){ return$messages; } } Ifyouwanttounpackfromaspecificpositioninabuffer,useseek:$unpacker->seek(42);//setpositionequalto42bytes $unpacker->seek(-8);//setpositionto8bytesbeforetheendofthebuffer Toskipbytesfromthecurrentposition,useskip:$unpacker->skip(10);//setpositionto10bytesaheadofthecurrentposition Togetthenumberofremaining(unread)bytesinthebuffer:$unreadBytesCount=$unpacker->getRemainingCount(); Tocheckwhetherthebufferhasunreaddata:$hasUnreadBytes=$unpacker->hasRemaining(); Ifneeded,youcanremovealreadyreaddatafromthebufferbycalling:$releasedBytesCount=$unpacker->release(); Withthereadmethodyoucanreadraw(packed)data:$packedData=$unpacker->read(2);//read2bytes BesidestheabovemethodsBufferUnpackerprovidestype-specificunpackingmethods,namely:$unpacker->unpackNil();//PHPnull $unpacker->unpackBool();//PHPbool $unpacker->unpackInt();//PHPint $unpacker->unpackFloat();//PHPfloat $unpacker->unpackStr();//PHPUTF-8string $unpacker->unpackBin();//PHPbinarystring $unpacker->unpackArray();//PHPsequentialarray $unpacker->unpackMap();//PHPassociativearray $unpacker->unpackExt();//PHPMessagePack\Type\Extobject UnpackingoptionsTheBufferUnpackerobjectsupportsanumberofbitmask-basedoptionsforfine-tuningtheunpackingprocess(defaultsareinbold):NameDescriptionBIGINT_AS_STRConvertsoverflowedintegerstostrings[1]BIGINT_AS_GMPConvertsoverflowedintegerstoGMPobjects[2]BIGINT_AS_DECConvertsoverflowedintegerstoDecimal\Decimalobjects[3]1.ThebinaryMessagePackformathasunsigned64-bitasitslargestintegerdatatype,butPHPdoesnotsupportsuchintegers,whichmeansthatanoverflowcanoccurduringunpacking.2.MakesuretheGMPextensionisenabled.3.MakesuretheDecimalextensionisenabled.Examples:$packedUint64="\xcf"."\xff\xff\xff\xff"."\xff\xff\xff\xff"; $unpacker=newBufferUnpacker($packedUint64); var_dump($unpacker->unpack());//string(20)"18446744073709551615" $unpacker=newBufferUnpacker($packedUint64,UnpackOptions::BIGINT_AS_GMP); var_dump($unpacker->unpack());//object(GMP){...} $unpacker=newBufferUnpacker($packedUint64,UnpackOptions::BIGINT_AS_DEC); var_dump($unpacker->unpack());//object(Decimal\Decimal){...} CustomtypesInadditiontothebasictypes,thelibraryprovidesfunctionalitytoserializeanddeserializearbitrarytypes.Thiscanbedoneinseveralways,dependingonyourusecase.Let'stakealookatthem.TypeobjectsIfyouneedtoserializeaninstanceofoneofyourclassesintooneofthebasicMessagePacktypes,thebestwaytodothisistoimplementtheCanBePackedinterfaceintheclass.AgoodexampleofsuchaclassistheMaptypeclassthatcomeswiththelibrary.ThistypeisusefulwhenyouwanttoexplicitlyspecifythatagivenPHParrayshouldbepackedasaMessagePackmapwithouttriggeringanautomatictypedetectionroutine:$packer=newPacker(); $packedMap=$packer->pack(newMap([1,2,3])); $packedArray=$packer->pack([1,2,3]); Moretypeexamplescanbefoundinthesrc/Typedirectory.TypetransformersAswithtypeobjects,typetransformersareonlyresponsibleforserializingvalues.TheyshouldbeusedwhenyouneedtoserializeavaluethatdoesnotimplementtheCanBePackedinterface.Examplesofsuchvaluescouldbeinstancesofbuilt-inorthird-partyclassesthatyoudon'town,ornon-objectssuchasresources.AtransformerclassmustimplementtheCanPackinterface.Touseatransformer,itmustfirstberegisteredinthepacker.HereisanexampleofhowtoserializePHPstreamsintotheMessagePackbinformattypeusingoneofthesuppliedtransformers,StreamTransformer:$packer=newPacker(null,[newStreamTransformer()]); $packedBin=$packer->pack(fopen('/path/to/file','r+')); Moretypetransformerexamplescanbefoundinthesrc/TypeTransformerdirectory.ExtensionsIncontrasttothecasesdescribedabove,extensionsareintendedtohandleextensiontypesandareresponsibleforbothserializationanddeserializationofvalues(types).AnextensionclassmustimplementtheExtensioninterface.Touseanextension,itmustfirstberegisteredinthepackerandtheunpacker.TheMessagePackspecificationdividesextensiontypesintotwogroups:predefinedandapplication-specific.Currently,thereisonlyonepredefinedtypeinthespecification,Timestamp.TimestampTheTimestampextensiontypeisapredefinedtype.SupportforthistypeinthelibraryisdonethroughtheTimestampExtensionclass.ThisclassisresponsibleforhandlingTimestampobjects,whichrepresentthenumberofsecondsandoptionaladjustmentinnanoseconds:$timestampExtension=newTimestampExtension(); $packer=newPacker(); $packer=$packer->extendWith($timestampExtension); $unpacker=newBufferUnpacker(); $unpacker=$unpacker->extendWith($timestampExtension); $packedTimestamp=$packer->pack(Timestamp::now()); $timestamp=$unpacker->reset($packedTimestamp)->unpack(); $seconds=$timestamp->getSeconds(); $nanoseconds=$timestamp->getNanoseconds(); WhenusingtheMessagePackclass,theTimestampextensionisalreadyregistered:$packedTimestamp=MessagePack::pack(Timestamp::now()); $timestamp=MessagePack::unpack($packedTimestamp); Application-specificextensionsInaddition,theformatcanbeextendedwithyourowntypes.Forexample,tomakethebuilt-inPHPDateTimeobjectsfirst-classcitizensinyourcode,youcancreateacorrespondingextension,asshownintheexample.Pleasenote,thatcustomextensionshavetoberegisteredwithauniqueextensionID(anintegerfrom0to127).Moreextensionexamplescanbefoundintheexamples/MessagePackdirectory.Tolearnmoreabouthowextensiontypescanbeuseful,checkoutthisarticle.ExceptionsIfanerroroccursduringpacking/unpacking,aPackingFailedExceptionoranUnpackingFailedExceptionwillbethrown,respectively.Inaddition,anInsufficientDataExceptioncanbethrownduringunpacking.AnInvalidOptionExceptionwillbethrownincaseaninvalidoption(oracombinationofmutuallyexclusiveoptions)isused.TestsRuntestsasfollows:vendor/bin/phpunit Also,ifyoualreadyhaveDockerinstalled,youcanrunthetestsinadockercontainer.First,createacontainer:./dockerfile.sh|dockerbuild-tmsgpack- ThecommandabovewillcreateacontainernamedmsgpackwithPHP8.1runtime.YoumaychangethedefaultruntimebydefiningthePHP_IMAGEenvironmentvariable:PHP_IMAGE='php:8.0-cli'./dockerfile.sh|dockerbuild-tmsgpack- Seealistofvariousimageshere.Thenruntheunittests:dockerrun--rm-v$PWD:/msgpack-w/msgpackmsgpack FuzzingToensurethattheunpackingworkscorrectlywithmalformed/semi-malformeddata,youcanuseatestingtechniquecalledFuzzing.Thelibraryshipswithahelpfile(target)forPHP-Fuzzerandcanbeusedasfollows:php-fuzzerfuzztests/fuzz_buffer_unpacker.php PerformanceTocheckperformance,run:php-n-dzend_extension=opcache.so\ -dpcre.jit=1-dopcache.enable=1-dopcache.enable_cli=1\ tests/bench.php ExampleoutputFilter:MessagePack\Tests\Perf\Filter\ListFilter Rounds:3 Iterations:100000 ============================================= Test/TargetPackerBufferUnpacker --------------------------------------------- nil..................0.0030........0.0139 false................0.0037........0.0144 true.................0.0040........0.0137 7-bituint#1........0.0052........0.0120 7-bituint#2........0.0059........0.0114 7-bituint#3........0.0061........0.0119 5-bitsint#1........0.0067........0.0126 5-bitsint#2........0.0064........0.0132 5-bitsint#3........0.0066........0.0135 8-bituint#1........0.0078........0.0200 8-bituint#2........0.0077........0.0212 8-bituint#3........0.0086........0.0203 16-bituint#1.......0.0111........0.0271 16-bituint#2.......0.0115........0.0260 16-bituint#3.......0.0103........0.0273 32-bituint#1.......0.0116........0.0326 32-bituint#2.......0.0118........0.0332 32-bituint#3.......0.0127........0.0325 64-bituint#1.......0.0140........0.0277 64-bituint#2.......0.0134........0.0294 64-bituint#3.......0.0134........0.0281 8-bitint#1.........0.0086........0.0241 8-bitint#2.........0.0089........0.0225 8-bitint#3.........0.0085........0.0229 16-bitint#1........0.0118........0.0280 16-bitint#2........0.0121........0.0270 16-bitint#3........0.0109........0.0274 32-bitint#1........0.0128........0.0346 32-bitint#2........0.0118........0.0339 32-bitint#3........0.0135........0.0368 64-bitint#1........0.0138........0.0276 64-bitint#2........0.0132........0.0286 64-bitint#3........0.0137........0.0274 64-bitint#4........0.0180........0.0285 64-bitfloat#1......0.0134........0.0284 64-bitfloat#2......0.0125........0.0275 64-bitfloat#3......0.0126........0.0283 fixstring#1........0.0035........0.0133 fixstring#2........0.0094........0.0216 fixstring#3........0.0094........0.0222 fixstring#4........0.0091........0.0241 8-bitstring#1......0.0122........0.0301 8-bitstring#2......0.0118........0.0304 8-bitstring#3......0.0119........0.0315 16-bitstring#1.....0.0150........0.0388 16-bitstring#2.....0.1545........0.1665 32-bitstring........0.1570........0.1756 widecharstring#1..0.0091........0.0236 widecharstring#2..0.0122........0.0313 8-bitbinary#1......0.0100........0.0302 8-bitbinary#2......0.0123........0.0324 8-bitbinary#3......0.0126........0.0327 16-bitbinary........0.0168........0.0372 32-bitbinary........0.1588........0.1754 fixarray#1.........0.0042........0.0131 fixarray#2.........0.0294........0.0367 fixarray#3.........0.0412........0.0472 16-bitarray#1......0.1378........0.1596 16-bitarray#2...........S.............S 32-bitarray..............S.............S complexarray........0.1865........0.2283 fixmap#1...........0.0725........0.1048 fixmap#2...........0.0319........0.0405 fixmap#3...........0.0356........0.0665 fixmap#4...........0.0465........0.0497 16-bitmap#1........0.2540........0.3028 16-bitmap#2.............S.............S 32-bitmap................S.............S complexmap..........0.2372........0.2710 fixext1.............0.0283........0.0358 fixext2.............0.0291........0.0371 fixext4.............0.0302........0.0355 fixext8.............0.0288........0.0384 fixext16............0.0293........0.0359 8-bitext............0.0302........0.0439 16-bitext...........0.0334........0.0499 32-bitext...........0.1845........0.1888 32-bittimestamp#1..0.0337........0.0547 32-bittimestamp#2..0.0335........0.0560 64-bittimestamp#1..0.0371........0.0575 64-bittimestamp#2..0.0374........0.0542 64-bittimestamp#3..0.0356........0.0533 96-bittimestamp#1..0.0362........0.0699 96-bittimestamp#2..0.0381........0.0701 96-bittimestamp#3..0.0367........0.0687 ============================================= Total2.76184.0820 Skipped44 Failed00 Ignored00 WithJIT:php-n-dzend_extension=opcache.so\ -dpcre.jit=1-dopcache.jit_buffer_size=64M-dopcache.jit=tracing-dopcache.enable=1-dopcache.enable_cli=1\ tests/bench.php ExampleoutputFilter:MessagePack\Tests\Perf\Filter\ListFilter Rounds:3 Iterations:100000 ============================================= Test/TargetPackerBufferUnpacker --------------------------------------------- nil..................0.0005........0.0054 false................0.0004........0.0059 true.................0.0004........0.0059 7-bituint#1........0.0010........0.0047 7-bituint#2........0.0010........0.0046 7-bituint#3........0.0010........0.0046 5-bitsint#1........0.0025........0.0046 5-bitsint#2........0.0023........0.0046 5-bitsint#3........0.0024........0.0045 8-bituint#1........0.0043........0.0081 8-bituint#2........0.0043........0.0079 8-bituint#3........0.0041........0.0080 16-bituint#1.......0.0064........0.0095 16-bituint#2.......0.0064........0.0091 16-bituint#3.......0.0064........0.0094 32-bituint#1.......0.0085........0.0114 32-bituint#2.......0.0077........0.0122 32-bituint#3.......0.0077........0.0120 64-bituint#1.......0.0085........0.0159 64-bituint#2.......0.0086........0.0157 64-bituint#3.......0.0086........0.0158 8-bitint#1.........0.0042........0.0080 8-bitint#2.........0.0042........0.0080 8-bitint#3.........0.0042........0.0081 16-bitint#1........0.0065........0.0095 16-bitint#2........0.0065........0.0090 16-bitint#3........0.0056........0.0085 32-bitint#1........0.0067........0.0107 32-bitint#2........0.0066........0.0106 32-bitint#3........0.0063........0.0104 64-bitint#1........0.0072........0.0162 64-bitint#2........0.0073........0.0174 64-bitint#3........0.0072........0.0164 64-bitint#4........0.0077........0.0161 64-bitfloat#1......0.0053........0.0135 64-bitfloat#2......0.0053........0.0135 64-bitfloat#3......0.0052........0.0135 fixstring#1.......-0.0002........0.0044 fixstring#2........0.0035........0.0067 fixstring#3........0.0035........0.0077 fixstring#4........0.0033........0.0078 8-bitstring#1......0.0059........0.0110 8-bitstring#2......0.0063........0.0121 8-bitstring#3......0.0064........0.0124 16-bitstring#1.....0.0099........0.0146 16-bitstring#2.....0.1522........0.1474 32-bitstring........0.1511........0.1483 widecharstring#1..0.0039........0.0084 widecharstring#2..0.0073........0.0123 8-bitbinary#1......0.0040........0.0112 8-bitbinary#2......0.0075........0.0123 8-bitbinary#3......0.0077........0.0129 16-bitbinary........0.0096........0.0145 32-bitbinary........0.1535........0.1479 fixarray#1.........0.0008........0.0061 fixarray#2.........0.0121........0.0165 fixarray#3.........0.0193........0.0222 16-bitarray#1......0.0607........0.0479 16-bitarray#2...........S.............S 32-bitarray..............S.............S complexarray........0.0749........0.0824 fixmap#1...........0.0329........0.0431 fixmap#2...........0.0161........0.0189 fixmap#3...........0.0205........0.0262 fixmap#4...........0.0252........0.0205 16-bitmap#1........0.1016........0.0927 16-bitmap#2.............S.............S 32-bitmap................S.............S complexmap..........0.1096........0.1030 fixext1.............0.0157........0.0161 fixext2.............0.0175........0.0183 fixext4.............0.0156........0.0185 fixext8.............0.0163........0.0184 fixext16............0.0164........0.0182 8-bitext............0.0158........0.0207 16-bitext...........0.0203........0.0219 32-bitext...........0.1614........0.1539 32-bittimestamp#1..0.0195........0.0249 32-bittimestamp#2..0.0188........0.0260 64-bittimestamp#1..0.0207........0.0281 64-bittimestamp#2..0.0212........0.0291 64-bittimestamp#3..0.0207........0.0295 96-bittimestamp#1..0.0222........0.0358 96-bittimestamp#2..0.0228........0.0353 96-bittimestamp#3..0.0210........0.0319 ============================================= Total1.64321.9674 Skipped44 Failed00 Ignored00 Youmaychangedefaultbenchmarksettingsbydefiningthefollowingenvironmentvariables:NameDefaultMP_BENCH_TARGETSpure_p,pure_u,seealistofavailabletargetsMP_BENCH_ITERATIONS100_000MP_BENCH_DURATIONnotsetMP_BENCH_ROUNDS3MP_BENCH_TESTS-@slow,seealistofavailabletestsForexample:exportMP_BENCH_TARGETS=pure_p exportMP_BENCH_ITERATIONS=1000000 exportMP_BENCH_ROUNDS=5 #acommaseparatedlistoftestnames exportMP_BENCH_TESTS='complexarray,complexmap' #oragroupname #exportMP_BENCH_TESTS='-@slow'//@pecl_comp #oraregexp #exportMP_BENCH_TESTS='/complex(array|map)/' Anotherexample,benchmarkingboththelibraryandthePECLextension:MP_BENCH_TARGETS=pure_p,pure_u,pecl_p,pecl_u\ php-n-dextension=msgpack.so-dzend_extension=opcache.so\ -dpcre.jit=1-dopcache.enable=1-dopcache.enable_cli=1\ tests/bench.php ExampleoutputFilter:MessagePack\Tests\Perf\Filter\ListFilter Rounds:3 Iterations:100000 =========================================================================== Test/TargetPackerBufferUnpackermsgpack_packmsgpack_unpack --------------------------------------------------------------------------- nil..................0.0031........0.0141......0.0055........0.0064 false................0.0039........0.0154......0.0056........0.0053 true.................0.0038........0.0139......0.0056........0.0044 7-bituint#1........0.0061........0.0110......0.0059........0.0046 7-bituint#2........0.0065........0.0119......0.0042........0.0029 7-bituint#3........0.0054........0.0117......0.0045........0.0025 5-bitsint#1........0.0047........0.0103......0.0038........0.0022 5-bitsint#2........0.0048........0.0117......0.0038........0.0022 5-bitsint#3........0.0046........0.0102......0.0038........0.0023 8-bituint#1........0.0063........0.0174......0.0039........0.0031 8-bituint#2........0.0063........0.0167......0.0040........0.0029 8-bituint#3........0.0063........0.0168......0.0039........0.0030 16-bituint#1.......0.0092........0.0222......0.0049........0.0030 16-bituint#2.......0.0096........0.0227......0.0042........0.0046 16-bituint#3.......0.0123........0.0274......0.0059........0.0051 32-bituint#1.......0.0136........0.0331......0.0060........0.0048 32-bituint#2.......0.0130........0.0336......0.0070........0.0048 32-bituint#3.......0.0127........0.0329......0.0051........0.0048 64-bituint#1.......0.0126........0.0268......0.0055........0.0049 64-bituint#2.......0.0135........0.0281......0.0052........0.0046 64-bituint#3.......0.0131........0.0274......0.0069........0.0044 8-bitint#1.........0.0077........0.0236......0.0058........0.0044 8-bitint#2.........0.0087........0.0244......0.0058........0.0048 8-bitint#3.........0.0084........0.0241......0.0055........0.0049 16-bitint#1........0.0112........0.0271......0.0048........0.0045 16-bitint#2........0.0124........0.0292......0.0057........0.0049 16-bitint#3........0.0118........0.0270......0.0058........0.0050 32-bitint#1........0.0137........0.0366......0.0058........0.0051 32-bitint#2........0.0133........0.0366......0.0056........0.0049 32-bitint#3........0.0129........0.0350......0.0052........0.0048 64-bitint#1........0.0145........0.0254......0.0034........0.0025 64-bitint#2........0.0097........0.0214......0.0034........0.0025 64-bitint#3........0.0096........0.0287......0.0059........0.0050 64-bitint#4........0.0143........0.0277......0.0059........0.0046 64-bitfloat#1......0.0134........0.0281......0.0057........0.0052 64-bitfloat#2......0.0141........0.0281......0.0057........0.0050 64-bitfloat#3......0.0144........0.0282......0.0057........0.0050 fixstring#1........0.0036........0.0143......0.0066........0.0053 fixstring#2........0.0107........0.0222......0.0065........0.0068 fixstring#3........0.0116........0.0245......0.0063........0.0069 fixstring#4........0.0105........0.0253......0.0083........0.0077 8-bitstring#1......0.0126........0.0318......0.0075........0.0088 8-bitstring#2......0.0121........0.0295......0.0076........0.0086 8-bitstring#3......0.0125........0.0293......0.0130........0.0093 16-bitstring#1.....0.0159........0.0368......0.0117........0.0086 16-bitstring#2.....0.1547........0.1686......0.1516........0.1373 32-bitstring........0.1558........0.1729......0.1511........0.1396 widecharstring#1..0.0098........0.0237......0.0066........0.0065 widecharstring#2..0.0128........0.0291......0.0061........0.0082 8-bitbinary#1...........I.............I...........F.............I 8-bitbinary#2...........I.............I...........F.............I 8-bitbinary#3...........I.............I...........F.............I 16-bitbinary.............I.............I...........F.............I 32-bitbinary.............I.............I...........F.............I fixarray#1.........0.0040........0.0129......0.0120........0.0058 fixarray#2.........0.0279........0.0390......0.0143........0.0165 fixarray#3.........0.0415........0.0463......0.0162........0.0187 16-bitarray#1......0.1349........0.1628......0.0334........0.0341 16-bitarray#2...........S.............S...........S.............S 32-bitarray..............S.............S...........S.............S complexarray.............I.............I...........F.............F fixmap#1................I.............I...........F.............I fixmap#2...........0.0345........0.0391......0.0143........0.0168 fixmap#3................I.............I...........F.............I fixmap#4...........0.0459........0.0473......0.0151........0.0163 16-bitmap#1........0.2518........0.2962......0.0400........0.0490 16-bitmap#2.............S.............S...........S.............S 32-bitmap................S.............S...........S.............S complexmap..........0.2380........0.2682......0.0545........0.0579 fixext1..................I.............I...........F.............F fixext2..................I.............I...........F.............F fixext4..................I.............I...........F.............F fixext8..................I.............I...........F.............F fixext16.................I.............I...........F.............F 8-bitext.................I.............I...........F.............F 16-bitext................I.............I...........F.............F 32-bitext................I.............I...........F.............F 32-bittimestamp#1.......I.............I...........F.............F 32-bittimestamp#2.......I.............I...........F.............F 64-bittimestamp#1.......I.............I...........F.............F 64-bittimestamp#2.......I.............I...........F.............F 64-bittimestamp#3.......I.............I...........F.............F 96-bittimestamp#1.......I.............I...........F.............F 96-bittimestamp#2.......I.............I...........F.............F 96-bittimestamp#3.......I.............I...........F.............F =========================================================================== Total1.56252.38660.77350.7243 Skipped4444 Failed002417 Ignored242407 WithJIT:MP_BENCH_TARGETS=pure_p,pure_u,pecl_p,pecl_u\ php-n-dextension=msgpack.so-dzend_extension=opcache.so\ -dpcre.jit=1-dopcache.jit_buffer_size=64M-dopcache.jit=tracing-dopcache.enable=1-dopcache.enable_cli=1\ tests/bench.php ExampleoutputFilter:MessagePack\Tests\Perf\Filter\ListFilter Rounds:3 Iterations:100000 =========================================================================== Test/TargetPackerBufferUnpackermsgpack_packmsgpack_unpack --------------------------------------------------------------------------- nil..................0.0001........0.0052......0.0053........0.0042 false................0.0007........0.0060......0.0057........0.0043 true.................0.0008........0.0060......0.0056........0.0041 7-bituint#1........0.0031........0.0046......0.0062........0.0041 7-bituint#2........0.0021........0.0043......0.0062........0.0041 7-bituint#3........0.0022........0.0044......0.0061........0.0040 5-bitsint#1........0.0030........0.0048......0.0062........0.0040 5-bitsint#2........0.0032........0.0046......0.0062........0.0040 5-bitsint#3........0.0031........0.0046......0.0062........0.0040 8-bituint#1........0.0054........0.0079......0.0062........0.0050 8-bituint#2........0.0051........0.0079......0.0064........0.0044 8-bituint#3........0.0051........0.0082......0.0062........0.0044 16-bituint#1.......0.0077........0.0094......0.0065........0.0045 16-bituint#2.......0.0077........0.0094......0.0063........0.0045 16-bituint#3.......0.0077........0.0095......0.0064........0.0047 32-bituint#1.......0.0088........0.0119......0.0063........0.0043 32-bituint#2.......0.0089........0.0117......0.0062........0.0039 32-bituint#3.......0.0089........0.0118......0.0063........0.0044 64-bituint#1.......0.0097........0.0155......0.0063........0.0045 64-bituint#2.......0.0095........0.0153......0.0061........0.0045 64-bituint#3.......0.0096........0.0156......0.0063........0.0047 8-bitint#1.........0.0053........0.0083......0.0062........0.0044 8-bitint#2.........0.0052........0.0080......0.0062........0.0044 8-bitint#3.........0.0052........0.0080......0.0062........0.0043 16-bitint#1........0.0089........0.0097......0.0069........0.0046 16-bitint#2........0.0075........0.0093......0.0063........0.0043 16-bitint#3........0.0075........0.0094......0.0062........0.0046 32-bitint#1........0.0086........0.0122......0.0063........0.0044 32-bitint#2........0.0087........0.0120......0.0066........0.0046 32-bitint#3........0.0086........0.0121......0.0060........0.0044 64-bitint#1........0.0096........0.0149......0.0060........0.0045 64-bitint#2........0.0096........0.0157......0.0062........0.0044 64-bitint#3........0.0096........0.0160......0.0063........0.0046 64-bitint#4........0.0097........0.0157......0.0061........0.0044 64-bitfloat#1......0.0079........0.0153......0.0056........0.0044 64-bitfloat#2......0.0079........0.0152......0.0057........0.0045 64-bitfloat#3......0.0079........0.0155......0.0057........0.0044 fixstring#1........0.0010........0.0045......0.0071........0.0044 fixstring#2........0.0048........0.0075......0.0070........0.0060 fixstring#3........0.0048........0.0086......0.0068........0.0060 fixstring#4........0.0050........0.0088......0.0070........0.0059 8-bitstring#1......0.0081........0.0129......0.0069........0.0062 8-bitstring#2......0.0086........0.0128......0.0069........0.0065 8-bitstring#3......0.0086........0.0126......0.0115........0.0065 16-bitstring#1.....0.0105........0.0137......0.0128........0.0068 16-bitstring#2.....0.1510........0.1486......0.1526........0.1391 32-bitstring........0.1517........0.1475......0.1504........0.1370 widecharstring#1..0.0044........0.0085......0.0067........0.0057 widecharstring#2..0.0081........0.0125......0.0069........0.0063 8-bitbinary#1...........I.............I...........F.............I 8-bitbinary#2...........I.............I...........F.............I 8-bitbinary#3...........I.............I...........F.............I 16-bitbinary.............I.............I...........F.............I 32-bitbinary.............I.............I...........F.............I fixarray#1.........0.0014........0.0059......0.0132........0.0055 fixarray#2.........0.0146........0.0156......0.0155........0.0148 fixarray#3.........0.0211........0.0229......0.0179........0.0180 16-bitarray#1......0.0673........0.0498......0.0343........0.0388 16-bitarray#2...........S.............S...........S.............S 32-bitarray..............S.............S...........S.............S complexarray.............I.............I...........F.............F fixmap#1................I.............I...........F.............I fixmap#2...........0.0148........0.0180......0.0156........0.0179 fixmap#3................I.............I...........F.............I fixmap#4...........0.0252........0.0201......0.0214........0.0167 16-bitmap#1........0.1027........0.0836......0.0388........0.0510 16-bitmap#2.............S.............S...........S.............S 32-bitmap................S.............S...........S.............S complexmap..........0.1104........0.1010......0.0556........0.0602 fixext1..................I.............I...........F.............F fixext2..................I.............I...........F.............F fixext4..................I.............I...........F.............F fixext8..................I.............I...........F.............F fixext16.................I.............I...........F.............F 8-bitext.................I.............I...........F.............F 16-bitext................I.............I...........F.............F 32-bitext................I.............I...........F.............F 32-bittimestamp#1.......I.............I...........F.............F 32-bittimestamp#2.......I.............I...........F.............F 64-bittimestamp#1.......I.............I...........F.............F 64-bittimestamp#2.......I.............I...........F.............F 64-bittimestamp#3.......I.............I...........F.............F 96-bittimestamp#1.......I.............I...........F.............F 96-bittimestamp#2.......I.............I...........F.............F 96-bittimestamp#3.......I.............I...........F.............F =========================================================================== Total0.96421.09090.82240.7213 Skipped4444 Failed002417 Ignored242407 Notethatthemsgpackextension(v2.1.2)doesn'tsupportext,binandUTF-8strtypes.LicenseThelibraryisreleasedundertheMITLicense.SeethebundledLICENSEfilefordetails.Author: rybakitSourceCode: https://github.com/rybakit/msgpack.phpLicense:MITLicense#php  AutumnBlick 1598839687 HownativeisReactNative?|ReactNativevsNativeAppDevelopment Ifyouareundertakingamobileappdevelopmentforyourstart-uporenterprise,youarelikelywonderingwhethertouseReactNative.Asapopulardevelopmentframework,ReactNativehelpsyoutodevelopnear-nativemobileapps.However,youareprobablyalsowonderinghowcloseyoucangettoanativeappbyusingReactNative.HownativeisReactNative? Inthearticle,wediscussthesimilaritiesbetweennativemobiledevelopmentanddevelopmentusingReactNative.Wealsotouchuponwheretheydifferandhowtobridgethegaps.Readon. AbriefintroductiontoReactNative Let’sbrieflysetthecontextfirst.WewillbrieflytouchuponwhatReactNativeisandhowitdiffersfromearlierhybrid frameworks. ReactNative isapopularJavaScriptframeworkthatFacebookhascreated.Youcanusethisopen-sourceframeworktocodenativelyrenderingAndroidandiOSmobileapps.Youcanuseittodevelopwebappstoo. FacebookhasdevelopedReactNativebasedonReact,itsJavaScriptlibrary.ThefirstreleaseofReactNativecameinMarch2015.Atthetimeofwritingthisarticle,thelateststablereleaseofReactNativeis0.62.0,anditwasreleasedinMarch2020. Althoughrelativelynew,ReactNativehasacquiredahighdegreeofpopularity.The“StackOverflowDeveloperSurvey2019”reportidentifiesitasthe8thmostlovedframework.Facebook,Walmart,andBloombergaresomeofthetopcompaniesthatuseReactNative. ThepopularityofReactNativecomesfromitsadvantages.Someofitsadvantagesareasfollows: Performance:Itdeliversoptimalperformance. Cross-platformdevelopment:YoucandevelopbothAndroidandiOSappswithit.Thereuseofcodeexpeditesdevelopmentandreducescosts. UIdesign:ReactNativeenablesyoutodesignsimpleandresponsiveUIforyourmobileapp. 3rdpartyplugins:Thisframeworksupports3rdpartyplugins. Developercommunity:AvibrantcommunityofdeveloperssupportReactNative. WhyReactNativeisfundamentallydifferentfromearlierhybridframeworks AreyouwonderingwhetherReactNativeisjustanotherofthosehybridframeworkslikeIonicorCordova?It’snot!ReactNativeisfundamentallydifferentfromtheseearlierhybridframeworks. ReactNativeisveryclosetonative.ConsiderthefollowingaspectsasdescribedontheReactNativewebsite: Accesstomanynativeplatformsfeatures:TheprimitivesofReactNativerendertonativeplatformUI.ThismeansthatyourReactNativeappwillusemanynativeplatform APIs asnativeappswoulddo. Near-nativeuserexperience:ReactNativeprovidesseveralnativecomponents,andtheseareplatformagnostic. TheeaseofaccessingnativeAPIs:ReactNativeusesadeclarativeUIparadigm.ThisenablesReactNativetointeracteasilywithnativeplatformAPIssinceReactNativewrapsexistingnativecode. Duetothesefactors,ReactNativeoffersmanymoreadvantagescomparedtothoseearlierhybridframeworks.Wenowreviewthem. #androidapp#frontend#iosapp#mobileappdevelopment#benefitsofreactnative#isreactnativegoodformobileappdevelopment#nativevs#prosandconsofreactnative#reactmobiledevelopment#reactnativedevelopment#reactnativeexperience#reactnativeframework#reactnativeiosvsandroid#reactnativeprosandcons#reactnativevsandroid#reactnativevsnative#reactnativevsnativeperformance#reactvsnative#whyreactnative#whyusereactnative TrinityKub 1594739112 HowtodisplayaMapboxMapandGeocoder — Mapbox/ReactTutorialPart1 Thismulti-partReacttutorialwillbecoveringhowtouseMapboxto: displayamap searchanaddress addmarkers displayapopupwhenclickingonamarker andevenremovingamarker. Wewillbeusingcreate-react-appforourbaseReactappandusingthereact-map-glandreact-mapbox-gl-geocoderlibrariesforourmapandgeocoderrespectively.Asanoption,Iwillbeusingreactstrapforstyling(incaseyouareunfamiliar,reactstrapisBootstrapforReact). 1.Createprojectandinstalldependencies First,wewillstartbysettingupourproject. npxcreate-react-appmapbox-project cdmapbox-project npmireact-map-glreact-mapbox-gl-geocoderbootstrapreactstrap npmstart 2.Mapboxkey InordertouseMapbox,youwillneedanAPIkey.Goto https://www.mapbox.com/ andclickonSignIn. Underthesigninform,clickonSignUpforMapbox.Onceyouaredonesigningup,youshouldbetakentoyourdashboard.Ifyouweren’tautomaticallygivenatoken,youcancreateonebyclickingCreateatoken. #react#programming#tutorial#mapping#mapbox TrinityKub 1594912380 HowtodisplayPopupsonaMapboxMap — Mapbox/ReactTutorialPart3 Thisispart3(andthelastone)ofamulti-partReacttutorialonMapbox. Inpart1,wesimplyfocusondisplayingamapandaddingageocodertolookupaddresses.Weevenmanagedtore-centerourmaptotheselectedaddress. Inpart2,welearnedhowtodisplaymarkers. Part3willbefocusingonpopupsandremovingmarkersfromamap. _Note: Here isthelinktoPart1incaseyoumissedit.And here ispart2 Let’sgetstarted! DisplayaPopup Onceagain,wewillbeusingthereact-map-gllibrarywhichoffersanicePopupcomponent.SoIwillgoaheadandcreatea CustomPopup componenttodisplaytheaddressafterclickingonamarker. importReactMapGL,{Marker,Popup}from'react-map-gl'; constCustomPopup=({index,marker,closePopup})=>{ return(

{marker.name}

)}; Again,thankstoreact-map-gl,wegetaPopupcomponentwhichtakeslat/long,butalso offsetTop (meaning,inthiscase,Iwantthepopuptoappearontopofthemarker). Tomakeitwork,weaddneedanonClickonourmarkerscalled openPopup.Thisfunctionwillsetwhichmarkerwasclickedthankstoitsuniqueindex. constCustomMarker=({index,marker,openPopup})=>{ return( openPopup(index)}> {index+1} )}; Andbacktoourparentcomponent: constructor(props){ super(props); this.state={ ..., selectedIndex:null, ... }; } setSelectedMarker=(index)=>{ this.setState({selectedIndex:index}) } closePopup=()=>{ this.setSelectedMarker(null) }; openPopup=(index)=>{ this.setSelectedMarker(index) } render(){ return( ... { this.state.markers.map((marker,index)=>{ return( ) }) } ... ) } #javascript#mapbox#reactjs#react TrinityKub 1594825860 HowtodisplayMarkersonaMapboxMap — Mapbox/ReactTutorialPart2 Thisispart2ofamulti-partReacttutorialonMapbox. Inpart1,wesimplyfocusondisplayingamapandaddingageocodertolookupaddresses.Weevenmanagedtore-centerourmaptotheselectedaddress. Note: Here isthelinktoPart1incaseyoumissedit. Whileverynice,amapdoesn’tquitefeelascompletewithoutmarkerstoshowuswhat’simportant. Solet’sgetstarted! Displayamarker Wehaveourmapandourgeocoder.Wecanlookupaddressesandselectone. Let’snowdisplayamarkeronthatparticularaddress.Ourreact-map-gllibraryalsocomeswithahandyMarkercomponent. importReactMapGL,{Marker}from'react-map-gl'; Thiscomponentwillallowustodisplayamarkerifwehaveselectedanaddress.Inourstate,wewilladda tempMarker settonullandinour onSelected function,wewillsettempMarkertothelatitude/longitudeitreturned. onSelected=(viewport,item)=>{ this.setState({ viewport, tempMarker:{ name:item.place_name, longitude:item.center[0], latitude:item.center[1] } }) } Theninsideour ReactMapGL component,wecandisplayourMarkercomponent: {tempMarker&& } OurMarkercomponenttakesalatitudeandalongitudealongwithitscontent.Youcanstyleyourmarkerhoweveryouwant.IamsimplygoingtouseanemptydivwithsomeCSStomakeitlooklikeanormalmarker. #react#tutorial#programming#mapbox#javascript



請為這篇文章評分?